diff options
Diffstat (limited to 'test/functional/legacy')
| -rw-r--r-- | test/functional/legacy/057_sort_spec.lua | 603 | ||||
| -rw-r--r-- | test/functional/legacy/060_exists_and_has_functions_spec.lua | 28 | ||||
| -rw-r--r-- | test/functional/legacy/062_tab_pages_spec.lua | 240 | ||||
| -rw-r--r-- | test/functional/legacy/077_mf_hash_grow_spec.lua | 2 | ||||
| -rw-r--r-- | test/functional/legacy/080_substitute_spec.lua | 162 | ||||
| -rw-r--r-- | test/functional/legacy/mapping_spec.lua | 13 |
6 files changed, 1032 insertions, 16 deletions
diff --git a/test/functional/legacy/057_sort_spec.lua b/test/functional/legacy/057_sort_spec.lua new file mode 100644 index 0000000000..585b391198 --- /dev/null +++ b/test/functional/legacy/057_sort_spec.lua @@ -0,0 +1,603 @@ +-- Tests for :sort command. + +local helpers = require('test.functional.helpers') +local insert, execute, clear, expect, eq, eval, source = helpers.insert, + helpers.execute, helpers.clear, helpers.expect, helpers.eq, helpers.eval, + helpers.source + +describe(':sort', function() + local text = [[ + abc + ab + a + a321 + a123 + a122 + b321 + b123 + c123d + 123b + c321d + b322b + b321 + b321b + ]] + before_each(clear) + + it('alphabetical', function() + insert(text) + execute('sort') + expect([[ + + 123b + a + a122 + a123 + a321 + ab + abc + b123 + b321 + b321 + b321b + b322b + c123d + c321d]]) + end) + + it('numerical', function() + insert([[ + abc + ab + a321 + a123 + a122 + a + x-22 + b321 + b123 + c123d + -24 + 123b + c321d + 0 + b322b + b321 + b321b + ]]) + execute('sort n') + expect([[ + abc + ab + a + + -24 + x-22 + 0 + a122 + a123 + b123 + c123d + 123b + a321 + b321 + c321d + b321 + b321b + b322b]]) + end) + + it('hexadecimal', function() + insert(text) + execute('sort x') + expect([[ + + a + ab + abc + 123b + a122 + a123 + a321 + b123 + b321 + b321 + b321b + b322b + c123d + c321d]]) + end) + + it('alphabetical, unique', function() + insert(text) + execute('sort u') + expect([[ + + 123b + a + a122 + a123 + a321 + ab + abc + b123 + b321 + b321b + b322b + c123d + c321d]]) + end) + + it('alphabetical, reverse', function() + insert(text) + execute('sort!') + expect([[ + c321d + c123d + b322b + b321b + b321 + b321 + b123 + abc + ab + a321 + a123 + a122 + a + 123b + ]]) + end) + + it('numerical, reverse', function() + insert(text) + execute('sort! n') + expect([[ + b322b + b321b + b321 + c321d + b321 + a321 + 123b + c123d + b123 + a123 + a122 + + a + ab + abc]]) + end) + + it('unique, reverse', function() + insert(text) + execute('sort! u') + expect([[ + c321d + c123d + b322b + b321b + b321 + b123 + abc + ab + a321 + a123 + a122 + a + 123b + ]]) + end) + + it('octal', function() + insert(text) + execute('sort o') + expect([[ + abc + ab + a + + a122 + a123 + b123 + c123d + 123b + a321 + b321 + c321d + b321 + b321b + b322b]]) + end) + + it('reverse, hexadecimal', function() + insert(text) + execute('sort! x') + expect([[ + c321d + c123d + b322b + b321b + b321 + b321 + b123 + a321 + a123 + a122 + 123b + abc + ab + a + ]]) + end) + + it('alphabetical, skip first character', function() + insert(text) + execute('sort/./') + expect([[ + a + + a122 + a123 + b123 + 123b + c123d + a321 + b321 + b321 + b321b + c321d + b322b + ab + abc]]) + end) + + it('alphabetical, skip first 2 characters', function() + insert(text) + execute('sort/../') + expect([[ + ab + a + + a321 + b321 + b321 + b321b + c321d + a122 + b322b + a123 + b123 + 123b + c123d + abc]]) + end) + + it('alphabetical, unique, skip first 2 characters', function() + insert(text) + execute('sort/../u') + expect([[ + ab + a + + a321 + b321 + b321b + c321d + a122 + b322b + a123 + b123 + 123b + c123d + abc]]) + end) + + it('numerical, skip first character', function() + insert(text) + execute('sort/./n') + expect([[ + abc + ab + a + + a122 + a123 + b123 + c123d + 123b + a321 + b321 + c321d + b321 + b321b + b322b]]) + end) + + it('alphabetical, sort on first character', function() + insert(text) + execute('sort/./r') + expect([[ + + 123b + abc + ab + a + a321 + a123 + a122 + b321 + b123 + b322b + b321 + b321b + c123d + c321d]]) + end) + + it('alphabetical, sort on first 2 characters', function() + insert(text) + execute('sort/../r') + expect([[ + a + + 123b + a123 + a122 + a321 + abc + ab + b123 + b321 + b322b + b321 + b321b + c123d + c321d]]) + end) + + it('numerical, sort on first character', function() + insert(text) + execute('sort/./rn') + expect([[ + abc + ab + a + a321 + a123 + a122 + b321 + b123 + c123d + 123b + c321d + b322b + b321 + b321b + ]]) + end) + + it('alphabetical, skip past first digit', function() + insert(text) + execute([[sort/\d/]]) + expect([[ + abc + ab + a + + a321 + b321 + b321 + b321b + c321d + a122 + b322b + a123 + b123 + 123b + c123d]]) + end) + + it('alphabetical, sort on first digit', function() + insert(text) + execute([[sort/\d/r]]) + expect([[ + abc + ab + a + + a123 + a122 + b123 + c123d + 123b + a321 + b321 + c321d + b322b + b321 + b321b]]) + end) + + it('numerical, skip past first digit', function() + insert(text) + execute([[sort/\d/n]]) + expect([[ + abc + ab + a + + a321 + b321 + c321d + b321 + b321b + a122 + b322b + a123 + b123 + c123d + 123b]]) + end) + + it('numerical, sort on first digit', function() + insert(text) + execute([[sort/\d/rn]]) + expect([[ + abc + ab + a + + a123 + a122 + b123 + c123d + 123b + a321 + b321 + c321d + b322b + b321 + b321b]]) + end) + + it('alphabetical, skip past first 2 digits', function() + insert(text) + execute([[sort/\d\d/]]) + expect([[ + abc + ab + a + + a321 + b321 + b321 + b321b + c321d + a122 + b322b + a123 + b123 + 123b + c123d]]) + end) + + it('numerical, skip past first 2 digits', function() + insert(text) + execute([[sort/\d\d/n]]) + expect([[ + abc + ab + a + + a321 + b321 + c321d + b321 + b321b + a122 + b322b + a123 + b123 + c123d + 123b]]) + end) + + it('hexadecimal, skip past first 2 digits', function() + insert(text) + execute([[sort/\d\d/x]]) + expect([[ + abc + ab + a + + a321 + b321 + b321 + a122 + a123 + b123 + b321b + c321d + b322b + 123b + c123d]]) + end) + + it('alpha, on first 2 digits', function() + insert(text) + execute([[sort/\d\d/r]]) + expect([[ + abc + ab + a + + a123 + a122 + b123 + c123d + 123b + a321 + b321 + c321d + b322b + b321 + b321b]]) + end) + + it('numeric, on first 2 digits', function() + insert(text) + execute([[sort/\d\d/rn]]) + expect([[ + abc + ab + a + + a123 + a122 + b123 + c123d + 123b + a321 + b321 + c321d + b322b + b321 + b321b]]) + end) + + it('hexadecimal, on first 2 digits', function() + insert(text) + execute([[sort/\d\d/rx]]) + expect([[ + abc + ab + a + + a123 + a122 + b123 + c123d + 123b + a321 + b321 + c321d + b322b + b321 + b321b]]) + end) + + it('fails with wrong arguments', function() + insert(text) + -- This should fail with "E474: Invalid argument". + source([[ + try + sort no + catch + let tmpvar = v:exception + endtry]]) + eq('Vim(sort):E474: Invalid argument', eval('tmpvar')) + expect(text) + end) +end) diff --git a/test/functional/legacy/060_exists_and_has_functions_spec.lua b/test/functional/legacy/060_exists_and_has_functions_spec.lua index c4d2b01522..e9b79b490d 100644 --- a/test/functional/legacy/060_exists_and_has_functions_spec.lua +++ b/test/functional/legacy/060_exists_and_has_functions_spec.lua @@ -1,18 +1,15 @@ --- Tests for the exists() and has() functions. ts=8 sw=2 +-- Tests for the exists() and has() functions. 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 write_file = helpers.write_file -local os = require('os') describe('exists() and has() functions', function() - setup(clear) - - it('is working', function() - + setup(function() + clear() -- Create a temporary script needed for the test. - write_file('test60.vim', [=[ + write_file('test60.vim', [[ " Vim script for exists() function test " Script-local variables are checked here @@ -110,7 +107,14 @@ describe('exists() and has() functions', function() echo "FAILED" endif unlet str - ]=]) + ]]) + end) + teardown(function() + os.remove('test.out') + os.remove('test60.vim') + end) + + it('is working', function() source([=[ " Add the special directory with test scripts to &rtp @@ -648,7 +652,7 @@ describe('exists() and has() functions', function() ]=]) -- Assert buffer contents. - expect([=[ + expect([[ #myagroup: 1 OK @@ -859,11 +863,7 @@ describe('exists() and has() functions', function() has patch 7.1.999: 1 has patch 7.4.123: 1 has patch 9.1.0: 0 - has patch 9.9.1: 0]=]) + has patch 9.9.1: 0]]) end) - teardown(function() - os.remove('test.out') - os.remove('test60.vim') - end) end) diff --git a/test/functional/legacy/062_tab_pages_spec.lua b/test/functional/legacy/062_tab_pages_spec.lua new file mode 100644 index 0000000000..6bbb06f9a7 --- /dev/null +++ b/test/functional/legacy/062_tab_pages_spec.lua @@ -0,0 +1,240 @@ +-- Tests for tab pages + +local helpers = require('test.functional.helpers') +local feed, insert, source, clear, execute, expect, eval, eq = + helpers.feed, helpers.insert, helpers.source, helpers.clear, + helpers.execute, helpers.expect, helpers.eval, helpers.eq + +describe('tab pages', function() + before_each(clear) + + it('can be opened and closed', function() + execute('tabnew') + eq(2, eval('tabpagenr()')) + execute('quit') + eq(1, eval('tabpagenr()')) + end) + + it('can be iterated with :tabdo', function() + source([[ + 0tabnew + 1tabnew + $tabnew + tabdo call append(line('$'), 'this is tab page ' . tabpagenr()) + tabclose! 2 + tabrewind + ]]) + eq('this is tab page 1', eval("getline('$')")) + execute('tablast') + eq('this is tab page 4', eval("getline('$')")) + end) + + it('have local variables accasible with settabvar()/gettabvar()', function() + -- Test for settabvar() and gettabvar() functions. Open a new tab page and + -- set 3 variables to a number, string and a list. Verify that the + -- variables are correctly set. + source([[ + tabnew + tabfirst + call settabvar(2, 'val_num', 100) + call settabvar(2, 'val_str', 'SetTabVar test') + call settabvar(2, 'val_list', ['red', 'blue', 'green']) + ]]) + + eq(100, eval('gettabvar(2, "val_num")')) + eq('SetTabVar test', eval('gettabvar(2, "val_str")')) + eq({'red', 'blue', 'green'}, eval('gettabvar(2, "val_list")')) + execute('tabnext 2') + eq(100, eval('t:val_num')) + eq('SetTabVar test', eval('t:val_str')) + eq({'red', 'blue', 'green'}, eval('t:val_list')) + end) + + it('work together with the drop feature and loaded buffers', function() + -- Test for ":tab drop exist-file" to keep current window. + execute('sp test1') + execute('tab drop test1') + eq(1, eval('tabpagenr("$")')) + eq(2, eval('winnr("$")')) + eq(1, eval('winnr()')) + end) + + it('work together with the drop feature and new files', function() + -- Test for ":tab drop new-file" to keep current window of tabpage 1. + execute('split') + execute('tab drop newfile') + eq(2, eval('tabpagenr("$")')) + eq(2, eval('tabpagewinnr(1, "$")')) + eq(1, eval('tabpagewinnr(1)')) + end) + + it('work together with the drop feature and multi loaded buffers', function() + -- Test for ":tab drop multi-opend-file" to keep current tabpage and + -- window. + execute('new test1') + execute('tabnew') + execute('new test1') + execute('tab drop test1') + eq(2, eval('tabpagenr()')) + eq(2, eval('tabpagewinnr(2, "$")')) + eq(1, eval('tabpagewinnr(2)')) + end) + + it('can be navigated with :tabmove', function() + execute('lang C') + execute('for i in range(9) | tabnew | endfor') + feed('1gt') + eq(1, eval('tabpagenr()')) + execute('tabmove 5') + eq(6, eval('tabpagenr()')) + execute('tabmove -2') + eq(4, eval('tabpagenr()')) + execute('tabmove +4') + eq(8, eval('tabpagenr()')) + execute('tabmove') + eq(10, eval('tabpagenr()')) + execute('tabmove -20') + eq(1, eval('tabpagenr()')) + execute('tabmove +20') + eq(10, eval('tabpagenr()')) + execute('3tabmove') + eq(4, eval('tabpagenr()')) + execute('7tabmove 5') + eq(6, eval('tabpagenr()')) + execute('let a="No error caught."') + execute('try') + execute('tabmove foo') + execute('catch E474') + execute('let a="E474 caught."') + execute('endtry') + eq('E474 caught.', eval('a')) + end) + + it('can trigger certain autocommands', function() + insert('Results:') + + -- Test autocommands. + source([[ + tabonly! + let g:r=[] + command -nargs=1 -bar C :call add(g:r, '=== '.<q-args>.' ===')|<args> + function Test() + autocmd TabEnter * :call add(g:r, 'TabEnter') + autocmd WinEnter * :call add(g:r, 'WinEnter') + autocmd BufEnter * :call add(g:r, 'BufEnter') + autocmd TabLeave * :call add(g:r, 'TabLeave') + autocmd WinLeave * :call add(g:r, 'WinLeave') + autocmd BufLeave * :call add(g:r, 'BufLeave') + let t:a='a' + C tab split + let t:a='b' + C tabnew + let t:a='c' + call add(g:r, join(map(range(1, tabpagenr('$')), + \ 'gettabvar(v:val, "a")'))) + C call map(range(1, tabpagenr('$')), + \ 'settabvar(v:val, ''a'', v:val*2)') + call add(g:r, join(map(range(1, tabpagenr('$')), + \ 'gettabvar(v:val, "a")'))) + let w:a='a' + C vsplit + let w:a='a' + let tabn=tabpagenr() + let winr=range(1, winnr('$')) + C tabnext 1 + call add(g:r, join(map(copy(winr), + \ 'gettabwinvar('.tabn.', v:val, "a")'))) + C call map(copy(winr), + \ 'settabwinvar('.tabn.', v:val, ''a'', v:val*2)') + call add(g:r, join(map(copy(winr), + \ 'gettabwinvar('.tabn.', v:val, "a")'))) + augroup TabDestructive + autocmd TabEnter * :C tabnext 2 | C tabclose 3 + augroup END + C tabnext 3 + let g:r+=[tabpagenr().'/'.tabpagenr('$')] + autocmd! TabDestructive TabEnter + C tabnew + C tabnext 1 + autocmd TabDestructive TabEnter * nested + \ :C tabnext 2 | C tabclose 3 + C tabnext 3 + let g:r+=[tabpagenr().'/'.tabpagenr('$')] + endfunction + call Test() + $ put =g:r + ]]) + + -- Assert buffer contents. + expect([[ + Results: + === tab split === + WinLeave + TabLeave + WinEnter + TabEnter + === tabnew === + WinLeave + TabLeave + WinEnter + TabEnter + BufLeave + BufEnter + a b c + === call map(range(1, tabpagenr('$')), 'settabvar(v:val, ''a'', v:val*2)') === + 2 4 6 + === vsplit === + WinLeave + WinEnter + === tabnext 1 === + BufLeave + WinLeave + TabLeave + WinEnter + TabEnter + BufEnter + a a + === call map(copy(winr), 'settabwinvar('.tabn.', v:val, ''a'', v:val*2)') === + 2 4 + === tabnext 3 === + BufLeave + WinLeave + TabLeave + WinEnter + TabEnter + === tabnext 2 === + === tabclose 3 === + 2/2 + === tabnew === + WinLeave + TabLeave + WinEnter + TabEnter + BufLeave + BufEnter + === tabnext 1 === + BufLeave + WinLeave + TabLeave + WinEnter + TabEnter + BufEnter + === tabnext 3 === + BufLeave + WinLeave + TabLeave + WinEnter + TabEnter + === tabnext 2 === + BufLeave + WinLeave + TabLeave + WinEnter + TabEnter + === tabnext 2 === + === tabclose 3 === + BufEnter + === tabclose 3 === + 2/2]]) + end) +end) diff --git a/test/functional/legacy/077_mf_hash_grow_spec.lua b/test/functional/legacy/077_mf_hash_grow_spec.lua index 01d916ef04..825f08e968 100644 --- a/test/functional/legacy/077_mf_hash_grow_spec.lua +++ b/test/functional/legacy/077_mf_hash_grow_spec.lua @@ -15,7 +15,7 @@ describe('mf_hash_grow()', function() -- Check to see if cksum exists, otherwise skip the test if os.execute('which cksum 2>&1 > /dev/null') ~= 0 then - pending("was not tested because cksum was not found") + pending('was not tested because cksum was not found', function() end) else it('is working', function() execute('set fileformat=unix undolevels=-1') 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) diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua index c387d7484c..0843506827 100644 --- a/test/functional/legacy/mapping_spec.lua +++ b/test/functional/legacy/mapping_spec.lua @@ -23,16 +23,27 @@ describe('mapping', function() execute('set langmap=+{ langnoremap') feed('o+<esc>') - -- expr mapping with langmap. + -- Insert mode expr mapping with langmap. execute('inoremap <expr> { "FAIL_iexplangmap"') feed('o+<esc>') + -- langmap should not get remapped in cmdline mode. + execute('cnoremap { FAIL_clangmap') + feed('o+<esc>') + execute('cunmap {') + + -- cmdline mode expr mapping with langmap. + execute('cnoremap <expr> { "FAIL_cexplangmap"') + feed('o+<esc>') + execute('cunmap {') -- Assert buffer contents. expect([[ test starts here: vim + + + + + +]]) end) end) |