aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/tabpage_spec.lua
blob: 7b97c7f0677b956bead76c6d7f7e8223a2f7a8e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
-- Sanity checks for tabpage_* API calls via msgpack-rpc
local helpers = require('test.functional.helpers')(after_each)
local clear, nvim, tabpage, curtab, eq, ok =
  helpers.clear, helpers.nvim, helpers.tabpage, helpers.curtab, helpers.eq,
  helpers.ok
local curtabmeths = helpers.curtabmeths
local funcs = helpers.funcs

describe('tabpage_* functions', function()
  before_each(clear)

  describe('get_windows and get_window', function()
    it('works', function()
      nvim('command', 'tabnew')
      nvim('command', 'vsplit')
      local tab1, tab2 = unpack(nvim('get_tabpages'))
      local win1, win2, win3 = unpack(nvim('get_windows'))
      eq({win1},  tabpage('get_windows', tab1))
      eq({win2, win3},  tabpage('get_windows', tab2))
      eq(win2, tabpage('get_window', tab2))
      nvim('set_current_window', win3)
      eq(win3, tabpage('get_window', tab2))
    end)
  end)

  describe('{get,set,del}_var', function()
    it('works', function()
      curtab('set_var', 'lua', {1, 2, {['3'] = 1}})
      eq({1, 2, {['3'] = 1}}, curtab('get_var', 'lua'))
      eq({1, 2, {['3'] = 1}}, nvim('eval', 't:lua'))
      eq(1, funcs.exists('t:lua'))
      curtabmeths.del_var('lua')
      eq(0, funcs.exists('t:lua'))
    end)
  end)

  describe('is_valid', function()
    it('works', function()
      nvim('command', 'tabnew')
      local tab = nvim('get_tabpages')[2]
      nvim('set_current_tabpage', tab)
      ok(tabpage('is_valid', tab))
      nvim('command', 'tabclose')
      ok(not tabpage('is_valid', tab))
    end)
  end)
end)