robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
1.2 KiB37 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
5local clear = n.clear
6local command = n.command
7local eq = t.eq
8local fn = n.fn
9local rmdir = n.rmdir
10local mkdir = t.mkdir
11
12describe(':file', function()
13  local swapdir = vim.uv.cwd() .. '/Xtest-file_spec'
14  before_each(function()
15    clear()
16    rmdir(swapdir)
17    mkdir(swapdir)
18  end)
19  after_each(function()
20    command('%bwipeout!')
21    rmdir(swapdir)
22  end)
23
24  it('rename does not lose swapfile #6487', function()
25    local testfile = 'test-file_spec'
26    local testfile_renamed = testfile .. '-renamed'
27    -- Note: `set swapfile` *must* go after `set directory`: otherwise it may
28    -- attempt to create a swapfile in different directory.
29    command('set directory^=' .. swapdir .. '//')
30    command('set swapfile fileformat=unix undolevels=-1')
31
32    command('edit! ' .. testfile)
33    -- Before #6487 this gave "E301: Oops, lost the swap file !!!" on Windows.
34    command('file ' .. testfile_renamed)
35    eq(testfile_renamed .. '.swp', string.match(fn.execute('swapname'), '[^%%]+$'))
36  end)
37end)