diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2025-02-05 23:09:29 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2025-02-05 23:09:29 +0000 |
commit | d5f194ce780c95821a855aca3c19426576d28ae0 (patch) | |
tree | d45f461b19f9118ad2bb1f440a7a08973ad18832 /test/functional/options | |
parent | c5d770d311841ea5230426cc4c868e8db27300a8 (diff) | |
parent | 44740e561fc93afe3ebecfd3618bda2d2abeafb0 (diff) | |
download | rneovim-rahm.tar.gz rneovim-rahm.tar.bz2 rneovim-rahm.zip |
Diffstat (limited to 'test/functional/options')
-rw-r--r-- | test/functional/options/defaults_spec.lua | 16 | ||||
-rw-r--r-- | test/functional/options/winfixbuf_spec.lua | 74 |
2 files changed, 40 insertions, 50 deletions
diff --git a/test/functional/options/defaults_spec.lua b/test/functional/options/defaults_spec.lua index e7f47ef4e9..a82279e775 100644 --- a/test/functional/options/defaults_spec.lua +++ b/test/functional/options/defaults_spec.lua @@ -14,7 +14,6 @@ local api = n.api local command = n.command local clear = n.clear local exc_exec = n.exc_exec -local exec_lua = n.exec_lua local eval = n.eval local eq = t.eq local ok = t.ok @@ -929,17 +928,12 @@ describe('stdpath()', function() assert_alive() -- Check for crash. #8393 -- Check that Nvim rejects invalid APPNAMEs - -- Call jobstart() and jobwait() in the same RPC request to reduce flakiness. local function test_appname(testAppname, expected_exitcode) - local lua_code = string.format( - [[ - local child = vim.fn.jobstart({ vim.v.progpath, '--clean', '--headless', '--listen', 'x', '+qall!' }, { env = { NVIM_APPNAME = %q } }) - return vim.fn.jobwait({ child }, %d)[1] - ]], - testAppname, - 3000 - ) - eq(expected_exitcode, exec_lua(lua_code)) + local p = n.spawn_wait({ + args = { '--listen', 'x', '+qall!' }, + env = { NVIM_APPNAME = testAppname }, + }) + eq(expected_exitcode, p.status) end -- Invalid appnames: test_appname('a/../b', 1) diff --git a/test/functional/options/winfixbuf_spec.lua b/test/functional/options/winfixbuf_spec.lua index 124f194b5a..a01650ea71 100644 --- a/test/functional/options/winfixbuf_spec.lua +++ b/test/functional/options/winfixbuf_spec.lua @@ -1,55 +1,51 @@ local n = require('test.functional.testnvim')() +local t = require('test.testutil') local clear = n.clear local exec_lua = n.exec_lua -describe("Nvim API calls with 'winfixbuf'", function() +describe("'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 + ---@return integer + local function setup_winfixbuf() + return exec_lua([[ + local buffer = vim.api.nvim_create_buf(true, true) + vim.api.nvim_create_buf(true, true) -- Make another buffer + vim.wo.winfixbuf = true + return buffer ]]) - - assert(results == false) + end + + it('nvim_win_set_buf on non-current buffer', function() + local other_buf = setup_winfixbuf() + t.eq( + "Vim:E1513: Cannot switch buffer. 'winfixbuf' is enabled", + t.pcall_err(n.api.nvim_win_set_buf, 0, other_buf) + ) 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) + it('nvim_set_current_buf on non-current buffer', function() + local other_buf = setup_winfixbuf() + t.eq( + "Vim:E1513: Cannot switch buffer. 'winfixbuf' is enabled", + t.pcall_err(n.api.nvim_set_current_buf, other_buf) + ) + end) - return results - ]]) + it('nvim_win_set_buf on current buffer', function() + setup_winfixbuf() + local curbuf = n.api.nvim_get_current_buf() + n.api.nvim_win_set_buf(0, curbuf) + t.eq(curbuf, n.api.nvim_get_current_buf()) + end) - assert(results == false) + it('nvim_set_current_buf on current buffer', function() + setup_winfixbuf() + local curbuf = n.api.nvim_get_current_buf() + n.api.nvim_set_current_buf(curbuf) + t.eq(curbuf, n.api.nvim_get_current_buf()) end) end) |