diff options
author | Lucas Hoffmann <l-m-h@web.de> | 2015-07-10 12:12:09 +0200 |
---|---|---|
committer | Michael Reed <m.reed@mykolab.com> | 2015-07-21 19:56:15 -0400 |
commit | 6571c84d54a93e186bccf298bf4a3d0a45ddf28c (patch) | |
tree | 174f05f5347c56bc01f94d7a57e7f10e8a06a33d | |
parent | d6c97a85ff036e03b7fff202f111e65045bcc2bd (diff) | |
download | rneovim-6571c84d54a93e186bccf298bf4a3d0a45ddf28c.tar.gz rneovim-6571c84d54a93e186bccf298bf4a3d0a45ddf28c.tar.bz2 rneovim-6571c84d54a93e186bccf298bf4a3d0a45ddf28c.zip |
tests: Migrate legacy test 80. #2989
The test is also split in several blocks and heavily modernized. This was
done to prevent the following quoting and escaping problems during migration:
- the vim command `put =...` treats double quotes as the start of a comment so
they have to be escaped with a backslash
- when inserting control characters on the command line they have to be
escaped with <C-V>
The parts one and two of the test are functional identical so they are wrapped
in a local function. The only difference was which letters where used to test
the same feature.
Part six did test a flag in 'cpoptions' that has been removed in neovim. It
has therefore been removed as well.
Reviewed-by: Michael Reed <Pyrohh@users.noreply.github.com>
-rw-r--r-- | src/nvim/testdir/Makefile | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test80.in | 197 | ||||
-rw-r--r-- | src/nvim/testdir/test80.ok | 129 | ||||
-rw-r--r-- | test/functional/legacy/080_substitute_spec.lua | 162 |
4 files changed, 163 insertions, 327 deletions
diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index a07b3be1f5..29782d5e31 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -22,7 +22,7 @@ SCRIPTS := test_eval.out \ test64.out \ test68.out test69.out \ test73.out \ - test79.out test80.out \ + test79.out \ test83.out \ test86.out test87.out test88.out \ test_listlbr.out \ diff --git a/src/nvim/testdir/test80.in b/src/nvim/testdir/test80.in deleted file mode 100644 index e0bcb0114b..0000000000 --- a/src/nvim/testdir/test80.in +++ /dev/null @@ -1,197 +0,0 @@ -Test for *sub-replace-special* and *sub-replace-expression* on substitue(). -Test for submatch() on substitue(). -Test for *:s%* on :substitute. - -STARTTEST -:so small.vim -ENDTEST - -TEST_1: - -STARTTEST -:set magic -:set cpo& -:$put =\"\n\nTEST_1:\" -:$put =substitute('A', 'A', '&&', '') -:$put =substitute('B', 'B', '\&', '') -:$put =substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', '') -:$put =substitute('D', 'D', 'd', '') -:$put =substitute('E', 'E', '~', '') -:$put =substitute('F', 'F', '\~', '') -:$put =substitute('G', 'G', '\ugg', '') -:$put =substitute('H', 'H', '\Uh\Eh', '') -:$put =substitute('I', 'I', '\lII', '') -:$put =substitute('J', 'J', '\LJ\EJ', '') -:$put =substitute('K', 'K', '\Uk\ek', '') -:$put =substitute('lLl', 'L', '
', '') -:$put =substitute('mMm', 'M', '\r', '') -:$put =substitute('nNn', 'N', '\
', '') -:$put =substitute('oOo', 'O', '\n', '') -:$put =substitute('pPp', 'P', '\b', '') -:$put =substitute('qQq', 'Q', '\t', '') -:$put =substitute('rRr', 'R', '\\', '') -:$put =substitute('sSs', 'S', '\c', '') -:$put =substitute('uUu', 'U', \"\n\", '') -:$put =substitute('vVv', 'V', \"\b\", '') -:$put =substitute('wWw', 'W', \"\\\", '') -:$put =substitute('xXx', 'X', \"\r\", '') -:$put =substitute('Y', 'Y', '\L\uyYy\l\EY', '') -:$put =substitute('Z', 'Z', '\U\lZzZ\u\Ez', '') -/^TEST_2 -ENDTEST - -TEST_2: - -STARTTEST -:set nomagic -:set cpo& -:$put =\"\n\nTEST_2:\" -:$put =substitute('A', 'A', '&&', '') -:$put =substitute('B', 'B', '\&', '') -:$put =substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', '') -:$put =substitute('D', 'D', 'd', '') -:$put =substitute('E', 'E', '~', '') -:$put =substitute('F', 'F', '\~', '') -:$put =substitute('G', 'G', '\ugg', '') -:$put =substitute('H', 'H', '\Uh\Eh', '') -:$put =substitute('I', 'I', '\lII', '') -:$put =substitute('J', 'J', '\LJ\EJ', '') -:$put =substitute('K', 'K', '\Uk\ek', '') -:$put =substitute('lLl', 'L', '
', '') -:$put =substitute('mMm', 'M', '\r', '') -:$put =substitute('nNn', 'N', '\
', '') -:$put =substitute('oOo', 'O', '\n', '') -:$put =substitute('pPp', 'P', '\b', '') -:$put =substitute('qQq', 'Q', '\t', '') -:$put =substitute('rRr', 'R', '\\', '') -:$put =substitute('sSs', 'S', '\c', '') -:$put =substitute('tTt', 'T', \"\r\", '') -:$put =substitute('uUu', 'U', \"\n\", '') -:$put =substitute('vVv', 'V', \"\b\", '') -:$put =substitute('wWw', 'W', \"\\\", '') -:$put =substitute('X', 'X', '\L\uxXx\l\EX', '') -:$put =substitute('Y', 'Y', '\U\lYyY\u\Ey', '') -/^TEST_3 -ENDTEST - -TEST_3: - -STARTTEST -:set magic& -:set cpo& -:$put =\"\n\nTEST_3:\" -:let y = substitute('aAa', 'A', '\="\\"', '') | $put =y -:let y = substitute('bBb', 'B', '\="\\\\"', '') | $put =y -:let y = substitute('cCc', 'C', '\="
"', '') | $put =y -:let y = substitute('dDd', 'D', '\="\\
"', '') | $put =y -:let y = substitute('eEe', 'E', '\="\\\\
"', '') | $put =y -:let y = substitute('fFf', 'F', '\="\\r"', '') | $put =y -:let y = substitute('jJj', 'J', '\="\\n"', '') | $put =y -:let y = substitute('kKk', 'K', '\="\r"', '') | $put =y -:let y = substitute('lLl', 'L', '\="\n"', '') | $put =y -/^TEST_4 -ENDTEST - -TEST_4: - -STARTTEST -:set magic& -:set cpo& -:$put =\"\n\nTEST_4:\" -:let y = substitute('aAa', 'A', '\=substitute(submatch(0), ".", "\\", "")', '') | $put =y -:let y = substitute('bBb', 'B', '\=substitute(submatch(0), ".", "\\\\", "")', '') | $put =y -:let y = substitute('cCc', 'C', '\=substitute(submatch(0), ".", "
", "")', '') | $put =y -:let y = substitute('dDd', 'D', '\=substitute(submatch(0), ".", "\\
", "")', '') | $put =y -:let y = substitute('eEe', 'E', '\=substitute(submatch(0), ".", "\\\\
", "")', '') | $put =y -:let y = substitute('fFf', 'F', '\=substitute(submatch(0), ".", "\\r", "")', '') | $put =y -:let y = substitute('jJj', 'J', '\=substitute(submatch(0), ".", "\\n", "")', '') | $put =y -:let y = substitute('kKk', 'K', '\=substitute(submatch(0), ".", "\r", "")', '') | $put =y -:let y = substitute('lLl', 'L', '\=substitute(submatch(0), ".", "\n", "")', '') | $put =y -/^TEST_5 -ENDTEST - -TEST_5: - -STARTTEST -:set magic& -:set cpo& -:$put =\"\n\nTEST_5:\" -:$put =substitute('A123456789', 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . submatch(6) . submatch(5) . submatch(4) . submatch(3) . submatch(2) . submatch(1)', '') -:$put =substitute('A123456789', 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\=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)])', '') -/^TEST_6 -ENDTEST - -TEST_6: - -STARTTEST -:set magic& -:$put =\"\n\nTEST_6:\" -:$put =substitute('C', 'C', 'c', '') -:$put =substitute('D', 'D', '%', '') -/^TEST_7 -ENDTEST - -TEST_7: - -STARTTEST -:set magic& -:set cpo& -:$put =\"\n\nTEST_7:\" -:$put =substitute('A
A', 'A.', '\=submatch(0)', '') -:$put =substitute(\"B\nB\", 'B.', '\=submatch(0)', '') -:$put =substitute(\"B\nB\", 'B.', '\=string(submatch(0, 1))', '') -:$put =substitute('-bb', '\zeb', 'a', 'g') -:$put =substitute('-bb', '\ze', 'c', 'g') -/^TEST_8 -ENDTEST - -TEST_8: - -STARTTEST -:set magic& -:set cpo& -:$put =\"\n\nTEST_8:\" -:$put =',,X' -:s/\(^\|,\)\ze\(,\|X\)/\1N/g -:$put =',,Y' -:s/\(^\|,\)\ze\(,\|Y\)/\1N/gc -a:$put =',,Z' -:s/\(^\|,\)\ze\(,\|Z\)/\1N/gc -yy/^TEST_9: -ENDTEST - -TEST_9: - -STARTTEST -:set magic& -:set cpo& -:$put =\"\n\nTEST_9:\" -:$put ='xxx' -:s/x/X/gc -yyq/^TEST_10: -ENDTEST - -TEST_10: - -STARTTEST -:set magic& -:set cpo& -:$put =\"\n\nTEST_10:\" -:let y = substitute('123', '\zs', 'a', 'g') | $put =y -:let y = substitute('123', '\zs.', 'a', 'g') | $put =y -:let y = substitute('123', '.\zs', 'a', 'g') | $put =y -:let y = substitute('123', '\ze', 'a', 'g') | $put =y -:let y = substitute('123', '\ze.', 'a', 'g') | $put =y -:let y = substitute('123', '.\ze', 'a', 'g') | $put =y -:let y = substitute('123', '1\|\ze', 'a', 'g') | $put =y -:let y = substitute('123', '1\zs\|[23]', 'a', 'g') | $put =y -/^TEST_11 -ENDTEST - -TEST_11: - -STARTTEST -:/^Results/,$wq! test.out -ENDTEST - -Results of test72: diff --git a/src/nvim/testdir/test80.ok b/src/nvim/testdir/test80.ok deleted file mode 100644 index 157a42dfc1..0000000000 --- a/src/nvim/testdir/test80.ok +++ /dev/null @@ -1,129 +0,0 @@ -Results of test72: - - -TEST_1: -AA -& -C123456789987654321 -d -~ -~ -Gg -Hh -iI -jJ -Kk -l
l -m
m -n
n -o -o -pp -q q -r\r -scs -u -u -vv -w\w -x
x -YyyY -zZZz - - -TEST_2: -AA -& -C123456789987654321 -d -~ -~ -Gg -Hh -iI -jJ -Kk -l
l -m
m -n
n -o -o -pp -q q -r\r -scs -t
t -u -u -vv -w\w -XxxX -yYYy - - -TEST_3: -a\a -b\\b -c
c -d\
d -e\\
e -f\rf -j\nj -k
k -l -l - - -TEST_4: -a\a -b\b -c
c -d
d -e\
e -f
f -j -j -k
k -l -l - - -TEST_5: -A123456789987654321 -[['A123456789'], ['9'], ['8'], ['7'], ['6'], ['5'], ['4'], ['3'], ['2'], ['1']] - - -TEST_6: -c -% - - -TEST_7: -A
A -B -B -['B -']B --abab -c-cbcbc - - -TEST_8: -N,,NX -N,,NY -N,,NZ - - -TEST_9: -XXx - - -TEST_10: -a1a2a3a -aaa -1a2a3a -a1a2a3a -a1a2a3 -aaa -aa2a3a -1aaa diff --git a/test/functional/legacy/080_substitute_spec.lua b/test/functional/legacy/080_substitute_spec.lua new file mode 100644 index 0000000000..89ef7a713c --- /dev/null +++ b/test/functional/legacy/080_substitute_spec.lua @@ -0,0 +1,162 @@ +-- Test for *sub-replace-special* and *sub-replace-expression* on substitue(). +-- Test for submatch() on substitue(). +-- Test for *:s%* on :substitute. + +local helpers = require('test.functional.helpers') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect +local eq, eval = helpers.eq, helpers.eval + +describe('substitue()', function() + before_each(clear) + + -- The original test contained several TEST_X lines to delimit different + -- parts. These where used to split the test into different it() blocks. + -- The TEST_X strings are repeated in the description of the blocks to make + -- it easier to incorporate upstream changes. + + local function test_1_and_2() + eq('AA', eval("substitute('A', 'A', '&&', '')")) + eq('&', eval([[substitute('B', 'B', '\&', '')]])) + eq('C123456789987654321', eval([[substitute('C123456789', ]] .. + [['C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] .. + [['\0\9\8\7\6\5\4\3\2\1', '')]])) + eq('d', eval("substitute('D', 'D', 'd', '')")) + eq('~', eval("substitute('E', 'E', '~', '')")) + eq('~', eval([[substitute('F', 'F', '\~', '')]])) + eq('Gg', eval([[substitute('G', 'G', '\ugg', '')]])) + eq('Hh', eval([[substitute('H', 'H', '\Uh\Eh', '')]])) + eq('iI', eval([[substitute('I', 'I', '\lII', '')]])) + eq('jJ', eval([[substitute('J', 'J', '\LJ\EJ', '')]])) + eq('Kk', eval([[substitute('K', 'K', '\Uk\ek', '')]])) + eq('l\rl', eval("substitute('lLl', 'L', '\r', '')")) + eq('m\rm', eval([[substitute('mMm', 'M', '\r', '')]])) + eq('n\rn', eval("substitute('nNn', 'N', '\\\r', '')")) + eq('o\no', eval([[substitute('oOo', 'O', '\n', '')]])) + eq('p\bp', eval([[substitute('pPp', 'P', '\b', '')]])) + eq('q\tq', eval([[substitute('qQq', 'Q', '\t', '')]])) + eq('r\\r', eval([[substitute('rRr', 'R', '\\', '')]])) + eq('scs', eval([[substitute('sSs', 'S', '\c', '')]])) + eq('t\rt', eval([[substitute('tTt', 'T', "\r", '')]])) + eq('u\nu', eval([[substitute('uUu', 'U', "\n", '')]])) + eq('v\bv', eval([[substitute('vVv', 'V', "\b", '')]])) + eq('w\\w', eval([[substitute('wWw', 'W', "\\", '')]])) + eq('XxxX', eval([[substitute('X', 'X', '\L\uxXx\l\EX', '')]])) + eq('yYYy', eval([[substitute('Y', 'Y', '\U\lYyY\u\Ey', '')]])) + end + + it('with "set magic" (TEST_1)', function() + execute('set magic') + test_1_and_2() + end) + + it('with "set nomagic" (TEST_2)', function() + execute('set nomagic') + test_1_and_2() + end) + + it('with sub-replace-expression (TEST_3)', function() + execute('set magic&') + eq('a\\a', eval([[substitute('aAa', 'A', '\="\\"', '')]])) + eq('b\\\\b', eval([[substitute('bBb', 'B', '\="\\\\"', '')]])) + eq('c\rc', eval([[substitute('cCc', 'C', '\="]]..'\r'..[["', '')]])) + eq('d\\\rd', eval([[substitute('dDd', 'D', '\="\\]]..'\r'..[["', '')]])) + eq('e\\\\\re', + eval([[substitute('eEe', 'E', '\="\\\\]]..'\r'..[["', '')]])) + eq('f\\rf', eval([[substitute('fFf', 'F', '\="\\r"', '')]])) + eq('j\\nj', eval([[substitute('jJj', 'J', '\="\\n"', '')]])) + eq('k\rk', eval([[substitute('kKk', 'K', '\="\r"', '')]])) + eq('l\nl', eval([[substitute('lLl', 'L', '\="\n"', '')]])) + end) + + it('with submatch() (TEST_4)', function() + execute('set magic&') + eq('a\\a', eval([[substitute('aAa', 'A', ]] .. + [['\=substitute(submatch(0), ".", "\\", "")', '')]])) + eq('b\\b', eval([[substitute('bBb', 'B', ]] .. + [['\=substitute(submatch(0), ".", "\\\\", "")', '')]])) + eq('c\rc', eval([[substitute('cCc', 'C', ]] .. + [['\=substitute(submatch(0), ".", "]]..'\r'..[[", "")', '')]])) + eq('d\rd', eval([[substitute('dDd', 'D', ]] .. + [['\=substitute(submatch(0), ".", "\\]]..'\r'..[[", "")', '')]])) + eq('e\\\re', eval([[substitute('eEe', 'E', ]] .. + [['\=substitute(submatch(0), ".", "\\\\]]..'\r'..[[", "")', '')]])) + eq('f\rf', eval([[substitute('fFf', 'F', ]] .. + [['\=substitute(submatch(0), ".", "\\r", "")', '')]])) + eq('j\nj', eval([[substitute('jJj', 'J', ]] .. + [['\=substitute(submatch(0), ".", "\\n", "")', '')]])) + eq('k\rk', eval([[substitute('kKk', 'K', ]] .. + [['\=substitute(submatch(0), ".", "\r", "")', '')]])) + eq('l\nl', eval([[substitute('lLl', 'L', ]] .. + [['\=substitute(submatch(0), ".", "\n", "")', '')]])) + end) + + it('with submatch() (TEST_5)', function() + execute('set magic&') + eq('A123456789987654321', eval([[substitute('A123456789', ]] .. + [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] .. + [['\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . ]] .. + [[submatch(6) . submatch(5) . submatch(4) . submatch(3) . ]] .. + [[submatch(2) . submatch(1)', '')]])) + eq("[['A123456789'], ['9'], ['8'], ['7'], ['6'], ['5'], ['4'], ['3'], " .. + "['2'], ['1']]", eval([[substitute('A123456789', ]] .. + [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] .. + [['\=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)])', '')]])) + end) + + -- TEST_6 was about the 'cpoptions' flag / which was removed in pull request + -- #2943. + + it('with submatch or \\ze (TEST_7)', function() + execute('set magic&') + eq('A\rA', eval("substitute('A\rA', 'A.', '\\=submatch(0)', '')")) + eq('B\nB', eval([[substitute("B\nB", 'B.', '\=submatch(0)', '')]])) + eq("['B\n']B", + eval([[substitute("B\nB", 'B.', '\=string(submatch(0, 1))', '')]])) + eq('-abab', eval([[substitute('-bb', '\zeb', 'a', 'g')]])) + eq('c-cbcbc', eval([[substitute('-bb', '\ze', 'c', 'g')]])) + end) + + it('with \\zs and \\ze (TEST_10)', function() + execute('set magic&') + eq('a1a2a3a', eval([[substitute('123', '\zs', 'a', 'g')]])) + eq('aaa', eval([[substitute('123', '\zs.', 'a', 'g')]])) + eq('1a2a3a', eval([[substitute('123', '.\zs', 'a', 'g')]])) + eq('a1a2a3a', eval([[substitute('123', '\ze', 'a', 'g')]])) + eq('a1a2a3', eval([[substitute('123', '\ze.', 'a', 'g')]])) + eq('aaa', eval([[substitute('123', '.\ze', 'a', 'g')]])) + eq('aa2a3a', eval([[substitute('123', '1\|\ze', 'a', 'g')]])) + eq('1aaa', eval([[substitute('123', '1\zs\|[23]', 'a', 'g')]])) + end) +end) + +describe(':substitue', function() + before_each(clear) + + it('with \\ze and \\zs and confirmation dialog (TEST_8)', function() + insert([[ + ,,X + ,,Y + ,,Z]]) + execute('set magic&') + execute([[1s/\(^\|,\)\ze\(,\|X\)/\1N/g]]) + execute([[2s/\(^\|,\)\ze\(,\|Y\)/\1N/gc]]) + feed('a') -- For the dialog of the previous :s command. + execute([[3s/\(^\|,\)\ze\(,\|Z\)/\1N/gc]]) + feed('yy') -- For the dialog of the previous :s command. + expect([[ + N,,NX + N,,NY + N,,NZ]]) + end) + + it('with confirmation dialog (TEST_9)', function() + insert('xxx') + execute('set magic&') + execute('s/x/X/gc') + feed('yyq') -- For the dialog of the previous :s command. + expect('XXx') + end) +end) |