history_spec.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear, meths, funcs, eq =
  3. helpers.clear, helpers.meths, helpers.funcs, helpers.eq
  4. describe('history support code', function()
  5. before_each(clear)
  6. it('correctly clears start of the history', function()
  7. -- Regression test: check absence of the memory leak when clearing start of
  8. -- the history using ex_getln.c/clr_history().
  9. eq(1, funcs.histadd(':', 'foo'))
  10. eq(1, funcs.histdel(':'))
  11. eq('', funcs.histget(':', -1))
  12. end)
  13. it('correctly clears end of the history', function()
  14. -- Regression test: check absence of the memory leak when clearing end of
  15. -- the history using ex_getln.c/clr_history().
  16. meths.set_option('history', 1)
  17. eq(1, funcs.histadd(':', 'foo'))
  18. eq(1, funcs.histdel(':'))
  19. eq('', funcs.histget(':', -1))
  20. end)
  21. it('correctly removes item from history', function()
  22. -- Regression test: check that ex_getln.c/del_history_idx() correctly clears
  23. -- history index after removing history entry. If it does not then deleting
  24. -- history will result in a double free.
  25. eq(1, funcs.histadd(':', 'foo'))
  26. eq(1, funcs.histadd(':', 'bar'))
  27. eq(1, funcs.histadd(':', 'baz'))
  28. eq(1, funcs.histdel(':', -2))
  29. eq(1, funcs.histdel(':'))
  30. eq('', funcs.histget(':', -1))
  31. end)
  32. end)