blob: 9c3ca8f1ddb8d6a60433b0aff25739743b6e0eb8 [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:
12:" regexp pattern
13:" text to test the pattern on
14:" expected match (optional)
15:" expected submatch 1 (optional)
16:" expected submatch 2 (optional)
17:" etc.
18:" When there is no match use only the first two items.
19:let tl = []
20
21:"""" Multi-byte character tests. These will fail unless vim is compiled
22:"""" with Multibyte (FEAT_MBYTE) or BIG/HUGE features.
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020023:call add(tl, [2, '[[:alpha:][=a=]]\+', '879 aiaãâaiuvna ', 'aiaãâaiuvna'])
24:call add(tl, [2, '[[=a=]]\+', 'ddaãâbcd', 'aãâ']) " equivalence classes
25:call add(tl, [2, '[^ม ]\+', 'มม oijasoifjos ifjoisj f osij j มมมมม abcd', 'oijasoifjos'])
26:call add(tl, [2, ' [^ ]\+', 'start มabcdม ', ' มabcdม'])
27:call add(tl, [2, '[ม[:alpha:][=a=]]\+', '879 aiaãมâมaiuvna ', 'aiaãมâมaiuvna'])
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020028
Bram Moolenaar0fabe3f2013-05-21 12:34:17 +020029:" this is not a normal "i" but 0xec
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020030:call add(tl, [2, '\p\+', 'ìa', 'ìa'])
Bram Moolenaar0fabe3f2013-05-21 12:34:17 +020031
Bram Moolenaard2470e92013-05-21 13:30:21 +020032:"""" Test recognition of some character classes
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020033:call add(tl, [2, '\i\+', '&*¨xx ', 'xx'])
34:call add(tl, [2, '\f\+', '&*Ÿfname ', 'fname'])
Bram Moolenaard2470e92013-05-21 13:30:21 +020035
Bram Moolenaar3c577f22013-05-24 21:59:54 +020036:"""" Test composing character matching
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020037:call add(tl, [2, '.ม', 'xม่x yมy', 'yม'])
38:call add(tl, [2, '.ม่', 'xม่x yมy', 'xม่'])
39:call add(tl, [2, "\u05b9", " x\u05b9 ", "x\u05b9"])
40:call add(tl, [2, ".\u05b9", " x\u05b9 ", "x\u05b9"])
41:call add(tl, [2, "\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
42:call add(tl, [2, ".\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
43:"call add(tl, [2, "\u05bb\u05b9", " x\u05b9\u05bb "])
44:"call add(tl, [2, ".\u05bb\u05b9", " x\u05b9\u05bb "])
45:call add(tl, [2, "\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
46:call add(tl, [2, ".\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
Bram Moolenaar56d58d52013-05-25 14:42:03 +020047
Bram Moolenaar3c577f22013-05-24 21:59:54 +020048
Bram Moolenaar1d814752013-05-24 20:25:33 +020049:"""" Test \Z
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020050:call add(tl, [2, 'ú\Z', 'x'])
51:call add(tl, [2, 'יהוה\Z', 'יהוה', 'יהוה'])
52:call add(tl, [2, 'יְהוָה\Z', 'יהוה', 'יהוה'])
53:call add(tl, [2, 'יהוה\Z', 'יְהוָה', 'יְהוָה'])
54:call add(tl, [2, 'יְהוָה\Z', 'יְהוָה', 'יְהוָה'])
55:call add(tl, [2, 'יְ\Z', 'וְיַ', 'יַ'])
56:call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
57:call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200dxy", "ק\u200dx"])
58:call add(tl, [2, "ק\u200dx\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
59:call add(tl, [2, "ק\u200dx\\Z", "xק\u200dxy", "ק\u200dx"])
60:"call add(tl, [2, "\u05b9\\Z", "xyz"])
61:"call add(tl, [2, "\\Z\u05b9", "xyz"])
62:"call add(tl, [2, "\u05b9\\+\\Z", "xyz", "xyz"])
63:"call add(tl, [2, "\\Z\u05b9\\+", "xyz", "xyz"])
Bram Moolenaar1d814752013-05-24 20:25:33 +020064
Bram Moolenaard2470e92013-05-21 13:30:21 +020065:"""" Combining different tests and features
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020066:call add(tl, [2, '[^[=a=]]\+', 'ddaãâbcd', 'dd'])
Bram Moolenaard2470e92013-05-21 13:30:21 +020067
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020068:"""" Run the tests
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020069
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020070:"
71:for t in tl
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020072: let re = t[0]
73: let pat = t[1]
74: let text = t[2]
75: let matchidx = 3
76: for engine in [0, 1, 2]
77: if engine == 2 && !re
78: continue
79: endif
80: let &regexpengine = engine
81: let l = matchlist(text, pat)
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020082:" check the match itself
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020083: if len(l) == 0 && len(t) > matchidx
84: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", did not match, expected: \"' . t[matchidx] . '\"'
85: elseif len(l) > 0 && len(t) == matchidx
86: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected no match'
87: elseif len(t) > matchidx && l[0] != t[matchidx]
88: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected: \"' . t[matchidx] . '\"'
89: else
90: $put ='OK ' . engine . ' - ' . pat
91: endif
92: if len(l) > 0
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020093:" check all the nine submatches
Bram Moolenaarfdb6dc12013-05-25 23:15:27 +020094: for i in range(1, 9)
95: if len(t) <= matchidx + i
96: let e = ''
97: else
98: let e = t[matchidx + i]
99: endif
100: if l[i] != e
101: $put ='ERROR: pat: \"' . pat . '\", text: \"' . text . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"'
102: endif
103: endfor
104: unlet i
105: endif
106: endfor
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +0200107:endfor
108:unlet t tl e l
109
110:/\%#=1^Results/,$wq! test.out
111ENDTEST
112
113Results of test95: