undolevels_spec.lua 1.7 KB

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