undolevels_spec.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local source, clear = n.source, n.clear
  4. local eq, api = t.eq, n.api
  5. describe('undolevel', function()
  6. setup(clear)
  7. it('is working', function()
  8. source([[
  9. func FillBuffer()
  10. for i in range(1,13)
  11. put=i
  12. " Set 'undolevels' to split undo.
  13. exe "setg ul=" . &g:ul
  14. endfor
  15. endfunc
  16. func Test_global_local_undolevels()
  17. new one
  18. set undolevels=5
  19. call FillBuffer()
  20. " will only undo the last 5 changes, end up with 13 - (5 + 1) = 7 lines
  21. earlier 10
  22. call assert_equal(5, &g:undolevels)
  23. call assert_equal(-123456, &l:undolevels)
  24. call assert_equal('7', getline('$'))
  25. new two
  26. setlocal undolevels=2
  27. call FillBuffer()
  28. " will only undo the last 2 changes, end up with 13 - (2 + 1) = 10 lines
  29. earlier 10
  30. call assert_equal(5, &g:undolevels)
  31. call assert_equal(2, &l:undolevels)
  32. call assert_equal('10', getline('$'))
  33. setlocal ul=10
  34. call assert_equal(5, &g:undolevels)
  35. call assert_equal(10, &l:undolevels)
  36. " Setting local value in "two" must not change local value in "one"
  37. wincmd p
  38. call assert_equal(5, &g:undolevels)
  39. call assert_equal(-123456, &l:undolevels)
  40. new three
  41. setglobal ul=50
  42. call assert_equal(50, &g:undolevels)
  43. call assert_equal(-123456, &l:undolevels)
  44. " Drop created windows
  45. set ul&
  46. new
  47. only!
  48. endfunc
  49. call Test_global_local_undolevels()
  50. ]])
  51. eq({}, api.nvim_get_vvar('errors'))
  52. end)
  53. end)