Repository: neovim/neovim
File: test/functional/ex_cmds/oldfiles_spec.lua (Lua)

Code before:
local Screen = require('test.functional.ui.screen')

local clear = n.clear
local command = n.command
local expect_exit = n.expect_exit
local api, eq, feed_command = n.api, t.eq, n.feed_command
local feed, poke_eventloop = n.feed, n.poke_eventloop
local ok = t.ok
local eval = n.eval

local shada_file = 'Xtest.shada'

local function _clear()
  clear {
    args = {
      '-i',
      shada_file, -- Need shada for these tests.
      '--cmd',
      'set noswapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler',
    },
    args_rm = { '-i', '--cmd' },
  }

  local shada_without_path_exclusions = api.nvim_get_option_value('shada', {}) --[[@as string]]
  shada_without_path_exclusions =
    shada_without_path_exclusions:gsub(',r/tmp/', ''):gsub(',r/private/', '')

  api.nvim_set_option_value('shada', shada_without_path_exclusions, {})
end

describe(':oldfiles', function()
  before_each(_clear)

  after_each(function()
    expect_exit(command, 'qall!')
    os.remove(shada_file)
  end)

  local function add_padding(s)
    return s .. string.rep(' ', 96 - string.len(s))
  end

  it('shows most recently used files', function()
    local screen = Screen.new(100, 5)
    screen._default_attr_ids = nil
    feed_command('edit testfile1')
    feed_command('edit testfile2')
    feed_command('wshada')
    feed_command('rshada!')
    local oldfiles = api.nvim_get_vvar('oldfiles')
    feed_command('oldfiles')

Review comment (suggestion):
nit
```suggestion
  local shada_without_path_exclusions = api.nvim_get_option_value('shada', {})
    :gsub(',r/tmp/', ''):gsub(',r/private/', '') --[[@as string]]
```

Code after:
local Screen = require('test.functional.ui.screen')

local clear = n.clear
local command = n.command
local expect_exit = n.expect_exit
local api, eq, feed_command = n.api, t.eq, n.feed_command
local feed, poke_eventloop = n.feed, n.poke_eventloop
local ok = t.ok
local eval = n.eval

local shada_file = 'Xtest.shada'

local function _clear()
  clear {
    args = {
      '-i',
      shada_file, -- Need shada for these tests.
      '--cmd',
      "set noswapfile undodir=. directory=. viewdir=. backupdir=. belloff= noshowcmd noruler shada=!,'100,<50,s10,h",
    },
    args_rm = { '-i', '--cmd' },
  }
end

describe(':oldfiles', function()
  before_each(_clear)

  after_each(function()
    expect_exit(command, 'qall!')
    os.remove(shada_file)
  end)

  local function add_padding(s)
    return s .. string.rep(' ', 96 - string.len(s))
  end

  it('shows most recently used files', function()
    local screen = Screen.new(100, 5)
    screen._default_attr_ids = nil
    feed_command('edit testfile1')
    feed_command('edit testfile2')
    feed_command('wshada')
    feed_command('rshada!')
    local oldfiles = api.nvim_get_vvar('oldfiles')
    feed_command('oldfiles')
    screen:expect([[
                                                                                                          |
      1: ]] .. add_padding(oldfiles[1]) .. [[ |
      2: ]] .. add_padding(oldfiles[2]) .. [[ |
                                                                                                          |
      Press ENTER or type command to continue^                                                             |