diff options
author | Lucas Hoffmann <lucc@users.noreply.github.com> | 2016-06-08 06:25:53 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2016-06-08 00:25:53 -0400 |
commit | 38d98bba6808fcdd97717d1ce0d4df3589cb9ff7 (patch) | |
tree | 99016427f4333db83f633a694a593cee4861bc8f | |
parent | 15afd30e0488881107bb74836e8c10799ee273f8 (diff) | |
download | rneovim-38d98bba6808fcdd97717d1ce0d4df3589cb9ff7.tar.gz rneovim-38d98bba6808fcdd97717d1ce0d4df3589cb9ff7.tar.bz2 rneovim-38d98bba6808fcdd97717d1ce0d4df3589cb9ff7.zip |
tests: Migrate legacy test 34. (#2849)
-rw-r--r-- | src/nvim/testdir/Makefile | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test34.in | 86 | ||||
-rw-r--r-- | src/nvim/testdir/test34.ok | 10 | ||||
-rw-r--r-- | test/functional/legacy/034_user_function_spec.lua | 102 |
4 files changed, 102 insertions, 97 deletions
diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 52b3465db4..4b2b150ef2 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -16,7 +16,6 @@ SCRIPTS := \ test24.out \ test30.out \ test32.out \ - test34.out \ test37.out \ test40.out \ test42.out \ diff --git a/src/nvim/testdir/test34.in b/src/nvim/testdir/test34.in deleted file mode 100644 index 4cb7e9494a..0000000000 --- a/src/nvim/testdir/test34.in +++ /dev/null @@ -1,86 +0,0 @@ -Test for user functions. -Also test an <expr> mapping calling a function. -Also test that a builtin function cannot be replaced. -Also test for regression when calling arbitrary expression. - -STARTTEST -:function Table(title, ...) -: let ret = a:title -: let idx = 1 -: while idx <= a:0 -: exe "let ret = ret . a:" . idx -: let idx = idx + 1 -: endwhile -: return ret -:endfunction -:function Compute(n1, n2, divname) -: if a:n2 == 0 -: return "fail" -: endif -: exe "let g:" . a:divname . " = ". a:n1 / a:n2 -: return "ok" -:endfunction -:func Expr1() -: normal! v -: return "111" -:endfunc -:func Expr2() -: call search('XX', 'b') -: return "222" -:endfunc -:func ListItem() -: let g:counter += 1 -: return g:counter . '. ' -:endfunc -:func ListReset() -: let g:counter = 0 -: return '' -:endfunc -:func FuncWithRef(a) -: unlet g:FuncRef -: return a:a -:endfunc -:let g:FuncRef=function("FuncWithRef") -:let counter = 0 -:inoremap <expr> ( ListItem() -:inoremap <expr> [ ListReset() -:imap <expr> + Expr1() -:imap <expr> * Expr2() -:let retval = "nop" -/^here -C=Table("xxx", 4, "asdf") - =Compute(45, 0, "retval") - =retval - =Compute(45, 5, "retval") - =retval - =g:FuncRef(333) - -XX+-XX ----*--- -(one -(two -[(one again:call append(line('$'), max([1, 2, 3])) -:call extend(g:, {'max': function('min')}) -:call append(line('$'), max([1, 2, 3])) -:try -: " Regression: the first line below used to throw ?E110: Missing ')'? -: " Second is here just to prove that this line is correct when not skipping -: " rhs of &&. -: $put =(0&&(function('tr'))(1, 2, 3)) -: $put =(1&&(function('tr'))(1, 2, 3)) -:catch -: $put ='!!! Unexpected exception:' -: $put =v:exception -:endtry -:$-9,$w! test.out -:delfunc Table -:delfunc Compute -:delfunc Expr1 -:delfunc Expr2 -:delfunc ListItem -:delfunc ListReset -:unlet retval counter -:q! -ENDTEST - -here diff --git a/src/nvim/testdir/test34.ok b/src/nvim/testdir/test34.ok deleted file mode 100644 index 97995de80e..0000000000 --- a/src/nvim/testdir/test34.ok +++ /dev/null @@ -1,10 +0,0 @@ -xxx4asdf fail nop ok 9 333 -XX111-XX ----222--- -1. one -2. two -1. one again -3 -3 -0 -1 diff --git a/test/functional/legacy/034_user_function_spec.lua b/test/functional/legacy/034_user_function_spec.lua new file mode 100644 index 0000000000..f1337584f0 --- /dev/null +++ b/test/functional/legacy/034_user_function_spec.lua @@ -0,0 +1,102 @@ +-- Test for user functions. +-- Also test an <expr> mapping calling a function. +-- Also test that a builtin function cannot be replaced. +-- Also test for regression when calling arbitrary expression. + +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 + +describe('user functions, expr-mappings, overwrite protected builtin functions and regression on calling expressions', function() + setup(clear) + + it('are working', function() + insert('here') + + source([[ + function Table(title, ...) + let ret = a:title + let idx = 1 + while idx <= a:0 + exe "let ret = ret . a:" . idx + let idx = idx + 1 + endwhile + return ret + endfunction + function Compute(n1, n2, divname) + if a:n2 == 0 + return "fail" + endif + exe "let g:" . a:divname . " = ". a:n1 / a:n2 + return "ok" + endfunction + func Expr1() + normal! v + return "111" + endfunc + func Expr2() + call search('XX', 'b') + return "222" + endfunc + func ListItem() + let g:counter += 1 + return g:counter . '. ' + endfunc + func ListReset() + let g:counter = 0 + return '' + endfunc + func FuncWithRef(a) + unlet g:FuncRef + return a:a + endfunc + let g:FuncRef=function("FuncWithRef") + let counter = 0 + inoremap <expr> ( ListItem() + inoremap <expr> [ ListReset() + imap <expr> + Expr1() + imap <expr> * Expr2() + let retval = "nop" + /^here + ]]) + feed('C<C-R>=Table("xxx", 4, "asdf")<cr>') + -- Using a actual space will not work as feed() calls dedent on the input. + feed('<space><C-R>=Compute(45, 0, "retval")<cr>') + feed('<space><C-R>=retval<cr>') + feed('<space><C-R>=Compute(45, 5, "retval")<cr>') + feed('<space><C-R>=retval<cr>') + feed('<space><C-R>=g:FuncRef(333)<cr>') + feed('<cr>') + feed('XX+-XX<cr>') + feed('---*---<cr>') + feed('(one<cr>') + feed('(two<cr>') + feed('[(one again<esc>') + execute('call append(line("$"), max([1, 2, 3]))') + execute('call extend(g:, {"max": function("min")})') + execute('call append(line("$"), max([1, 2, 3]))') + execute('try') + -- Regression: the first line below used to throw "E110: Missing ')'" + -- Second is here just to prove that this line is correct when not + -- skipping rhs of &&. + execute([[ $put =(0&&(function('tr'))(1, 2, 3))]]) + execute([[ $put =(1&&(function('tr'))(1, 2, 3))]]) + execute('catch') + execute([[ $put ='!!! Unexpected exception:']]) + execute(' $put =v:exception') + execute('endtry') + + -- Assert buffer contents. + expect([[ + xxx4asdf fail nop ok 9 333 + XX111-XX + ---222--- + 1. one + 2. two + 1. one again + 3 + 3 + 0 + 1]]) + end) +end) |