aboutsummaryrefslogtreecommitdiff
path: root/test/functional/options/winfixbuf_spec.lua
blob: 124f194b5a70099ae706ff47fd84b5794b687c77 (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
48
49
50
51
52
53
54
55
local n = require('test.functional.testnvim')()

local clear = n.clear
local exec_lua = n.exec_lua

describe("Nvim API calls with 'winfixbuf'", function()
  before_each(function()
    clear()
  end)

  it("Calling vim.api.nvim_win_set_buf with 'winfixbuf'", function()
    local results = exec_lua([[
      local function _setup_two_buffers()
        local buffer = vim.api.nvim_create_buf(true, true)

        vim.api.nvim_create_buf(true, true)  -- Make another buffer

        local current_window = 0
        vim.api.nvim_set_option_value("winfixbuf", true, {win=current_window})

        return buffer
      end

      local other_buffer = _setup_two_buffers()
      local current_window = 0
      local results, _ = pcall(vim.api.nvim_win_set_buf, current_window, other_buffer)

      return results
    ]])

    assert(results == false)
  end)

  it("Calling vim.api.nvim_set_current_buf with 'winfixbuf'", function()
    local results = exec_lua([[
      local function _setup_two_buffers()
        local buffer = vim.api.nvim_create_buf(true, true)

        vim.api.nvim_create_buf(true, true)  -- Make another buffer

        local current_window = 0
        vim.api.nvim_set_option_value("winfixbuf", true, {win=current_window})

        return buffer
      end

      local other_buffer = _setup_two_buffers()
      local results, _ = pcall(vim.api.nvim_set_current_buf, other_buffer)

      return results
    ]])

    assert(results == false)
  end)
end)