neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_nested_function.vim (1344B)


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