diff options
author | Marco Hinz <mh.codebro@gmail.com> | 2015-11-10 16:23:18 +0100 |
---|---|---|
committer | Marco Hinz <mh.codebro@gmail.com> | 2015-11-11 17:12:02 +0100 |
commit | 947e356cdaa931bec9b2314c36bbfed926514030 (patch) | |
tree | 7af5e54813f434f37476181d4832eb5ba731ad00 /test/functional/ex_cmds/oldfiles_spec.lua | |
parent | 3b615980c814eff3fa284dd07b61fbf50885f4ab (diff) | |
download | rneovim-947e356cdaa931bec9b2314c36bbfed926514030.tar.gz rneovim-947e356cdaa931bec9b2314c36bbfed926514030.tar.bz2 rneovim-947e356cdaa931bec9b2314c36bbfed926514030.zip |
Test: improve functional/ex_cmds/oldfiles_spec.lua
- change approach for test 1: screen:expect() instead of assert()
- use execute() instead of command()
- 2 new tests that check none and wrong input for :oldfiles!
Helped-by: @fwalch
Helped-by: @tarruda
Helper-by: @justinmk
Diffstat (limited to 'test/functional/ex_cmds/oldfiles_spec.lua')
-rw-r--r-- | test/functional/ex_cmds/oldfiles_spec.lua | 93 |
1 files changed, 65 insertions, 28 deletions
diff --git a/test/functional/ex_cmds/oldfiles_spec.lua b/test/functional/ex_cmds/oldfiles_spec.lua index fedf5babe8..d54e43f6cb 100644 --- a/test/functional/ex_cmds/oldfiles_spec.lua +++ b/test/functional/ex_cmds/oldfiles_spec.lua @@ -1,49 +1,86 @@ -local h = require('test.functional.helpers') +local Screen = require('test.functional.ui.screen') +local helpers = require('test.functional.helpers') -local buf = h.curbufmeths -local command = h.command -local eq = h.eq -local execute = h.execute -local feed = h.feed -local nvim = h.nvim +local buf, eq, execute = helpers.curbufmeths, helpers.eq, helpers.execute +local feed, nvim, nvim_prog = helpers.feed, helpers.nvim, helpers.nvim_prog +local set_session, spawn = helpers.set_session, helpers.spawn local shada_file = 'test.shada' --- h.clear() uses "-i NONE", which is not useful for this test. -local function clear() +-- +-- helpers.clear() uses "-i NONE", which is not useful for this test. +-- +local function _clear() if session then session:exit(0) end - h.set_session(h.spawn({h.nvim_prog, - '-u', 'NONE', - '--cmd', 'set noswapfile undodir=. directory=. viewdir=. backupdir=.', - '--embed'})) + set_session(spawn({nvim_prog, + '-u', 'NONE', + '--cmd', 'set noswapfile undodir=. directory=. viewdir=. backupdir=.', + '--embed'})) end describe(':oldfiles', function() - before_each(clear) + before_each(_clear) - it('shows most recently used files', function() - command('edit testfile1') - command('edit testfile2') - command('wshada ' .. shada_file) - command('rshada! ' .. shada_file) - assert(string.find(nvim('command_output', 'oldfiles'), 'testfile2')) + after_each(function() 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() + screen = Screen.new(100, 5) + screen:attach() + execute('edit testfile1') + local filename1 = buf.get_name() + execute('edit testfile2') + local filename2 = buf.get_name() + execute('wshada ' .. shada_file) + execute('rshada! ' .. shada_file) + execute('oldfiles') + screen:expect([[ + testfile2 | + 1: ]].. add_padding(filename1) ..[[ | + 2: ]].. add_padding(filename2) ..[[ | + | + Press ENTER or type command to continue^ | + ]]) + end) end) describe(':oldfiles!', function() - it('provides a file selection prompt and edits the chosen file', function() - command('edit testfile1') - command('edit testfile2') - local filename = buf.get_name() - command('wshada ' .. shada_file) - clear() - command('rshada! ' .. shada_file) + local filename + + before_each(function() + _clear() + execute('edit testfile1') + execute('edit testfile2') + filename = buf.get_name() + execute('wshada ' .. shada_file) + _clear() + execute('rshada! ' .. shada_file) execute('oldfiles!') + end) + + after_each(function() + os.remove(shada_file) + end) + + it('provides a prompt and edits the chosen file', function() feed('2<cr>') eq(filename, buf.get_name()) - os.remove(shada_file) + end) + + it('provides a prompt and does nothing on <cr>', function() + feed('<cr>') + eq('', buf.get_name()) + end) + + it('provides a prompt and does nothing if choice is out-of-bounds', function() + feed('3<cr>') + eq('', buf.get_name()) end) end) |