blob: 817e1f12e1de646285f17d6edf8f2feae3028858 [file] [log] [blame]
Bram Moolenaard7a06b12013-05-21 13:05:15 +02001Test for regexp patterns with multi-byte support, using utf-8.
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002See test64 for the non-multi-byte tests.
3
4A pattern that gives the expected result produces OK, so that we know it was
5actually tried.
6
7STARTTEST
8:so small.vim
9:so mbyte.vim
Bram Moolenaar1d814752013-05-24 20:25:33 +020010:set nocp encoding=utf-8 viminfo+=nviminfo nomore
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020011:" tl is a List of Lists with:
Bram Moolenaar3f1682e2013-05-26 14:32:05 +020012:" 2: test auto/old/new 0: test auto/old 1: test auto/new
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020013:" regexp pattern
14:" text to test the pattern on
15:" expected match (optional)
16:" expected submatch 1 (optional)
17:" expected submatch 2 (optional)
18:" etc.
19:" When there is no match use only the first two items.
20:let tl = []
21
22:"""" Multi-byte character tests. These will fail unless vim is compiled
23:"""" with Multibyte (FEAT_MBYTE) or BIG/HUGE features.
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020024:call add(tl, [2, '[[:alpha:][=a=]]\+', '879 aiaãâaiuvna ', 'aiaãâaiuvna'])
25:call add(tl, [2, '[[=a=]]\+', 'ddaãâbcd', 'aãâ']) " equivalence classes
26:call add(tl, [2, '[^ม ]\+', 'มม oijasoifjos ifjoisj f osij j มมมมม abcd', 'oijasoifjos'])
27:call add(tl, [2, ' [^ ]\+', 'start มabcdม ', ' มabcdม'])
28:call add(tl, [2, '[ม[:alpha:][=a=]]\+', '879 aiaãมâมaiuvna ', 'aiaãมâมaiuvna'])
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020029
Bram Moolenaar0fabe3f2013-05-21 12:34:17 +020030:" this is not a normal "i" but 0xec
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020031:call add(tl, [2, '\p\+', 'ìa', 'ìa'])
Bram Moolenaarac7c33e2013-07-21 17:06:00 +020032:call add(tl, [2, '\p*', 'aあ', 'aあ'])
Bram Moolenaar0fabe3f2013-05-21 12:34:17 +020033
Bram Moolenaard2470e92013-05-21 13:30:21 +020034:"""" Test recognition of some character classes
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020035:call add(tl, [2, '\i\+', '&*¨xx ', 'xx'])
36:call add(tl, [2, '\f\+', '&*Ÿfname ', 'fname'])
Bram Moolenaard2470e92013-05-21 13:30:21 +020037
Bram Moolenaar3c577f22013-05-24 21:59:54 +020038:"""" Test composing character matching
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020039:call add(tl, [2, '.ม', 'xม่x yมy', 'yม'])
40:call add(tl, [2, '.ม่', 'xม่x yมy', 'xม่'])
41:call add(tl, [2, "\u05b9", " x\u05b9 ", "x\u05b9"])
42:call add(tl, [2, ".\u05b9", " x\u05b9 ", "x\u05b9"])
43:call add(tl, [2, "\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
44:call add(tl, [2, ".\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
Bram Moolenaar3f1682e2013-05-26 14:32:05 +020045:call add(tl, [2, "\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
46:call add(tl, [2, ".\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020047:call add(tl, [2, "\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
48:call add(tl, [2, ".\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
Bram Moolenaar3f1682e2013-05-26 14:32:05 +020049:call add(tl, [2, "\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"])
50:call add(tl, [2, ".\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"])
51:call add(tl, [1, "\u05b9\u05bb", " y\u05b9 x\u05b9\u05bb ", "x\u05b9\u05bb"])
52:call add(tl, [2, ".\u05b9\u05bb", " y\u05bb x\u05b9\u05bb ", "x\u05b9\u05bb"])
Bram Moolenaar6082bea2014-05-13 18:04:00 +020053:call add(tl, [2, "a", "ca\u0300t"])
54:call add(tl, [2, "a\u0300", "ca\u0300t", "a\u0300"])
Bram Moolenaar56d58d52013-05-25 14:42:03 +020055
Bram Moolenaar3c577f22013-05-24 21:59:54 +020056
Bram Moolenaar1d814752013-05-24 20:25:33 +020057:"""" Test \Z
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020058:call add(tl, [2, 'ú\Z', 'x'])
59:call add(tl, [2, 'יהוה\Z', 'יהוה', 'יהוה'])
60:call add(tl, [2, 'יְהוָה\Z', 'יהוה', 'יהוה'])
61:call add(tl, [2, 'יהוה\Z', 'יְהוָה', 'יְהוָה'])
62:call add(tl, [2, 'יְהוָה\Z', 'יְהוָה', 'יְהוָה'])
63:call add(tl, [2, 'יְ\Z', 'וְיַ', 'יַ'])
64:call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
65:call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200dxy", "ק\u200dx"])
66:call add(tl, [2, "ק\u200dx\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
67:call add(tl, [2, "ק\u200dx\\Z", "xק\u200dxy", "ק\u200dx"])
Bram Moolenaar3451d662013-05-26 15:14:55 +020068:call add(tl, [2, "\u05b9\\Z", "xyz"])
69:call add(tl, [2, "\\Z\u05b9", "xyz"])
70:call add(tl, [2, "\u05b9\\Z", "xy\u05b9z", "y\u05b9"])
71:call add(tl, [2, "\\Z\u05b9", "xy\u05b9z", "y\u05b9"])
72:call add(tl, [1, "\u05b9\\+\\Z", "xy\u05b9z\u05b9 ", "y\u05b9z\u05b9"])
73:call add(tl, [1, "\\Z\u05b9\\+", "xy\u05b9z\u05b9 ", "y\u05b9z\u05b9"])
Bram Moolenaar1d814752013-05-24 20:25:33 +020074
Bram Moolenaard2470e92013-05-21 13:30:21 +020075:"""" Combining different tests and features
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020076:call add(tl, [2, '[^[=a=]]\+', 'ddaãâbcd', 'dd'])
Bram Moolenaard2470e92013-05-21 13:30:21 +020077
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020078:"""" Run the tests
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020079
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020080:"
81:for t in tl
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020082: let re = t[0]
83: let pat = t[1]
84: let text = t[2]
85: let matchidx = 3
86: for engine in [0, 1, 2]
Bram Moolenaar3f1682e2013-05-26 14:32:05 +020087: if engine == 2 && re == 0 || engine == 1 && re == 1
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020088: continue
89: endif
90: let &regexpengine = engine
Bram Moolenaar16299b52013-05-30 18:45:23 +020091: try
92: let l = matchlist(text, pat)
93: catch
94: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", caused an exception: \"' . v:exception . '\"'
95: endtry
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020096:" check the match itself
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020097: if len(l) == 0 && len(t) > matchidx
98: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", did not match, expected: \"' . t[matchidx] . '\"'
99: elseif len(l) > 0 && len(t) == matchidx
100: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected no match'
101: elseif len(t) > matchidx && l[0] != t[matchidx]
102: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected: \"' . t[matchidx] . '\"'
103: else
104: $put ='OK ' . engine . ' - ' . pat
105: endif
106: if len(l) > 0
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +0200107:" check all the nine submatches
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +0200108: for i in range(1, 9)
109: if len(t) <= matchidx + i
110: let e = ''
111: else
112: let e = t[matchidx + i]
113: endif
114: if l[i] != e
115: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"'
116: endif
117: endfor
118: unlet i
119: endif
120: endfor
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +0200121:endfor
122:unlet t tl e l
123
Bram Moolenaarac7c33e2013-07-21 17:06:00 +0200124:" check that 'ambiwidth' does not change the meaning of \p
125:set regexpengine=1 ambiwidth=single
126:$put ='eng 1 ambi single: ' . match(\"\u00EC\", '\p')
127:set regexpengine=1 ambiwidth=double
128:$put ='eng 1 ambi double: ' . match(\"\u00EC\", '\p')
129:set regexpengine=2 ambiwidth=single
130:$put ='eng 2 ambi single: ' . match(\"\u00EC\", '\p')
131:set regexpengine=2 ambiwidth=double
132:$put ='eng 2 ambi double: ' . match(\"\u00EC\", '\p')
133
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +0200134:/\%#=1^Results/,$wq! test.out
135ENDTEST
136
137Results of test95: