Bram Moolenaar | d7a06b1 | 2013-05-21 13:05:15 +0200 | [diff] [blame] | 1 | Test for regexp patterns with multi-byte support, using utf-8. |
Bram Moolenaar | fbc0d2e | 2013-05-19 19:40:29 +0200 | [diff] [blame] | 2 | See test64 for the non-multi-byte tests. |
| 3 | |
| 4 | A pattern that gives the expected result produces OK, so that we know it was |
| 5 | actually tried. |
| 6 | |
| 7 | STARTTEST |
| 8 | :so small.vim |
| 9 | :so mbyte.vim |
Bram Moolenaar | 1d81475 | 2013-05-24 20:25:33 +0200 | [diff] [blame^] | 10 | :set nocp encoding=utf-8 viminfo+=nviminfo nomore |
Bram Moolenaar | fbc0d2e | 2013-05-19 19:40:29 +0200 | [diff] [blame] | 11 | :" 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 Moolenaar | 0fabe3f | 2013-05-21 12:34:17 +0200 | [diff] [blame] | 29 | :" this is not a normal "i" but 0xec |
| 30 | :call add(tl, ['\p\+', 'ìa', 'ìa']) |
| 31 | |
Bram Moolenaar | d2470e9 | 2013-05-21 13:30:21 +0200 | [diff] [blame] | 32 | :"""" Test recognition of some character classes |
Bram Moolenaar | 02e26d9 | 2013-05-23 22:43:08 +0200 | [diff] [blame] | 33 | :call add(tl, ['\i\+', '&*¨xx ', 'xx']) |
| 34 | :call add(tl, ['\%#=1\i\+', '&*¨xx ', 'xx']) |
Bram Moolenaar | d2470e9 | 2013-05-21 13:30:21 +0200 | [diff] [blame] | 35 | :call add(tl, ['\f\+', '&*fname ', 'fname']) |
Bram Moolenaar | 02e26d9 | 2013-05-23 22:43:08 +0200 | [diff] [blame] | 36 | :call add(tl, ['\%#=1\f\+', '&*fname ', 'fname']) |
Bram Moolenaar | d2470e9 | 2013-05-21 13:30:21 +0200 | [diff] [blame] | 37 | |
Bram Moolenaar | 1d81475 | 2013-05-24 20:25:33 +0200 | [diff] [blame^] | 38 | :"""" Test \Z |
| 39 | :call add(tl, ['ú\Z', 'x']) |
| 40 | |
Bram Moolenaar | d2470e9 | 2013-05-21 13:30:21 +0200 | [diff] [blame] | 41 | :"""" Combining different tests and features |
| 42 | :call add(tl, ['[^[=a=]]\+', 'ddaãâbcd', 'dd']) |
| 43 | |
Bram Moolenaar | fbc0d2e | 2013-05-19 19:40:29 +0200 | [diff] [blame] | 44 | :"""" Run the tests |
Bram Moolenaar | fbc0d2e | 2013-05-19 19:40:29 +0200 | [diff] [blame] | 45 | :" |
| 46 | :for t in tl |
| 47 | : let l = matchlist(t[1], t[0]) |
| 48 | :" check the match itself |
| 49 | : if len(l) == 0 && len(t) > 2 |
| 50 | : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", did not match, expected: \"' . t[2] . '\"' |
| 51 | : elseif len(l) > 0 && len(t) == 2 |
| 52 | : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", match: \"' . l[0] . '\", expected no match' |
| 53 | : elseif len(t) > 2 && l[0] != t[2] |
| 54 | : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", match: \"' . l[0] . '\", expected: \"' . t[2] . '\"' |
| 55 | : else |
| 56 | : $put ='OK - ' . t[0] |
| 57 | : endif |
| 58 | : if len(l) > 0 |
| 59 | :" check all the nine submatches |
| 60 | : for i in range(1, 9) |
| 61 | : if len(t) <= i + 2 |
| 62 | : let e = '' |
| 63 | : else |
| 64 | : let e = t[i + 2] |
| 65 | : endif |
| 66 | : if l[i] != e |
| 67 | : $put ='ERROR: pat: \"' . t[0] . '\", text: \"' . t[1] . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"' |
| 68 | : endif |
| 69 | : endfor |
| 70 | : unlet i |
| 71 | : endif |
| 72 | :endfor |
| 73 | :unlet t tl e l |
| 74 | |
| 75 | :/\%#=1^Results/,$wq! test.out |
| 76 | ENDTEST |
| 77 | |
| 78 | Results of test95: |