test_nested_function.vim 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. " Tests for nested functions
  2. source check.vim
  3. func NestedFunc()
  4. func! Func1()
  5. let g:text .= 'Func1 '
  6. endfunc
  7. call Func1()
  8. func! s:func2()
  9. let g:text .= 's:func2 '
  10. endfunc
  11. call s:func2()
  12. func! s:_func3()
  13. let g:text .= 's:_func3 '
  14. endfunc
  15. call s:_func3()
  16. let fn = 'Func4'
  17. func! {fn}()
  18. let g:text .= 'Func4 '
  19. endfunc
  20. call {fn}()
  21. let fn = 'func5'
  22. func! s:{fn}()
  23. let g:text .= 's:func5'
  24. endfunc
  25. call s:{fn}()
  26. endfunc
  27. func Test_nested_functions()
  28. let g:text = ''
  29. call NestedFunc()
  30. call assert_equal('Func1 s:func2 s:_func3 Func4 s:func5', g:text)
  31. endfunction
  32. func Test_nested_argument()
  33. func g:X()
  34. let g:Y = function('sort')
  35. endfunc
  36. let g:Y = function('sort')
  37. echo g:Y([], g:X())
  38. delfunc g:X
  39. unlet g:Y
  40. endfunc
  41. func Recurse(count)
  42. if a:count > 0
  43. call Recurse(a:count - 1)
  44. endif
  45. endfunc
  46. func Test_max_nesting()
  47. " TODO: why does this fail on Windows? Runs out of stack perhaps?
  48. CheckNotMSWindows
  49. let call_depth_here = 2
  50. let ex_depth_here = 5
  51. set mfd&
  52. call Recurse(99 - call_depth_here)
  53. call assert_fails('call Recurse(' . (100 - call_depth_here) . ')', 'E132:')
  54. set mfd=210
  55. call Recurse(209 - ex_depth_here)
  56. call assert_fails('call Recurse(' . (210 - ex_depth_here) . ')', 'E169:')
  57. set mfd&
  58. endfunc
  59. " vim: shiftwidth=2 sts=2 expandtab