mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	 052498ed42
			
		
	
	052498ed42
	
	
	
		
			
			Specifically, functions that are run in the context of the test runner are put in module `test/testutil.lua` while the functions that are run in the context of the test session are put in `test/functional/testnvim.lua`. Closes https://github.com/neovim/neovim/issues/27004.
		
			
				
	
	
		
			93 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			93 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| -- Tests for 'directory' option.
 | |
| -- - ".", in same dir as file
 | |
| -- - "./dir", in directory relative to file
 | |
| -- - "dir", in directory relative to current dir
 | |
| 
 | |
| local t = require('test.testutil')
 | |
| local n = require('test.functional.testnvim')()
 | |
| 
 | |
| local eq = t.eq
 | |
| local neq = t.neq
 | |
| local poke_eventloop = n.poke_eventloop
 | |
| local fn = n.fn
 | |
| local api = n.api
 | |
| local clear = n.clear
 | |
| local insert = n.insert
 | |
| local command = n.command
 | |
| local write_file = t.write_file
 | |
| local expect_exit = n.expect_exit
 | |
| local mkdir = t.mkdir
 | |
| 
 | |
| local function ls_dir_sorted(dirname)
 | |
|   local files = {}
 | |
|   for f in vim.fs.dir(dirname) do
 | |
|     if f ~= '.' and f ~= '..' then
 | |
|       table.insert(files, f)
 | |
|     end
 | |
|   end
 | |
|   table.sort(files)
 | |
|   return files
 | |
| end
 | |
| 
 | |
| describe("'directory' option", function()
 | |
|   setup(function()
 | |
|     local text = [[
 | |
|       start of testfile
 | |
|       line 2 Abcdefghij
 | |
|       line 3 Abcdefghij
 | |
|       end of testfile
 | |
|       ]]
 | |
|     write_file('Xtest1', text)
 | |
|     mkdir('Xtest.je')
 | |
|     mkdir('Xtest2')
 | |
|     write_file('Xtest2/Xtest3', text)
 | |
|     clear()
 | |
|   end)
 | |
|   teardown(function()
 | |
|     expect_exit(command, 'qall!')
 | |
|     n.rmdir('Xtest.je')
 | |
|     n.rmdir('Xtest2')
 | |
|     os.remove('Xtest1')
 | |
|   end)
 | |
| 
 | |
|   it('is working', function()
 | |
|     insert([[
 | |
|       start of testfile
 | |
|       line 2 Abcdefghij
 | |
|       line 3 Abcdefghij
 | |
|       end of testfile]])
 | |
| 
 | |
|     api.nvim_set_option_value('swapfile', true, {})
 | |
|     api.nvim_set_option_value('swapfile', true, {})
 | |
|     api.nvim_set_option_value('directory', '.', {})
 | |
| 
 | |
|     -- sanity check: files should not exist yet.
 | |
|     eq(nil, vim.uv.fs_stat('.Xtest1.swp'))
 | |
| 
 | |
|     command('edit! Xtest1')
 | |
|     poke_eventloop()
 | |
|     eq('Xtest1', fn.buffer_name('%'))
 | |
|     -- Verify that the swapfile exists. In the legacy test this was done by
 | |
|     -- reading the output from :!ls.
 | |
|     neq(nil, vim.uv.fs_stat('.Xtest1.swp'))
 | |
| 
 | |
|     api.nvim_set_option_value('directory', './Xtest2,.', {})
 | |
|     command('edit Xtest1')
 | |
|     poke_eventloop()
 | |
| 
 | |
|     -- swapfile should no longer exist in CWD.
 | |
|     eq(nil, vim.uv.fs_stat('.Xtest1.swp'))
 | |
| 
 | |
|     eq({ 'Xtest1.swp', 'Xtest3' }, ls_dir_sorted('Xtest2'))
 | |
| 
 | |
|     api.nvim_set_option_value('directory', 'Xtest.je', {})
 | |
|     command('bdelete')
 | |
|     command('edit Xtest2/Xtest3')
 | |
|     eq(true, api.nvim_get_option_value('swapfile', {}))
 | |
|     poke_eventloop()
 | |
| 
 | |
|     eq({ 'Xtest3' }, ls_dir_sorted('Xtest2'))
 | |
|     eq({ 'Xtest3.swp' }, ls_dir_sorted('Xtest.je'))
 | |
|   end)
 | |
| end)
 |