comparison src/testdir/test_user_func.vim @ 17638:9ffec4eb8d33 v8.1.1816

patch 8.1.1816: cannot use a user defined function as a method commit https://github.com/vim/vim/commit/fcfe1a9b8950b8b211ab3b24d84b17c6847ea43f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 4 23:04:39 2019 +0200 patch 8.1.1816: cannot use a user defined function as a method Problem: Cannot use a user defined function as a method. Solution: Pass the base as the first argument to the user defined function after "->". (partly by FUJIWARA Takuya)
author Bram Moolenaar <Bram@vim.org>
date Sun, 04 Aug 2019 23:15:05 +0200
parents 1a911bd57f11
children 2a017e9dc6da
comparison
equal deleted inserted replaced
17637:698003085267 17638:9ffec4eb8d33
45 unlet g:FuncRef 45 unlet g:FuncRef
46 return a:a 46 return a:a
47 endfunc 47 endfunc
48 48
49 func Test_user_func() 49 func Test_user_func()
50 let g:FuncRef=function("FuncWithRef") 50 let g:FuncRef = function("FuncWithRef")
51 let g:counter = 0 51 let g:counter = 0
52 inoremap <expr> ( ListItem() 52 inoremap <expr> ( ListItem()
53 inoremap <expr> [ ListReset() 53 inoremap <expr> [ ListReset()
54 imap <expr> + Expr1() 54 imap <expr> + Expr1()
55 imap <expr> * Expr2() 55 imap <expr> * Expr2()
59 call assert_equal('fail', Compute(45, 0, "retval")) 59 call assert_equal('fail', Compute(45, 0, "retval"))
60 call assert_equal('nop', g:retval) 60 call assert_equal('nop', g:retval)
61 call assert_equal('ok', Compute(45, 5, "retval")) 61 call assert_equal('ok', Compute(45, 5, "retval"))
62 call assert_equal(9, g:retval) 62 call assert_equal(9, g:retval)
63 call assert_equal(333, g:FuncRef(333)) 63 call assert_equal(333, g:FuncRef(333))
64
65 let g:retval = "nop"
66 call assert_equal('xxx4asdf', "xxx"->Table(4, "asdf"))
67 call assert_equal('fail', 45->Compute(0, "retval"))
68 call assert_equal('nop', g:retval)
69 call assert_equal('ok', 45->Compute(5, "retval"))
70 call assert_equal(9, g:retval)
71 " call assert_equal(333, 333->g:FuncRef())
64 72
65 enew 73 enew
66 74
67 normal oXX+-XX 75 normal oXX+-XX
68 call assert_equal('XX111-XX', getline('.')) 76 call assert_equal('XX111-XX', getline('.'))
142 \ .. " function Args2(a = 1, b = 2, c = 3)\n" 150 \ .. " function Args2(a = 1, b = 2, c = 3)\n"
143 \ .. "1 return deepcopy(a:)\n" 151 \ .. "1 return deepcopy(a:)\n"
144 \ .. " endfunction", 152 \ .. " endfunction",
145 \ execute('func Args2')) 153 \ execute('func Args2'))
146 endfunc 154 endfunc
155
156 func s:addFoo(lead)
157 return a:lead .. 'foo'
158 endfunc
159
160 func Test_user_method()
161 eval 'bar'->s:addFoo()->assert_equal('barfoo')
162 endfunc