mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-03 17:24:29 +00:00 
			
		
		
		
	It is otherwise impossible to determine which test failed sanitizer/valgrind check. test/functional/helpers.lua module return was changed so that tests which do not provide after_each function to get new check will automatically fail.
		
			
				
	
	
		
			103 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			103 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
-- 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')(after_each)
 | 
						|
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)
 |