vimscript_spec.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. local n = require('test.functional.testnvim')()
  2. local Screen = require('test.functional.ui.screen')
  3. local clear = n.clear
  4. local exec = n.exec
  5. local feed = n.feed
  6. local api = n.api
  7. before_each(clear)
  8. describe('Vim script', function()
  9. -- oldtest: Test_deep_nest()
  10. it('Error when if/for/while/try/function is nested too deep', function()
  11. local screen = Screen.new(80, 24)
  12. api.nvim_set_option_value('laststatus', 2, {})
  13. exec([[
  14. " Deep nesting of if ... endif
  15. func Test1()
  16. let @a = join(repeat(['if v:true'], 51), "\n")
  17. let @a ..= "\n"
  18. let @a ..= join(repeat(['endif'], 51), "\n")
  19. @a
  20. let @a = ''
  21. endfunc
  22. " Deep nesting of for ... endfor
  23. func Test2()
  24. let @a = join(repeat(['for i in [1]'], 51), "\n")
  25. let @a ..= "\n"
  26. let @a ..= join(repeat(['endfor'], 51), "\n")
  27. @a
  28. let @a = ''
  29. endfunc
  30. " Deep nesting of while ... endwhile
  31. func Test3()
  32. let @a = join(repeat(['while v:true'], 51), "\n")
  33. let @a ..= "\n"
  34. let @a ..= join(repeat(['endwhile'], 51), "\n")
  35. @a
  36. let @a = ''
  37. endfunc
  38. " Deep nesting of try ... endtry
  39. func Test4()
  40. let @a = join(repeat(['try'], 51), "\n")
  41. let @a ..= "\necho v:true\n"
  42. let @a ..= join(repeat(['endtry'], 51), "\n")
  43. @a
  44. let @a = ''
  45. endfunc
  46. " Deep nesting of function ... endfunction
  47. func Test5()
  48. let @a = join(repeat(['function X()'], 51), "\n")
  49. let @a ..= "\necho v:true\n"
  50. let @a ..= join(repeat(['endfunction'], 51), "\n")
  51. @a
  52. let @a = ''
  53. endfunc
  54. ]])
  55. screen:expect({ any = '%[No Name%]' })
  56. feed(':call Test1()<CR>')
  57. screen:expect({ any = 'E579: ' })
  58. feed('<C-C>')
  59. screen:expect({ any = '%[No Name%]' })
  60. feed(':call Test2()<CR>')
  61. screen:expect({ any = 'E585: ' })
  62. feed('<C-C>')
  63. screen:expect({ any = '%[No Name%]' })
  64. feed(':call Test3()<CR>')
  65. screen:expect({ any = 'E585: ' })
  66. feed('<C-C>')
  67. screen:expect({ any = '%[No Name%]' })
  68. feed(':call Test4()<CR>')
  69. screen:expect({ any = 'E601: ' })
  70. feed('<C-C>')
  71. screen:expect({ any = '%[No Name%]' })
  72. feed(':call Test5()<CR>')
  73. screen:expect({ any = 'E1058: ' })
  74. end)
  75. -- oldtest: Test_typed_script_var()
  76. it('using s: with a typed command', function()
  77. local screen = Screen.new(80, 24)
  78. feed(":echo get(s:, 'foo', 'x')\n")
  79. screen:expect({ any = 'E116: ' })
  80. end)
  81. end)