tabpage_spec.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear, nvim, tabpage, curtab, eq, ok =
  3. helpers.clear, helpers.nvim, helpers.tabpage, helpers.curtab, helpers.eq,
  4. helpers.ok
  5. local curtabmeths = helpers.curtabmeths
  6. local funcs = helpers.funcs
  7. local request = helpers.request
  8. local NIL = helpers.NIL
  9. local pcall_err = helpers.pcall_err
  10. local command = helpers.command
  11. describe('api/tabpage', function()
  12. before_each(clear)
  13. describe('list_wins and get_win', function()
  14. it('works', function()
  15. nvim('command', 'tabnew')
  16. nvim('command', 'vsplit')
  17. local tab1, tab2 = unpack(nvim('list_tabpages'))
  18. local win1, win2, win3 = unpack(nvim('list_wins'))
  19. eq({win1}, tabpage('list_wins', tab1))
  20. eq({win2, win3}, tabpage('list_wins', tab2))
  21. eq(win2, tabpage('get_win', tab2))
  22. nvim('set_current_win', win3)
  23. eq(win3, tabpage('get_win', tab2))
  24. end)
  25. it('validates args', function()
  26. eq('Invalid tabpage id: 23', pcall_err(tabpage, 'list_wins', 23))
  27. end)
  28. end)
  29. describe('{get,set,del}_var', function()
  30. it('works', function()
  31. curtab('set_var', 'lua', {1, 2, {['3'] = 1}})
  32. eq({1, 2, {['3'] = 1}}, curtab('get_var', 'lua'))
  33. eq({1, 2, {['3'] = 1}}, nvim('eval', 't:lua'))
  34. eq(1, funcs.exists('t:lua'))
  35. curtabmeths.del_var('lua')
  36. eq(0, funcs.exists('t:lua'))
  37. eq('Key not found: lua', pcall_err(curtabmeths.del_var, 'lua'))
  38. curtabmeths.set_var('lua', 1)
  39. command('lockvar t:lua')
  40. eq('Key is locked: lua', pcall_err(curtabmeths.del_var, 'lua'))
  41. eq('Key is locked: lua', pcall_err(curtabmeths.set_var, 'lua', 1))
  42. end)
  43. it('tabpage_set_var returns the old value', function()
  44. local val1 = {1, 2, {['3'] = 1}}
  45. local val2 = {4, 7}
  46. eq(NIL, request('tabpage_set_var', 0, 'lua', val1))
  47. eq(val1, request('tabpage_set_var', 0, 'lua', val2))
  48. end)
  49. it('tabpage_del_var returns the old value', function()
  50. local val1 = {1, 2, {['3'] = 1}}
  51. local val2 = {4, 7}
  52. eq(NIL, request('tabpage_set_var', 0, 'lua', val1))
  53. eq(val1, request('tabpage_set_var', 0, 'lua', val2))
  54. eq(val2, request('tabpage_del_var', 0, 'lua'))
  55. end)
  56. end)
  57. describe('get_number', function()
  58. it('works', function()
  59. local tabs = nvim('list_tabpages')
  60. eq(1, tabpage('get_number', tabs[1]))
  61. nvim('command', 'tabnew')
  62. local tab1, tab2 = unpack(nvim('list_tabpages'))
  63. eq(1, tabpage('get_number', tab1))
  64. eq(2, tabpage('get_number', tab2))
  65. nvim('command', '-tabmove')
  66. eq(2, tabpage('get_number', tab1))
  67. eq(1, tabpage('get_number', tab2))
  68. end)
  69. end)
  70. describe('is_valid', function()
  71. it('works', function()
  72. nvim('command', 'tabnew')
  73. local tab = nvim('list_tabpages')[2]
  74. nvim('set_current_tabpage', tab)
  75. ok(tabpage('is_valid', tab))
  76. nvim('command', 'tabclose')
  77. ok(not tabpage('is_valid', tab))
  78. end)
  79. end)
  80. end)