blob: 0f678794e9f16857d064d68ae6654e80b14dc8c1 [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 Moolenaar0fabe3f2013-05-21 12:34:17 +020032
Bram Moolenaard2470e92013-05-21 13:30:21 +020033:"""" Test recognition of some character classes
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020034:call add(tl, [2, '\i\+', '&*¨xx ', 'xx'])
35:call add(tl, [2, '\f\+', '&*Ÿfname ', 'fname'])
Bram Moolenaard2470e92013-05-21 13:30:21 +020036
Bram Moolenaar3c577f22013-05-24 21:59:54 +020037:"""" Test composing character matching
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020038:call add(tl, [2, '.ม', 'xม่x yมy', 'yม'])
39:call add(tl, [2, '.ม่', 'xม่x yมy', 'xม่'])
40:call add(tl, [2, "\u05b9", " x\u05b9 ", "x\u05b9"])
41:call add(tl, [2, ".\u05b9", " x\u05b9 ", "x\u05b9"])
42:call add(tl, [2, "\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
43:call add(tl, [2, ".\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
Bram Moolenaar3f1682e2013-05-26 14:32:05 +020044:call add(tl, [2, "\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
45:call add(tl, [2, ".\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020046:call add(tl, [2, "\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
47:call add(tl, [2, ".\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
Bram Moolenaar3f1682e2013-05-26 14:32:05 +020048:call add(tl, [2, "\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"])
49:call add(tl, [2, ".\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"])
50:call add(tl, [1, "\u05b9\u05bb", " y\u05b9 x\u05b9\u05bb ", "x\u05b9\u05bb"])
51:call add(tl, [2, ".\u05b9\u05bb", " y\u05bb x\u05b9\u05bb ", "x\u05b9\u05bb"])
Bram Moolenaar56d58d52013-05-25 14:42:03 +020052
Bram Moolenaar3c577f22013-05-24 21:59:54 +020053
Bram Moolenaar1d814752013-05-24 20:25:33 +020054:"""" Test \Z
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020055:call add(tl, [2, 'ú\Z', 'x'])
56:call add(tl, [2, 'יהוה\Z', 'יהוה', 'יהוה'])
57:call add(tl, [2, 'יְהוָה\Z', 'יהוה', 'יהוה'])
58:call add(tl, [2, 'יהוה\Z', 'יְהוָה', 'יְהוָה'])
59:call add(tl, [2, 'יְהוָה\Z', 'יְהוָה', 'יְהוָה'])
60:call add(tl, [2, 'יְ\Z', 'וְיַ', 'יַ'])
61:call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
62:call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200dxy", "ק\u200dx"])
63:call add(tl, [2, "ק\u200dx\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
64:call add(tl, [2, "ק\u200dx\\Z", "xק\u200dxy", "ק\u200dx"])
65:"call add(tl, [2, "\u05b9\\Z", "xyz"])
66:"call add(tl, [2, "\\Z\u05b9", "xyz"])
67:"call add(tl, [2, "\u05b9\\+\\Z", "xyz", "xyz"])
68:"call add(tl, [2, "\\Z\u05b9\\+", "xyz", "xyz"])
Bram Moolenaar1d814752013-05-24 20:25:33 +020069
Bram Moolenaard2470e92013-05-21 13:30:21 +020070:"""" Combining different tests and features
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020071:call add(tl, [2, '[^[=a=]]\+', 'ddaãâbcd', 'dd'])
Bram Moolenaard2470e92013-05-21 13:30:21 +020072
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020073:"""" Run the tests
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020074
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020075:"
76:for t in tl
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020077: let re = t[0]
78: let pat = t[1]
79: let text = t[2]
80: let matchidx = 3
81: for engine in [0, 1, 2]
Bram Moolenaar3f1682e2013-05-26 14:32:05 +020082: if engine == 2 && re == 0 || engine == 1 && re == 1
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020083: continue
84: endif
85: let &regexpengine = engine
86: let l = matchlist(text, pat)
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020087:" check the match itself
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020088: if len(l) == 0 && len(t) > matchidx
89: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", did not match, expected: \"' . t[matchidx] . '\"'
90: elseif len(l) > 0 && len(t) == matchidx
91: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected no match'
92: elseif len(t) > matchidx && l[0] != t[matchidx]
93: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected: \"' . t[matchidx] . '\"'
94: else
95: $put ='OK ' . engine . ' - ' . pat
96: endif
97: if len(l) > 0
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020098:" check all the nine submatches
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020099: for i in range(1, 9)
100: if len(t) <= matchidx + i
101: let e = ''
102: else
103: let e = t[matchidx + i]
104: endif
105: if l[i] != e
106: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"'
107: endif
108: endfor
109: unlet i
110: endif
111: endfor
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +0200112:endfor
113:unlet t tl e l
114
115:/\%#=1^Results/,$wq! test.out
116ENDTEST
117
118Results of test95: