mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	 167a2383b9
			
		
	
	167a2383b9
	
	
	
		
			
			Problem: - API functions using `try_start` directly instead of `TRY_WRAP`, do not surface the underlying error message, and instead show generic things like "Failed to set buffer". - Error handling code is duplicated in the API impl, instead of delegating to the vim buffer/window handling logic. Solution: - Use `TRY_WRAP`.
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| local n = require('test.functional.testnvim')()
 | |
| local t = require('test.testutil')
 | |
| 
 | |
| local clear = n.clear
 | |
| local exec_lua = n.exec_lua
 | |
| 
 | |
| describe("'winfixbuf'", function()
 | |
|   before_each(function()
 | |
|     clear()
 | |
|   end)
 | |
| 
 | |
|   ---@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
 | |
|     ]])
 | |
|   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('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)
 | |
| 
 | |
|   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)
 | |
| 
 | |
|   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)
 |