robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
4.0 KiB144 linesraw
1-- Tests for regexp with multi-byte encoding and various magic settings.
2-- Test matchstr() with a count and multi-byte chars.
3--
4-- This test contains both "test44" and "test99" from the old test suite.
5
6local n = require('test.functional.testnvim')()
7local t = require('test.testutil')
8
9local describe, it, before_each = t.describe, t.it, t.before_each
10local feed, insert = n.feed, n.insert
11local clear, feed_command, expect = n.clear, n.feed_command, n.expect
12
13-- Runs the test protocol with the given 'regexpengine' setting. In the old test
14-- suite the test protocol was duplicated in test44 and test99, the only
15-- difference being the 'regexpengine' setting. We've extracted it here.
16local function run_test_with_regexpengine(regexpengine)
17  insert([[
18    1 a aa abb abbccc
19    2 d dd dee deefff
20    3 g gg ghh ghhiii
21    4 j jj jkk jkklll
22    5 m mm mnn mnnooo
23    6 x ^aa$ x
24    7 (a)(b) abbaa
25    8 axx [ab]xx
26    9 หม่x อมx
27    a อมx หม่x
28    b ちカヨは
29    c x ¬€x
30    d 天使x
31    e ������y
32    f ������z
33    g a啷bb
34    j 0123❤x
35    k combinations
36    l ä ö ü ᾱ̆́]])
37
38  feed_command('set re=' .. regexpengine)
39
40  -- Lines 1-8. Exercise regexp search with various magic settings. On each
41  -- line the character on which the cursor is expected to land is deleted.
42  feed('/^1<cr>')
43  feed([[/a*b\{2}c\+/e<cr>x]])
44  feed([[/\Md\*e\{2}f\+/e<cr>x]])
45  feed_command('set nomagic')
46  feed([[/g\*h\{2}i\+/e<cr>x]])
47  feed([[/\mj*k\{2}l\+/e<cr>x]])
48  feed([[/\vm*n{2}o+/e<cr>x]])
49  feed([[/\V^aa$<cr>x]])
50  feed_command('set magic')
51  feed([[/\v(a)(b)\2\1\1/e<cr>x]])
52  feed([[/\V[ab]\(\[xy]\)\1<cr>x]])
53
54  -- Line 9. Search for multi-byte character without combining character.
55  feed('/ม<cr>x')
56
57  -- Line a. Search for multi-byte character with combining character.
58  feed('/ม่<cr>x')
59
60  -- Line b. Find word by change of word class.
61  -- (The "<" character in this test step seemed to confuse our "feed" test
62  -- helper, which is why we've resorted to "execute" here.)
63  feed_command([[/ち\<カヨ\>は]])
64  feed('x')
65
66  -- Lines c-i. Test \%u, [\u], and friends.
67  feed([[/\%u20ac<cr>x]])
68  feed([[/[\u4f7f\u5929]\+<cr>x]])
69  feed([[/\%U12345678<cr>x]])
70  feed([[/[\U1234abcd\u1234\uabcd]<cr>x]])
71  feed([[/\%d21879b<cr>x]])
72
73  -- Line j. Test backwards search from a multi-byte character.
74  feed('/x<cr>x')
75  feed('?.<cr>x')
76
77  -- Line k. Test substitution with combining characters by executing register
78  -- contents.
79  feed_command([[let @w=':%s#comb[i]nations#œ̄ṣ́m̥̄ᾱ̆́#g']])
80  feed_command('@w')
81
82  -- Line l. Ex command ":s/ \?/ /g" should NOT split multi-byte characters
83  -- into bytes (fixed by vim-7.3.192).
84  feed_command([[/^l]])
85  feed_command([[s/ \?/ /g]])
86
87  -- Additional tests. Test matchstr() with multi-byte characters.
88  feed('G')
89  feed_command([[put =matchstr(\"אבגד\", \".\", 0, 2)]])   -- ב
90  feed_command([[put =matchstr(\"אבגד\", \"..\", 0, 2)]])  -- בג
91  feed_command([[put =matchstr(\"אבגד\", \".\", 0, 0)]])   -- א
92  feed_command([[put =matchstr(\"אבגד\", \".\", 4, -1)]])  -- ג
93
94  -- Test that a search with "/e" offset wraps around at the end of the buffer.
95  feed_command('new')
96  feed_command([[$put =['dog(a', 'cat('] ]])
97  feed('/(/e+<cr>')
98  feed('"ayn')
99  feed_command('bd!')
100  feed_command([[$put ='']])
101  feed('G"ap')
102
103  -- Assert buffer contents.
104  expect([[
105    1 a aa abb abbcc
106    2 d dd dee deeff
107    3 g gg ghh ghhii
108    4 j jj jkk jkkll
109    5 m mm mnn mnnoo
110    6 x aa$ x
111    7 (a)(b) abba
112    8 axx ab]xx
113    9 หม่x อx
114    a อมx หx
115    b カヨは
116    c x ¬x
117    d 使x
118    e y
119    f z
120    g abb
121    j 012❤
122    k œ̄ṣ́m̥̄ᾱ̆́
123     l ä ö ü ᾱ̆́
124    ב
125    בג
126    א
127    ג
128    a
129    cat(]])
130end
131
132describe('multi-byte regexp search with magic settings', function()
133  before_each(clear)
134
135  it('is working with regexpengine=1', function()
136    -- The old test44.
137    run_test_with_regexpengine(1)
138  end)
139
140  it('is working with regexpengine=2', function()
141    -- The old test99.
142    run_test_with_regexpengine(2)
143  end)
144end)