diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2019-09-05 14:10:32 -0700 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2019-09-05 14:10:32 -0700 |
| commit | 8b06231612cd608b2dce5e0a09bf40192a4803cb (patch) | |
| tree | 04fbfef7b326574e296b2fe1a772829ac0af8be4 /src/nvim/testdir | |
| parent | 096212d52c6375c19c046d86a7178bae91e287fc (diff) | |
| parent | d3f1eb3024fa297c970a79dd24ef818e4aeb8525 (diff) | |
| download | rneovim-8b06231612cd608b2dce5e0a09bf40192a4803cb.tar.gz rneovim-8b06231612cd608b2dce5e0a09bf40192a4803cb.tar.bz2 rneovim-8b06231612cd608b2dce5e0a09bf40192a4803cb.zip | |
Merge #10869 'vim-patch:8.1.{0309,0362,0365,0515,1946}'
Diffstat (limited to 'src/nvim/testdir')
| -rw-r--r-- | src/nvim/testdir/screendump.vim | 0 | ||||
| -rw-r--r-- | src/nvim/testdir/test_alot.vim | 1 | ||||
| -rw-r--r-- | src/nvim/testdir/test_expand_func.vim | 66 | ||||
| -rw-r--r-- | src/nvim/testdir/test_functions.vim | 27 | ||||
| -rw-r--r-- | src/nvim/testdir/test_maparg.vim | 19 | ||||
| -rw-r--r-- | src/nvim/testdir/test_options.vim | 2 | ||||
| -rw-r--r-- | src/nvim/testdir/test_profile.vim | 334 |
7 files changed, 403 insertions, 46 deletions
diff --git a/src/nvim/testdir/screendump.vim b/src/nvim/testdir/screendump.vim new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/src/nvim/testdir/screendump.vim diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index 30e29bd05d..6bf2e8329c 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -11,6 +11,7 @@ source test_ex_equal.vim source test_ex_undo.vim source test_ex_z.vim source test_execute_func.vim +source test_expand_func.vim source test_expr.vim source test_feedkeys.vim source test_filter_cmd.vim diff --git a/src/nvim/testdir/test_expand_func.vim b/src/nvim/testdir/test_expand_func.vim new file mode 100644 index 0000000000..fb29c3eb7a --- /dev/null +++ b/src/nvim/testdir/test_expand_func.vim @@ -0,0 +1,66 @@ +" Tests for expand() + +let s:sfile = expand('<sfile>') +let s:slnum = str2nr(expand('<slnum>')) +let s:sflnum = str2nr(expand('<sflnum>')) + +func s:expand_sfile() + return expand('<sfile>') +endfunc + +func s:expand_slnum() + return str2nr(expand('<slnum>')) +endfunc + +func s:expand_sflnum() + return str2nr(expand('<sflnum>')) +endfunc + +func Test_expand_sfile() + call assert_match('test_expand_func\.vim$', s:sfile) + call assert_match('^function .*\.\.Test_expand_sfile$', expand('<sfile>')) + + " Call in script-local function + call assert_match('^function .*\.\.Test_expand_sfile\[5\]\.\.<SNR>\d\+_expand_sfile$', s:expand_sfile()) + + " Call in command + command Sfile echo expand('<sfile>') + call assert_match('^function .*\.\.Test_expand_sfile$', trim(execute('Sfile'))) + delcommand Sfile +endfunc + +func Test_expand_slnum() + call assert_equal(4, s:slnum) + call assert_equal(2, str2nr(expand('<slnum>'))) + + " Line-continuation + call assert_equal( + \ 5, + \ str2nr(expand('<slnum>'))) + + " Call in script-local function + call assert_equal(1, s:expand_slnum()) + + " Call in command + command Slnum echo expand('<slnum>') + call assert_equal(14, str2nr(trim(execute('Slnum')))) + delcommand Slnum +endfunc + +func Test_expand_sflnum() + call assert_equal(5, s:sflnum) + call assert_equal(52, str2nr(expand('<sflnum>'))) + + " Line-continuation + call assert_equal( + \ 55, + \ str2nr(expand('<sflnum>'))) + + " Call in script-local function + call assert_equal(16, s:expand_sflnum()) + + " Call in command + command Flnum echo expand('<sflnum>') + call assert_equal(64, str2nr(trim(execute('Flnum')))) + delcommand Flnum +endfunc diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 6c3d944ad5..a36c51f56f 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1067,6 +1067,33 @@ func Test_func_range_with_edit() bwipe! endfunc +func Test_func_exists_on_reload() + call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists') + call assert_equal(0, exists('*ExistingFunction')) + source Xfuncexists + call assert_equal(1, exists('*ExistingFunction')) + " Redefining a function when reloading a script is OK. + source Xfuncexists + call assert_equal(1, exists('*ExistingFunction')) + + " But redefining in another script is not OK. + call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists2') + call assert_fails('source Xfuncexists2', 'E122:') + + delfunc ExistingFunction + call assert_equal(0, exists('*ExistingFunction')) + call writefile([ + \ 'func ExistingFunction()', 'echo "yes"', 'endfunc', + \ 'func ExistingFunction()', 'echo "no"', 'endfunc', + \ ], 'Xfuncexists') + call assert_fails('source Xfuncexists', 'E122:') + call assert_equal(1, exists('*ExistingFunction')) + + call delete('Xfuncexists2') + call delete('Xfuncexists') + delfunc ExistingFunction +endfunc + sandbox function Fsandbox() normal ix endfunc diff --git a/src/nvim/testdir/test_maparg.vim b/src/nvim/testdir/test_maparg.vim index 6324e39eec..0b941d51ec 100644 --- a/src/nvim/testdir/test_maparg.vim +++ b/src/nvim/testdir/test_maparg.vim @@ -10,23 +10,30 @@ function Test_maparg() set cpo-=< set encoding=utf8 " Test maparg() with a string result + let sid = s:SID() + let lnum = expand('<sflnum>') map foo<C-V> is<F4>foo vnoremap <script> <buffer> <expr> <silent> bar isbar - let sid = s:SID() call assert_equal("is<F4>foo", maparg('foo<C-V>')) call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>', - \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'rhs': 'is<F4>foo', - \ 'buffer': 0}, maparg('foo<C-V>', '', 0, 1)) + \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, + \ 'rhs': 'is<F4>foo', 'buffer': 0}, + \ maparg('foo<C-V>', '', 0, 1)) call assert_equal({'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v', - \ 'nowait': 0, 'expr': 1, 'sid': sid, 'rhs': 'isbar', 'buffer': 1}, + \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2, + \ 'rhs': 'isbar', 'buffer': 1}, \ maparg('bar', '', 0, 1)) + let lnum = expand('<sflnum>') map <buffer> <nowait> foo bar call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ', - \ 'nowait': 1, 'expr': 0, 'sid': sid, 'rhs': 'bar', 'buffer': 1}, + \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar', + \ 'buffer': 1}, \ maparg('foo', '', 0, 1)) + let lnum = expand('<sflnum>') tmap baz foo call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'baz', 'mode': 't', - \ 'nowait': 0, 'expr': 0, 'sid': sid, 'rhs': 'foo', 'buffer': 0}, + \ 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'foo', + \ 'buffer': 0}, \ maparg('baz', 't', 0, 1)) map abc x<char-114>x diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index ffd344200b..f4f5cbca61 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -216,7 +216,7 @@ func Test_set_completion() " Expand files and directories. call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx') - call assert_match('./samples/ ./sautest/ ./setup.vim ./shared.vim', @:) + call assert_match('./samples/ ./sautest/ ./screendump.vim ./setup.vim ./shared.vim', @:) call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) diff --git a/src/nvim/testdir/test_profile.vim b/src/nvim/testdir/test_profile.vim index 9b78d90b0b..7e853eeac3 100644 --- a/src/nvim/testdir/test_profile.vim +++ b/src/nvim/testdir/test_profile.vim @@ -3,6 +3,8 @@ if !has('profile') finish endif +source screendump.vim + func Test_profile_func() let lines = [ \ 'profile start Xprofile_func.log', @@ -49,36 +51,260 @@ func Test_profile_func() " - Unlike Foo3(), Foo2() should not be deleted since there is a check " for v:profiling. " - Bar() is not reported since it does not match "profile func Foo*". - call assert_equal(28, len(lines)) + call assert_equal(30, len(lines)) + + call assert_equal('FUNCTION Foo1()', lines[0]) + call assert_match('Defined:.*Xprofile_func.vim', lines[1]) + call assert_equal('Called 2 times', lines[2]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4]) + call assert_equal('', lines[5]) + call assert_equal('count total (s) self (s)', lines[6]) + call assert_equal('', lines[7]) + call assert_equal('FUNCTION Foo2()', lines[8]) + call assert_equal('Called 1 time', lines[10]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[11]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[12]) + call assert_equal('', lines[13]) + call assert_equal('count total (s) self (s)', lines[14]) + call assert_match('^\s*1\s\+.*\slet l:count = 100$', lines[15]) + call assert_match('^\s*101\s\+.*\swhile l:count > 0$', lines[16]) + call assert_match('^\s*100\s\+.*\s let l:count = l:count - 1$', lines[17]) + call assert_match('^\s*101\s\+.*\sendwhile$', lines[18]) + call assert_equal('', lines[19]) + call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[20]) + call assert_equal('count total (s) self (s) function', lines[21]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[22]) + call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[23]) + call assert_equal('', lines[24]) + call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[25]) + call assert_equal('count total (s) self (s) function', lines[26]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[27]) + call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[28]) + call assert_equal('', lines[29]) + + call delete('Xprofile_func.vim') + call delete('Xprofile_func.log') +endfunc + +func Test_profile_func_with_ifelse() + let lines = [ + \ "func! Foo1()", + \ " if 1", + \ " let x = 0", + \ " elseif 1", + \ " let x = 1", + \ " else", + \ " let x = 2", + \ " endif", + \ "endfunc", + \ "func! Foo2()", + \ " if 0", + \ " let x = 0", + \ " elseif 1", + \ " let x = 1", + \ " else", + \ " let x = 2", + \ " endif", + \ "endfunc", + \ "func! Foo3()", + \ " if 0", + \ " let x = 0", + \ " elseif 0", + \ " let x = 1", + \ " else", + \ " let x = 2", + \ " endif", + \ "endfunc", + \ "call Foo1()", + \ "call Foo2()", + \ "call Foo3()", + \ ] + + call writefile(lines, 'Xprofile_func.vim') + call system(v:progpath + \ . ' -es -u NONE -U NONE -i NONE --noplugin' + \ . ' -c "profile start Xprofile_func.log"' + \ . ' -c "profile func Foo*"' + \ . ' -c "so Xprofile_func.vim"' + \ . ' -c "qall!"') + call assert_equal(0, v:shell_error) + + let lines = readfile('Xprofile_func.log') + + " - Foo1() should pass 'if' block. + " - Foo2() should pass 'elseif' block. + " - Foo3() should pass 'else' block. + call assert_equal(57, len(lines)) + + call assert_equal('FUNCTION Foo1()', lines[0]) + call assert_match('Defined:.*Xprofile_func.vim', lines[1]) + call assert_equal('Called 1 time', lines[2]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4]) + call assert_equal('', lines[5]) + call assert_equal('count total (s) self (s)', lines[6]) + call assert_match('^\s*1\s\+.*\sif 1$', lines[7]) + call assert_match('^\s*1\s\+.*\s let x = 0$', lines[8]) + call assert_match( '^\s\+elseif 1$', lines[9]) + call assert_match( '^\s\+let x = 1$', lines[10]) + call assert_match( '^\s\+else$', lines[11]) + call assert_match( '^\s\+let x = 2$', lines[12]) + call assert_match('^\s*1\s\+.*\sendif$', lines[13]) + call assert_equal('', lines[14]) + call assert_equal('FUNCTION Foo2()', lines[15]) + call assert_equal('Called 1 time', lines[17]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[18]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[19]) + call assert_equal('', lines[20]) + call assert_equal('count total (s) self (s)', lines[21]) + call assert_match('^\s*1\s\+.*\sif 0$', lines[22]) + call assert_match( '^\s\+let x = 0$', lines[23]) + call assert_match('^\s*1\s\+.*\selseif 1$', lines[24]) + call assert_match('^\s*1\s\+.*\s let x = 1$', lines[25]) + call assert_match( '^\s\+else$', lines[26]) + call assert_match( '^\s\+let x = 2$', lines[27]) + call assert_match('^\s*1\s\+.*\sendif$', lines[28]) + call assert_equal('', lines[29]) + call assert_equal('FUNCTION Foo3()', lines[30]) + call assert_equal('Called 1 time', lines[32]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[33]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[34]) + call assert_equal('', lines[35]) + call assert_equal('count total (s) self (s)', lines[36]) + call assert_match('^\s*1\s\+.*\sif 0$', lines[37]) + call assert_match( '^\s\+let x = 0$', lines[38]) + call assert_match('^\s*1\s\+.*\selseif 0$', lines[39]) + call assert_match( '^\s\+let x = 1$', lines[40]) + call assert_match('^\s*1\s\+.*\selse$', lines[41]) + call assert_match('^\s*1\s\+.*\s let x = 2$', lines[42]) + call assert_match('^\s*1\s\+.*\sendif$', lines[43]) + call assert_equal('', lines[44]) + call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[45]) + call assert_equal('count total (s) self (s) function', lines[46]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[47]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[48]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[49]) + call assert_equal('', lines[50]) + call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[51]) + call assert_equal('count total (s) self (s) function', lines[52]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[53]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[54]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[55]) + call assert_equal('', lines[56]) + + call delete('Xprofile_func.vim') + call delete('Xprofile_func.log') +endfunc + +func Test_profile_func_with_trycatch() + let lines = [ + \ "func! Foo1()", + \ " try", + \ " let x = 0", + \ " catch", + \ " let x = 1", + \ " finally", + \ " let x = 2", + \ " endtry", + \ "endfunc", + \ "func! Foo2()", + \ " try", + \ " throw 0", + \ " catch", + \ " let x = 1", + \ " finally", + \ " let x = 2", + \ " endtry", + \ "endfunc", + \ "func! Foo3()", + \ " try", + \ " throw 0", + \ " catch", + \ " throw 1", + \ " finally", + \ " let x = 2", + \ " endtry", + \ "endfunc", + \ "call Foo1()", + \ "call Foo2()", + \ "try", + \ " call Foo3()", + \ "catch", + \ "endtry", + \ ] + + call writefile(lines, 'Xprofile_func.vim') + call system(v:progpath + \ . ' -es -u NONE -U NONE -i NONE --noplugin' + \ . ' -c "profile start Xprofile_func.log"' + \ . ' -c "profile func Foo*"' + \ . ' -c "so Xprofile_func.vim"' + \ . ' -c "qall!"') + call assert_equal(0, v:shell_error) + + let lines = readfile('Xprofile_func.log') + + " - Foo1() should pass 'try' 'finally' blocks. + " - Foo2() should pass 'catch' 'finally' blocks. + " - Foo3() should not pass 'endtry'. + call assert_equal(57, len(lines)) call assert_equal('FUNCTION Foo1()', lines[0]) - call assert_equal('Called 2 times', lines[1]) - call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[2]) - call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[3]) - call assert_equal('', lines[4]) - call assert_equal('count total (s) self (s)', lines[5]) - call assert_equal('', lines[6]) - call assert_equal('FUNCTION Foo2()', lines[7]) - call assert_equal('Called 1 time', lines[8]) - call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[9]) - call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[10]) - call assert_equal('', lines[11]) - call assert_equal('count total (s) self (s)', lines[12]) - call assert_match('^\s*1\s\+.*\slet l:count = 100$', lines[13]) - call assert_match('^\s*101\s\+.*\swhile l:count > 0$', lines[14]) - call assert_match('^\s*100\s\+.*\s let l:count = l:count - 1$', lines[15]) - call assert_match('^\s*100\s\+.*\sendwhile$', lines[16]) - call assert_equal('', lines[17]) - call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[18]) - call assert_equal('count total (s) self (s) function', lines[19]) - call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[20]) - call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[21]) - call assert_equal('', lines[22]) - call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[23]) - call assert_equal('count total (s) self (s) function', lines[24]) - call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[25]) - call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[26]) - call assert_equal('', lines[27]) + call assert_match('Defined:.*Xprofile_func.vim', lines[1]) + call assert_equal('Called 1 time', lines[2]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4]) + call assert_equal('', lines[5]) + call assert_equal('count total (s) self (s)', lines[6]) + call assert_match('^\s*1\s\+.*\stry$', lines[7]) + call assert_match('^\s*1\s\+.*\s let x = 0$', lines[8]) + call assert_match( '^\s\+catch$', lines[9]) + call assert_match( '^\s\+let x = 1$', lines[10]) + call assert_match('^\s*1\s\+.*\sfinally$', lines[11]) + call assert_match('^\s*1\s\+.*\s let x = 2$', lines[12]) + call assert_match('^\s*1\s\+.*\sendtry$', lines[13]) + call assert_equal('', lines[14]) + call assert_equal('FUNCTION Foo2()', lines[15]) + call assert_equal('Called 1 time', lines[17]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[18]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[19]) + call assert_equal('', lines[20]) + call assert_equal('count total (s) self (s)', lines[21]) + call assert_match('^\s*1\s\+.*\stry$', lines[22]) + call assert_match('^\s*1\s\+.*\s throw 0$', lines[23]) + call assert_match('^\s*1\s\+.*\scatch$', lines[24]) + call assert_match('^\s*1\s\+.*\s let x = 1$', lines[25]) + call assert_match('^\s*1\s\+.*\sfinally$', lines[26]) + call assert_match('^\s*1\s\+.*\s let x = 2$', lines[27]) + call assert_match('^\s*1\s\+.*\sendtry$', lines[28]) + call assert_equal('', lines[29]) + call assert_equal('FUNCTION Foo3()', lines[30]) + call assert_equal('Called 1 time', lines[32]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[33]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[34]) + call assert_equal('', lines[35]) + call assert_equal('count total (s) self (s)', lines[36]) + call assert_match('^\s*1\s\+.*\stry$', lines[37]) + call assert_match('^\s*1\s\+.*\s throw 0$', lines[38]) + call assert_match('^\s*1\s\+.*\scatch$', lines[39]) + call assert_match('^\s*1\s\+.*\s throw 1$', lines[40]) + call assert_match('^\s*1\s\+.*\sfinally$', lines[41]) + call assert_match('^\s*1\s\+.*\s let x = 2$', lines[42]) + call assert_match( '^\s\+endtry$', lines[43]) + call assert_equal('', lines[44]) + call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[45]) + call assert_equal('count total (s) self (s) function', lines[46]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[47]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[48]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[49]) + call assert_equal('', lines[50]) + call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[51]) + call assert_equal('count total (s) self (s) function', lines[52]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[53]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[54]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[55]) + call assert_equal('', lines[56]) call delete('Xprofile_func.vim') call delete('Xprofile_func.log') @@ -123,7 +349,7 @@ func Test_profile_file() call assert_equal(' " a comment', lines[9]) " if self and total are equal we only get one number call assert_match('^\s*20\s\+\(\d\+\.\d\+\s\+\)\=\d\+\.\d\+\s\+call Foo()$', lines[10]) - call assert_match('^\s*20\s\+\d\+\.\d\+\s\+endfor$', lines[11]) + call assert_match('^\s*22\s\+\d\+\.\d\+\s\+endfor$', lines[11]) " if self and total are equal we only get one number call assert_match('^\s*2\s\+\(\d\+\.\d\+\s\+\)\=\d\+\.\d\+\s\+call Foo()$', lines[12]) call assert_equal('', lines[13]) @@ -249,18 +475,19 @@ func Test_profdel_func() call assert_equal(0, v:shell_error) let lines = readfile('Xprofile_file.log') - call assert_equal(24, len(lines)) + call assert_equal(26, len(lines)) " Check that: " - Foo1() is called twice (profdel not invoked) " - Foo2() is called once (profdel invoked after it was called) " - Foo3() is not called (profdel invoked before it was called) call assert_equal('FUNCTION Foo1()', lines[0]) - call assert_equal('Called 2 times', lines[1]) - call assert_equal('FUNCTION Foo2()', lines[7]) - call assert_equal('Called 1 time', lines[8]) - call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[14]) - call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[19]) + call assert_match('Defined:.*Xprofile_file.vim', lines[1]) + call assert_equal('Called 2 times', lines[2]) + call assert_equal('FUNCTION Foo2()', lines[8]) + call assert_equal('Called 1 time', lines[10]) + call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[16]) + call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[21]) call delete('Xprofile_file.vim') call delete('Xprofile_file.log') @@ -282,13 +509,42 @@ func Test_profdel_star() call assert_equal(0, v:shell_error) let lines = readfile('Xprofile_file.log') - call assert_equal(15, len(lines)) + call assert_equal(16, len(lines)) call assert_equal('FUNCTION Foo()', lines[0]) - call assert_equal('Called 1 time', lines[1]) - call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[7]) - call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[11]) + call assert_match('Defined:.*Xprofile_file.vim', lines[1]) + call assert_equal('Called 1 time', lines[2]) + call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[8]) + call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[12]) call delete('Xprofile_file.vim') call delete('Xprofile_file.log') endfunc + +" When typing the function it won't have a script ID, test that this works. +func Test_profile_typed_func() + if !CanRunVimInTerminal() + throw 'Skipped: cannot run Vim in a terminal window' + endif + + let lines =<< trim END + profile start XprofileTypedFunc + END + call writefile(lines, 'XtestProfile') + let buf = RunVimInTerminal('-S XtestProfile', #{}) + + call term_sendkeys(buf, ":func DoSomething()\<CR>" + \ .. "echo 'hello'\<CR>" + \ .. "endfunc\<CR>") + call term_sendkeys(buf, ":profile func DoSomething\<CR>") + call term_sendkeys(buf, ":call DoSomething()\<CR>") + call term_wait(buf, 200) + call StopVimInTerminal(buf) + let lines = readfile('XprofileTypedFunc') + call assert_equal("FUNCTION DoSomething()", lines[0]) + call assert_equal("Called 1 time", lines[1]) + + " clean up + call delete('XprofileTypedFunc') + call delete('XtestProfile') +endfunc |