diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-06-12 11:44:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-12 11:44:01 +0800 |
commit | 3c4890d1efe7c23c0bff7bc4532f19cf03c94e04 (patch) | |
tree | df2e7dec9bc967c4d0338fa1b142f39ba0deb750 | |
parent | 6e1fa16ddecca1b6e10563a75385cedea32f8911 (diff) | |
download | rneovim-3c4890d1efe7c23c0bff7bc4532f19cf03c94e04.tar.gz rneovim-3c4890d1efe7c23c0bff7bc4532f19cf03c94e04.tar.bz2 rneovim-3c4890d1efe7c23c0bff7bc4532f19cf03c94e04.zip |
test(old): reorder test_substitute.vim to match upstream (#23994)
-rw-r--r-- | test/old/testdir/test_substitute.vim | 418 |
1 files changed, 209 insertions, 209 deletions
diff --git a/test/old/testdir/test_substitute.vim b/test/old/testdir/test_substitute.vim index 75bd3cff6f..daa9426911 100644 --- a/test/old/testdir/test_substitute.vim +++ b/test/old/testdir/test_substitute.vim @@ -148,215 +148,6 @@ func Test_substitute_repeat() bwipe! endfunc -" Tests for *sub-replace-special* and *sub-replace-expression* on :substitute. - -" Execute a list of :substitute command tests -func Run_SubCmd_Tests(tests) - enew! - for t in a:tests - let start = line('.') + 1 - let end = start + len(t[2]) - 1 - exe "normal o" . t[0] - call cursor(start, 1) - exe t[1] - call assert_equal(t[2], getline(start, end), t[1]) - endfor - enew! -endfunc - -func Test_sub_cmd_1() - set magic - set cpo& - - " List entry format: [input, cmd, output] - let tests = [['A', 's/A/&&/', ['AA']], - \ ['B', 's/B/\&/', ['&']], - \ ['C123456789', 's/C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\0\9\8\7\6\5\4\3\2\1/', ['C123456789987654321']], - \ ['D', 's/D/d/', ['d']], - \ ['E', 's/E/~/', ['d']], - \ ['F', 's/F/\~/', ['~']], - \ ['G', 's/G/\ugg/', ['Gg']], - \ ['H', 's/H/\Uh\Eh/', ['Hh']], - \ ['I', 's/I/\lII/', ['iI']], - \ ['J', 's/J/\LJ\EJ/', ['jJ']], - \ ['K', 's/K/\Uk\ek/', ['Kk']], - \ ['lLl', "s/L/\<C-V>\<C-M>/", ["l\<C-V>", 'l']], - \ ['mMm', 's/M/\r/', ['m', 'm']], - \ ['nNn', "s/N/\\\<C-V>\<C-M>/", ["n\<C-V>", 'n']], - \ ['oOo', 's/O/\n/', ["o\no"]], - \ ['pPp', 's/P/\b/', ["p\<C-H>p"]], - \ ['qQq', 's/Q/\t/', ["q\tq"]], - \ ['rRr', 's/R/\\/', ['r\r']], - \ ['sSs', 's/S/\c/', ['scs']], - \ ['tTt', "s/T/\<C-V>\<C-J>/", ["t\<C-V>\<C-J>t"]], - \ ['U', 's/U/\L\uuUu\l\EU/', ['UuuU']], - \ ['V', 's/V/\U\lVvV\u\Ev/', ['vVVv']], - \ ['\', 's/\\/\\\\/', ['\\']] - \ ] - call Run_SubCmd_Tests(tests) -endfunc - -func Test_sub_cmd_2() - set nomagic - set cpo& - - " List entry format: [input, cmd, output] - let tests = [['A', 's/A/&&/', ['&&']], - \ ['B', 's/B/\&/', ['B']], - \ ['C123456789', 's/\mC\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\0\9\8\7\6\5\4\3\2\1/', ['C123456789987654321']], - \ ['D', 's/D/d/', ['d']], - \ ['E', 's/E/~/', ['~']], - \ ['F', 's/F/\~/', ['~']], - \ ['G', 's/G/\ugg/', ['Gg']], - \ ['H', 's/H/\Uh\Eh/', ['Hh']], - \ ['I', 's/I/\lII/', ['iI']], - \ ['J', 's/J/\LJ\EJ/', ['jJ']], - \ ['K', 's/K/\Uk\ek/', ['Kk']], - \ ['lLl', "s/L/\<C-V>\<C-M>/", ["l\<C-V>", 'l']], - \ ['mMm', 's/M/\r/', ['m', 'm']], - \ ['nNn', "s/N/\\\<C-V>\<C-M>/", ["n\<C-V>", 'n']], - \ ['oOo', 's/O/\n/', ["o\no"]], - \ ['pPp', 's/P/\b/', ["p\<C-H>p"]], - \ ['qQq', 's/Q/\t/', ["q\tq"]], - \ ['rRr', 's/R/\\/', ['r\r']], - \ ['sSs', 's/S/\c/', ['scs']], - \ ['tTt', "s/T/\<C-V>\<C-J>/", ["t\<C-V>\<C-J>t"]], - \ ['U', 's/U/\L\uuUu\l\EU/', ['UuuU']], - \ ['V', 's/V/\U\lVvV\u\Ev/', ['vVVv']], - \ ['\', 's/\\/\\\\/', ['\\']] - \ ] - call Run_SubCmd_Tests(tests) -endfunc - -func Test_sub_cmd_3() - set nomagic - set cpo& - - " List entry format: [input, cmd, output] - let tests = [['aAa', "s/A/\\='\\'/", ['a\a']], - \ ['bBb', "s/B/\\='\\\\'/", ['b\\b']], - \ ['cCc', "s/C/\\='\<C-V>\<C-M>'/", ["c\<C-V>", 'c']], - \ ['dDd', "s/D/\\='\\\<C-V>\<C-M>'/", ["d\\\<C-V>", 'd']], - \ ['eEe', "s/E/\\='\\\\\<C-V>\<C-M>'/", ["e\\\\\<C-V>", 'e']], - \ ['fFf', "s/F/\\='\r'/", ['f', 'f']], - \ ['gGg', "s/G/\\='\<C-V>\<C-J>'/", ["g\<C-V>", 'g']], - \ ['hHh', "s/H/\\='\\\<C-V>\<C-J>'/", ["h\\\<C-V>", 'h']], - \ ['iIi', "s/I/\\='\\\\\<C-V>\<C-J>'/", ["i\\\\\<C-V>", 'i']], - \ ['jJj', "s/J/\\='\n'/", ['j', 'j']], - \ ['kKk', 's/K/\="\r"/', ['k', 'k']], - \ ['lLl', 's/L/\="\n"/', ['l', 'l']] - \ ] - call Run_SubCmd_Tests(tests) -endfunc - -" Test for submatch() on :substitute. -func Test_sub_cmd_4() - set magic& - set cpo& - - " List entry format: [input, cmd, output] - let tests = [ ['aAa', "s/A/\\=substitute(submatch(0), '.', '\\', '')/", - \ ['a\a']], - \ ['bBb', "s/B/\\=substitute(submatch(0), '.', '\\', '')/", - \ ['b\b']], - \ ['cCc', "s/C/\\=substitute(submatch(0), '.', '\<C-V>\<C-M>', '')/", - \ ["c\<C-V>", 'c']], - \ ['dDd', "s/D/\\=substitute(submatch(0), '.', '\\\<C-V>\<C-M>', '')/", - \ ["d\<C-V>", 'd']], - \ ['eEe', "s/E/\\=substitute(submatch(0), '.', '\\\\\<C-V>\<C-M>', '')/", - \ ["e\\\<C-V>", 'e']], - \ ['fFf', "s/F/\\=substitute(submatch(0), '.', '\\r', '')/", - \ ['f', 'f']], - \ ['gGg', 's/G/\=substitute(submatch(0), ".", "\<C-V>\<C-J>", "")/', - \ ["g\<C-V>", 'g']], - \ ['hHh', 's/H/\=substitute(submatch(0), ".", "\\\<C-V>\<C-J>", "")/', - \ ["h\<C-V>", 'h']], - \ ['iIi', 's/I/\=substitute(submatch(0), ".", "\\\\\<C-V>\<C-J>", "")/', - \ ["i\\\<C-V>", 'i']], - \ ['jJj', "s/J/\\=substitute(submatch(0), '.', '\\n', '')/", - \ ['j', 'j']], - \ ['kKk', "s/K/\\=substitute(submatch(0), '.', '\\r', '')/", - \ ['k', 'k']], - \ ['lLl', "s/L/\\=substitute(submatch(0), '.', '\\n', '')/", - \ ['l', 'l']], - \ ] - call Run_SubCmd_Tests(tests) -endfunc - -func Test_sub_cmd_5() - set magic& - set cpo& - - " List entry format: [input, cmd, output] - let tests = [ ['A123456789', 's/A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . submatch(6) . submatch(5) . submatch(4) . submatch(3) . submatch(2) . submatch(1)/', ['A123456789987654321']], - \ ['B123456789', 's/B\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\=string([submatch(0, 1), submatch(9, 1), submatch(8, 1), submatch(7, 1), submatch(6, 1), submatch(5, 1), submatch(4, 1), submatch(3, 1), submatch(2, 1), submatch(1, 1)])/', ["[['B123456789'], ['9'], ['8'], ['7'], ['6'], ['5'], ['4'], ['3'], ['2'], ['1']]"]], - \ ] - call Run_SubCmd_Tests(tests) -endfunc - -" Test for *:s%* on :substitute. -func Test_sub_cmd_6() - set magic& - " Nvim: no "/" flag in 'cpoptions'. - " set cpo+=/ - - " List entry format: [input, cmd, output] - let tests = [ ['A', 's/A/a/', ['a']], - \ ['B', 's/B/%/', ['a']], - \ ] - " call Run_SubCmd_Tests(tests) - - set cpo-=/ - let tests = [ ['C', 's/C/c/', ['c']], - \ ['D', 's/D/%/', ['%']], - \ ] - call Run_SubCmd_Tests(tests) - - set cpo& -endfunc - -" Test for :s replacing \n with line break. -func Test_sub_cmd_7() - set magic& - set cpo& - - " List entry format: [input, cmd, output] - let tests = [ ["A\<C-V>\<C-M>A", 's/A./\=submatch(0)/', ['A', 'A']], - \ ["B\<C-V>\<C-J>B", 's/B./\=submatch(0)/', ['B', 'B']], - \ ["C\<C-V>\<C-J>C", 's/C./\=strtrans(string(submatch(0, 1)))/', [strtrans("['C\<C-J>']C")]], - \ ["D\<C-V>\<C-J>\nD", 's/D.\nD/\=strtrans(string(submatch(0, 1)))/', [strtrans("['D\<C-J>', 'D']")]], - \ ["E\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>E", 's/E\_.\{-}E/\=strtrans(string(submatch(0, 1)))/', [strtrans("['E\<C-J>', '\<C-J>', '\<C-J>', '\<C-J>', '\<C-J>E']")]], - \ ] - call Run_SubCmd_Tests(tests) - - exe "normal oQ\nQ\<Esc>k" - call assert_fails('s/Q[^\n]Q/\=submatch(0)."foobar"/', 'E486') - enew! -endfunc - -func TitleString() - let check = 'foo' =~ 'bar' - return "" -endfunc - -func Test_sub_cmd_8() - set titlestring=%{TitleString()} - - enew! - call append(0, ['', 'test_one', 'test_two']) - call cursor(1,1) - /^test_one/s/.*/\="foo\nbar"/ - call assert_equal('foo', getline(2)) - call assert_equal('bar', getline(3)) - call feedkeys(':/^test_two/s/.*/\="foo\nbar"/c', "t") - call feedkeys("\<CR>y", "xt") - call assert_equal('foo', getline(4)) - call assert_equal('bar', getline(5)) - - enew! - set titlestring& -endfunc - " Test %s/\n// which is implemented as a special case to use a " more efficient join rather than doing a regular substitution. func Test_substitute_join() @@ -669,6 +460,215 @@ func Test_substitute_partial() call assert_fails("call substitute('123', '2', Replacer, 'g')", 'E118') endfunc +" Tests for *sub-replace-special* and *sub-replace-expression* on :substitute. + +" Execute a list of :substitute command tests +func Run_SubCmd_Tests(tests) + enew! + for t in a:tests + let start = line('.') + 1 + let end = start + len(t[2]) - 1 + exe "normal o" . t[0] + call cursor(start, 1) + exe t[1] + call assert_equal(t[2], getline(start, end), t[1]) + endfor + enew! +endfunc + +func Test_sub_cmd_1() + set magic + set cpo& + + " List entry format: [input, cmd, output] + let tests = [['A', 's/A/&&/', ['AA']], + \ ['B', 's/B/\&/', ['&']], + \ ['C123456789', 's/C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\0\9\8\7\6\5\4\3\2\1/', ['C123456789987654321']], + \ ['D', 's/D/d/', ['d']], + \ ['E', 's/E/~/', ['d']], + \ ['F', 's/F/\~/', ['~']], + \ ['G', 's/G/\ugg/', ['Gg']], + \ ['H', 's/H/\Uh\Eh/', ['Hh']], + \ ['I', 's/I/\lII/', ['iI']], + \ ['J', 's/J/\LJ\EJ/', ['jJ']], + \ ['K', 's/K/\Uk\ek/', ['Kk']], + \ ['lLl', "s/L/\<C-V>\<C-M>/", ["l\<C-V>", 'l']], + \ ['mMm', 's/M/\r/', ['m', 'm']], + \ ['nNn', "s/N/\\\<C-V>\<C-M>/", ["n\<C-V>", 'n']], + \ ['oOo', 's/O/\n/', ["o\no"]], + \ ['pPp', 's/P/\b/', ["p\<C-H>p"]], + \ ['qQq', 's/Q/\t/', ["q\tq"]], + \ ['rRr', 's/R/\\/', ['r\r']], + \ ['sSs', 's/S/\c/', ['scs']], + \ ['tTt', "s/T/\<C-V>\<C-J>/", ["t\<C-V>\<C-J>t"]], + \ ['U', 's/U/\L\uuUu\l\EU/', ['UuuU']], + \ ['V', 's/V/\U\lVvV\u\Ev/', ['vVVv']], + \ ['\', 's/\\/\\\\/', ['\\']] + \ ] + call Run_SubCmd_Tests(tests) +endfunc + +func Test_sub_cmd_2() + set nomagic + set cpo& + + " List entry format: [input, cmd, output] + let tests = [['A', 's/A/&&/', ['&&']], + \ ['B', 's/B/\&/', ['B']], + \ ['C123456789', 's/\mC\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\0\9\8\7\6\5\4\3\2\1/', ['C123456789987654321']], + \ ['D', 's/D/d/', ['d']], + \ ['E', 's/E/~/', ['~']], + \ ['F', 's/F/\~/', ['~']], + \ ['G', 's/G/\ugg/', ['Gg']], + \ ['H', 's/H/\Uh\Eh/', ['Hh']], + \ ['I', 's/I/\lII/', ['iI']], + \ ['J', 's/J/\LJ\EJ/', ['jJ']], + \ ['K', 's/K/\Uk\ek/', ['Kk']], + \ ['lLl', "s/L/\<C-V>\<C-M>/", ["l\<C-V>", 'l']], + \ ['mMm', 's/M/\r/', ['m', 'm']], + \ ['nNn', "s/N/\\\<C-V>\<C-M>/", ["n\<C-V>", 'n']], + \ ['oOo', 's/O/\n/', ["o\no"]], + \ ['pPp', 's/P/\b/', ["p\<C-H>p"]], + \ ['qQq', 's/Q/\t/', ["q\tq"]], + \ ['rRr', 's/R/\\/', ['r\r']], + \ ['sSs', 's/S/\c/', ['scs']], + \ ['tTt', "s/T/\<C-V>\<C-J>/", ["t\<C-V>\<C-J>t"]], + \ ['U', 's/U/\L\uuUu\l\EU/', ['UuuU']], + \ ['V', 's/V/\U\lVvV\u\Ev/', ['vVVv']], + \ ['\', 's/\\/\\\\/', ['\\']] + \ ] + call Run_SubCmd_Tests(tests) +endfunc + +func Test_sub_cmd_3() + set nomagic + set cpo& + + " List entry format: [input, cmd, output] + let tests = [['aAa', "s/A/\\='\\'/", ['a\a']], + \ ['bBb', "s/B/\\='\\\\'/", ['b\\b']], + \ ['cCc', "s/C/\\='\<C-V>\<C-M>'/", ["c\<C-V>", 'c']], + \ ['dDd', "s/D/\\='\\\<C-V>\<C-M>'/", ["d\\\<C-V>", 'd']], + \ ['eEe', "s/E/\\='\\\\\<C-V>\<C-M>'/", ["e\\\\\<C-V>", 'e']], + \ ['fFf', "s/F/\\='\r'/", ['f', 'f']], + \ ['gGg', "s/G/\\='\<C-V>\<C-J>'/", ["g\<C-V>", 'g']], + \ ['hHh', "s/H/\\='\\\<C-V>\<C-J>'/", ["h\\\<C-V>", 'h']], + \ ['iIi', "s/I/\\='\\\\\<C-V>\<C-J>'/", ["i\\\\\<C-V>", 'i']], + \ ['jJj', "s/J/\\='\n'/", ['j', 'j']], + \ ['kKk', 's/K/\="\r"/', ['k', 'k']], + \ ['lLl', 's/L/\="\n"/', ['l', 'l']] + \ ] + call Run_SubCmd_Tests(tests) +endfunc + +" Test for submatch() on :substitute. +func Test_sub_cmd_4() + set magic& + set cpo& + + " List entry format: [input, cmd, output] + let tests = [ ['aAa', "s/A/\\=substitute(submatch(0), '.', '\\', '')/", + \ ['a\a']], + \ ['bBb', "s/B/\\=substitute(submatch(0), '.', '\\', '')/", + \ ['b\b']], + \ ['cCc', "s/C/\\=substitute(submatch(0), '.', '\<C-V>\<C-M>', '')/", + \ ["c\<C-V>", 'c']], + \ ['dDd', "s/D/\\=substitute(submatch(0), '.', '\\\<C-V>\<C-M>', '')/", + \ ["d\<C-V>", 'd']], + \ ['eEe', "s/E/\\=substitute(submatch(0), '.', '\\\\\<C-V>\<C-M>', '')/", + \ ["e\\\<C-V>", 'e']], + \ ['fFf', "s/F/\\=substitute(submatch(0), '.', '\\r', '')/", + \ ['f', 'f']], + \ ['gGg', 's/G/\=substitute(submatch(0), ".", "\<C-V>\<C-J>", "")/', + \ ["g\<C-V>", 'g']], + \ ['hHh', 's/H/\=substitute(submatch(0), ".", "\\\<C-V>\<C-J>", "")/', + \ ["h\<C-V>", 'h']], + \ ['iIi', 's/I/\=substitute(submatch(0), ".", "\\\\\<C-V>\<C-J>", "")/', + \ ["i\\\<C-V>", 'i']], + \ ['jJj', "s/J/\\=substitute(submatch(0), '.', '\\n', '')/", + \ ['j', 'j']], + \ ['kKk', "s/K/\\=substitute(submatch(0), '.', '\\r', '')/", + \ ['k', 'k']], + \ ['lLl', "s/L/\\=substitute(submatch(0), '.', '\\n', '')/", + \ ['l', 'l']], + \ ] + call Run_SubCmd_Tests(tests) +endfunc + +func Test_sub_cmd_5() + set magic& + set cpo& + + " List entry format: [input, cmd, output] + let tests = [ ['A123456789', 's/A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . submatch(6) . submatch(5) . submatch(4) . submatch(3) . submatch(2) . submatch(1)/', ['A123456789987654321']], + \ ['B123456789', 's/B\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\=string([submatch(0, 1), submatch(9, 1), submatch(8, 1), submatch(7, 1), submatch(6, 1), submatch(5, 1), submatch(4, 1), submatch(3, 1), submatch(2, 1), submatch(1, 1)])/', ["[['B123456789'], ['9'], ['8'], ['7'], ['6'], ['5'], ['4'], ['3'], ['2'], ['1']]"]], + \ ] + call Run_SubCmd_Tests(tests) +endfunc + +" Test for *:s%* on :substitute. +func Test_sub_cmd_6() + set magic& + " Nvim: no "/" flag in 'cpoptions'. + " set cpo+=/ + + " List entry format: [input, cmd, output] + let tests = [ ['A', 's/A/a/', ['a']], + \ ['B', 's/B/%/', ['a']], + \ ] + " call Run_SubCmd_Tests(tests) + + set cpo-=/ + let tests = [ ['C', 's/C/c/', ['c']], + \ ['D', 's/D/%/', ['%']], + \ ] + call Run_SubCmd_Tests(tests) + + set cpo& +endfunc + +" Test for :s replacing \n with line break. +func Test_sub_cmd_7() + set magic& + set cpo& + + " List entry format: [input, cmd, output] + let tests = [ ["A\<C-V>\<C-M>A", 's/A./\=submatch(0)/', ['A', 'A']], + \ ["B\<C-V>\<C-J>B", 's/B./\=submatch(0)/', ['B', 'B']], + \ ["C\<C-V>\<C-J>C", 's/C./\=strtrans(string(submatch(0, 1)))/', [strtrans("['C\<C-J>']C")]], + \ ["D\<C-V>\<C-J>\nD", 's/D.\nD/\=strtrans(string(submatch(0, 1)))/', [strtrans("['D\<C-J>', 'D']")]], + \ ["E\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>E", 's/E\_.\{-}E/\=strtrans(string(submatch(0, 1)))/', [strtrans("['E\<C-J>', '\<C-J>', '\<C-J>', '\<C-J>', '\<C-J>E']")]], + \ ] + call Run_SubCmd_Tests(tests) + + exe "normal oQ\nQ\<Esc>k" + call assert_fails('s/Q[^\n]Q/\=submatch(0)."foobar"/', 'E486') + enew! +endfunc + +func TitleString() + let check = 'foo' =~ 'bar' + return "" +endfunc + +func Test_sub_cmd_8() + set titlestring=%{TitleString()} + + enew! + call append(0, ['', 'test_one', 'test_two']) + call cursor(1,1) + /^test_one/s/.*/\="foo\nbar"/ + call assert_equal('foo', getline(2)) + call assert_equal('bar', getline(3)) + call feedkeys(':/^test_two/s/.*/\="foo\nbar"/c', "t") + call feedkeys("\<CR>y", "xt") + call assert_equal('foo', getline(4)) + call assert_equal('bar', getline(5)) + + enew! + set titlestring& +endfunc + func Test_sub_cmd_9() new let input = ['1 aaa', '2 aaa', '3 aaa'] |