blob: 2484ace1aa8a228d7d593e1d5d7786950684f776 [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.
23:call add(tl, ['[[:alpha:][=a=]]\+', '879 aiaãâaiuvna ', 'aiaãâaiuvna'])
24:call add(tl, ['[[=a=]]\+', 'ddaãâbcd', 'aãâ']) " equivalence classes
25:call add(tl, ['[^ม ]\+', 'มม oijasoifjos ifjoisj f osij j มมมมม abcd', 'oijasoifjos'])
26:call add(tl, [' [^ ]\+', 'start มabcdม ', ' มabcdม'])
27:call add(tl, ['[ม[:alpha:][=a=]]\+', '879 aiaãมâมaiuvna ', 'aiaãมâมaiuvna'])
28
Bram Moolenaar0fabe3f2013-05-21 12:34:17 +020029:" this is not a normal "i" but 0xec
30:call add(tl, ['\p\+', 'ìa', 'ìa'])
31
Bram Moolenaard2470e92013-05-21 13:30:21 +020032:"""" Test recognition of some character classes
Bram Moolenaar02e26d92013-05-23 22:43:08 +020033:call add(tl, ['\i\+', '&*¨xx ', 'xx'])
34:call add(tl, ['\%#=1\i\+', '&*¨xx ', 'xx'])
Bram Moolenaard2470e92013-05-21 13:30:21 +020035:call add(tl, ['\f\+', '&*Ÿfname ', 'fname'])
Bram Moolenaar02e26d92013-05-23 22:43:08 +020036:call add(tl, ['\%#=1\f\+', '&*Ÿfname ', 'fname'])
Bram Moolenaard2470e92013-05-21 13:30:21 +020037
Bram Moolenaar3c577f22013-05-24 21:59:54 +020038:"""" Test composing character matching
39:call add(tl, ['.ม', 'xม่x yมy', 'yม'])
40:call add(tl, ['.ม่', 'xม่x yมy', 'xม่'])
Bram Moolenaar56d58d52013-05-25 14:42:03 +020041:call add(tl, ["\u05b9", " x\u05b9 ", "x\u05b9"])
42:call add(tl, [".\u05b9", " x\u05b9 ", "x\u05b9"])
43:call add(tl, ["\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
44:call add(tl, [".\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
45:call add(tl, ["\u05bb\u05b9", " x\u05b9\u05bb "])
46:call add(tl, [".\u05bb\u05b9", " x\u05b9\u05bb "])
47:call add(tl, ["\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
48:call add(tl, [".\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
49
Bram Moolenaar3c577f22013-05-24 21:59:54 +020050
Bram Moolenaar1d814752013-05-24 20:25:33 +020051:"""" Test \Z
52:call add(tl, ['ú\Z', 'x'])
Bram Moolenaarfad8de02013-05-24 23:10:50 +020053:call add(tl, ['יהוה\Z', 'יהוה', 'יהוה'])
54:call add(tl, ['יְהוָה\Z', 'יהוה', 'יהוה'])
55:call add(tl, ['יהוה\Z', 'יְהוָה', 'יְהוָה'])
56:call add(tl, ['יְהוָה\Z', 'יְהוָה', 'יְהוָה'])
57:call add(tl, ['יְ\Z', 'וְיַ', 'יַ'])
58:call add(tl, ["ק\u200d\u05b9x\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
59:call add(tl, ["ק\u200d\u05b9x\\Z", "xק\u200dxy", "ק\u200dx"])
60:call add(tl, ["ק\u200dx\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
61:call add(tl, ["ק\u200dx\\Z", "xק\u200dxy", "ק\u200dx"])
Bram Moolenaar56d58d52013-05-25 14:42:03 +020062:call add(tl, ["\u05b9\\+\\Z", "xyz", "xyz"])
63:call add(tl, ["\\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
66:call add(tl, ['[^[=a=]]\+', 'ddaãâbcd', 'dd'])
67
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020068:"""" Run the tests
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020069:"
70:for t in tl
71: let l = matchlist(t[1], t[0])
72:" check the match itself
73: if len(l) == 0 && len(t) > 2
74: $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", did not match, expected: \"' . t[2] . '\"'
75: elseif len(l) > 0 && len(t) == 2
76: $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", match: \"' . l[0] . '\", expected no match'
77: elseif len(t) > 2 && l[0] != t[2]
78: $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", match: \"' . l[0] . '\", expected: \"' . t[2] . '\"'
79: else
80: $put ='OK - ' . t[0]
81: endif
82: if len(l) > 0
83:" check all the nine submatches
84: for i in range(1, 9)
85: if len(t) <= i + 2
86: let e = ''
87: else
88: let e = t[i + 2]
89: endif
90: if l[i] != e
91: $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"'
92: endif
93: endfor
94: unlet i
95: endif
96:endfor
97:unlet t tl e l
98
99:/\%#=1^Results/,$wq! test.out
100ENDTEST
101
102Results of test95: