Repository: neovim/neovim
File: test/functional/shada/buffers_spec.lua (Lua)

Code before:
    api.nvim_buf_set_lines(0, 0, 1, true, { 'foo' })
    nvim_command('enew')
    api.nvim_buf_set_lines(0, 0, 1, true, { 'bar' })
    eq(2, fn.bufnr('$'))
    expect_exit(nvim_command, 'qall!')
    reset('set shada+=% hidden')
    eq(1, fn.bufnr('$'))
    eq('', fn.bufname(1))
  end)

  it('restores 1 buffer with %1 in &shada, #5759', function()
    reset('set shada+=%1')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%1')
    eq(2, fn.bufnr('$'))
    eq('', fn.bufname(1))
    eq(testfilename, fn.bufname(2))
  end)

  it('does not add extui buffers to oldfiles', function()
    reset("set shada='100")
    nvim_command('edit ' .. testfilename)
    nvim_command('write')
    nvim_command('lua require("vim._extui").enable({})')
    nvim_command('echom "hello"')
    nvim_command('messages')
    nvim_command('close')
    expect_exit(nvim_command, 'qall')
    reset("set shada='100")
    local oldfiles = api.nvim_get_vvar('oldfiles')
    eq(1, #oldfiles)
    t.matches(testfilename:gsub('%-', '%%-') .. '$', oldfiles[1])
  end)
end)


Review comment (suggestion):
Better to just test this with a 'nobuflisted' buffer, which is what we're changing here:
```diff
diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua
index e44d233dbc..ad4b36240b 100644
--- a/test/functional/shada/buffers_spec.lua
+++ b/test/functional/shada/buffers_spec.lua
@@ -92,18 +92,13 @@ describe('shada support code', function()
     eq(testfilename, fn.bufname(2))
   end)
 
-  it('does not add extui buffers to oldfiles', function()
+  it('does not add nobuflisted buffers to oldfiles', function()
     reset("set shada='100")
     nvim_command('edit ' .. testfilename)
+    nvim_command('set nobuflisted')
     nvim_command('write')
-    nvim_command('lua require("vim._extui").enable({})')
-    nvim_command('echom "hello"')
-    nvim_command('messages')
-    nvim_command('close')
     expect_exit(nvim_command, 'qall')
     reset("set shada='100")
-    local oldfiles = api.nvim_get_vvar('oldfiles')
-    eq(1, #oldfiles)
-    t.matches(testfilename:gsub('%-', '%%-') .. '$', oldfiles[1])
+    eq({}, api.nvim_get_vvar('oldfiles'))
   end)
 end)
```

Code after:
    api.nvim_buf_set_lines(0, 0, 1, true, { 'foo' })
    nvim_command('enew')
    api.nvim_buf_set_lines(0, 0, 1, true, { 'bar' })
    eq(2, fn.bufnr('$'))
    expect_exit(nvim_command, 'qall!')
    reset('set shada+=% hidden')
    eq(1, fn.bufnr('$'))
    eq('', fn.bufname(1))
  end)

  it('restores 1 buffer with %1 in &shada, #5759', function()
    reset('set shada+=%1')
    nvim_command('edit ' .. testfilename)
    nvim_command('edit ' .. testfilename_2)
    expect_exit(nvim_command, 'qall')
    reset('set shada+=%1')
    eq(2, fn.bufnr('$'))
    eq('', fn.bufname(1))
    eq(testfilename, fn.bufname(2))
  end)

  it("does not add 'nobuflisted' buffers to v:oldfiles", function()
    reset("set shada='100")
    nvim_command('edit ' .. testfilename)
    nvim_command('setlocal nobuflisted')
    nvim_command('edit ' .. testfilename_2)
    nvim_command('setlocal buflisted')
    nvim_command('write')
    expect_exit(nvim_command, 'qall')
    reset("set shada='100")
    local oldfiles = api.nvim_get_vvar('oldfiles')
    eq(1, #oldfiles)
    t.matches(vim.pesc(testfilename_2), oldfiles[1])
  end)
end)