robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
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 ) 17insert ( [[ 181 a aa abb abbccc 192 d dd dee deefff 203 g gg ghh ghhiii 214 j jj jkk jkklll 225 m mm mnn mnnooo 236 x ^aa$ x 247 (a)(b) abbaa 258 axx [ab]xx 269 หม่x อมx 27a อมx หม่x 28b ちカヨは 29c x ¬€x 30d 天使x 31e ������y 32f ������z 33g a啷bb 34j 0123❤x 35k combinations 36l ä ö ü ᾱ̆́]] ) 37 38feed_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. 42feed ( '/^1<cr>' ) 43feed ( [[/a*b\{2}c\+/e<cr>x]] ) 44feed ( [[/\Md\*e\{2}f\+/e<cr>x]] ) 45feed_command ( 'set nomagic' ) 46feed ( [[/g\*h\{2}i\+/e<cr>x]] ) 47feed ( [[/\mj*k\{2}l\+/e<cr>x]] ) 48feed ( [[/\vm*n{2}o+/e<cr>x]] ) 49feed ( [[/\V^aa$<cr>x]] ) 50feed_command ( 'set magic' ) 51feed ( [[/\v(a)(b)\2\1\1/e<cr>x]] ) 52feed ( [[/\V[ab]\(\[xy]\)\1<cr>x]] ) 53 54-- Line 9. Search for multi-byte character without combining character. 55feed ( '/ม<cr>x' ) 56 57-- Line a. Search for multi-byte character with combining character. 58feed ( '/ม่<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.) 63feed_command ( [[/ち\<カヨ\>は]] ) 64feed ( 'x' ) 65 66-- Lines c-i. Test \%u, [\u], and friends. 67feed ( [[/\%u20ac<cr>x]] ) 68feed ( [[/[\u4f7f\u5929]\+<cr>x]] ) 69feed ( [[/\%U12345678<cr>x]] ) 70feed ( [[/[\U1234abcd\u1234\uabcd]<cr>x]] ) 71feed ( [[/\%d21879b<cr>x]] ) 72 73-- Line j. Test backwards search from a multi-byte character. 74feed ( '/x<cr>x' ) 75feed ( '?.<cr>x' ) 76 77-- Line k. Test substitution with combining characters by executing register 78-- contents. 79feed_command ( [[let @w=':%s#comb[i]nations#œ̄ṣ́m̥̄ᾱ̆́#g']] ) 80feed_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). 84feed_command ( [[/^l]] ) 85feed_command ( [[s/ \?/ /g]] ) 86 87-- Additional tests. Test matchstr() with multi-byte characters. 88feed ( 'G' ) 89feed_command ( [[put =matchstr(\"אבגד\", \".\", 0, 2)]] ) -- ב 90feed_command ( [[put =matchstr(\"אבגד\", \"..\", 0, 2)]] ) -- בג 91feed_command ( [[put =matchstr(\"אבגד\", \".\", 0, 0)]] ) -- א 92feed_command ( [[put =matchstr(\"אבגד\", \".\", 4, -1)]] ) -- ג 93 94-- Test that a search with "/e" offset wraps around at the end of the buffer. 95feed_command ( 'new' ) 96feed_command ( [[$put =['dog(a', 'cat('] ]] ) 97feed ( '/(/e+<cr>' ) 98feed ( '"ayn' ) 99feed_command ( 'bd!' ) 100feed_command ( [[$put ='']] ) 101feed ( 'G"ap' ) 102 103-- Assert buffer contents. 104expect ( [[ 1051 a aa abb abbcc 1062 d dd dee deeff 1073 g gg ghh ghhii 1084 j jj jkk jkkll 1095 m mm mnn mnnoo 1106 x aa$ x 1117 (a)(b) abba 1128 axx ab]xx 1139 หม่x อx 114a อมx หx 115b カヨは 116c x ¬x 117d 使x 118e y 119f z 120g abb 121j 012❤ 122k œ̄ṣ́m̥̄ᾱ̆́ 123l ä ö ü ᾱ̆́ 124ב 125בג 126א 127ג 128a 129cat(]] ) 130end 131 132describe ( 'multi-byte regexp search with magic settings' , function () 133before_each ( clear ) 134 135it ( 'is working with regexpengine=1' , function () 136-- The old test44. 137run_test_with_regexpengine ( 1 ) 138end ) 139 140it ( 'is working with regexpengine=2' , function () 141-- The old test99. 142run_test_with_regexpengine ( 2 ) 143end ) 144end )