neovim/test/functional/legacy/031_close_commands_spec.lua

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

131 lines
3.2 KiB
Lua
Raw Normal View History

2015-05-24 13:04:51 -07:00
-- Test for commands that close windows and/or buffers
-- :quit
-- :close
-- :hide
-- :only
-- :sall
-- :all
-- :ball
-- :buf
-- :edit
local n = require('test.functional.testnvim')()
local feed = n.feed
local clear = n.clear
local source = n.source
local insert = n.insert
local expect = n.expect
local feed_command = n.feed_command
local expect_exit = n.expect_exit
2015-05-24 13:04:51 -07:00
describe('Commands that close windows and/or buffers', function()
local function cleanup()
os.remove('Xtest1')
os.remove('Xtest2')
os.remove('Xtest3')
end
setup(function()
cleanup()
clear()
end)
teardown(function()
cleanup()
end)
2015-05-24 13:04:51 -07:00
it('is working', function()
insert('testtext')
feed('GA 1<Esc>:$w! Xtest1<CR>')
feed('$r2:$w! Xtest2<CR>')
feed('$r3:$w! Xtest3<CR>')
feed_command('n! Xtest1 Xtest2')
2015-05-24 13:04:51 -07:00
feed('A 1<Esc>:set hidden<CR>')
-- Test for working :n when hidden set
feed_command('n')
2015-05-24 13:04:51 -07:00
expect('testtext 2')
-- Test for failing :rew when hidden not set
feed_command('set nohidden')
2015-05-24 13:04:51 -07:00
feed('A 2<Esc>:rew<CR>')
expect('testtext 2 2')
-- Test for working :rew when hidden set
feed_command('set hidden')
feed_command('rew')
2015-05-24 13:04:51 -07:00
expect('testtext 1 1')
-- Test for :all keeping a buffer when it's modified
feed_command('set nohidden')
2015-05-24 13:04:51 -07:00
feed('A 1<Esc>:sp<CR>')
feed_command('n Xtest2 Xtest3')
feed_command('all')
feed_command('1wincmd w')
2015-05-24 13:04:51 -07:00
expect('testtext 1 1 1')
-- Test abandoning changed buffer, should be unloaded even when 'hidden' set
feed_command('set hidden')
2015-05-24 13:04:51 -07:00
feed('A 1<Esc>:q!<CR>')
expect('testtext 2 2')
feed_command('unhide')
2015-05-24 13:04:51 -07:00
expect('testtext 2 2')
-- Test ":hide" hides anyway when 'hidden' not set
feed_command('set nohidden')
2015-05-24 13:04:51 -07:00
feed('A 2<Esc>:hide<CR>')
expect('testtext 3')
-- Test ":edit" failing in modified buffer when 'hidden' not set
feed('A 3<Esc>:e Xtest1<CR>')
expect('testtext 3 3')
-- Test ":edit" working in modified buffer when 'hidden' set
feed_command('set hidden')
feed_command('e Xtest1')
2015-05-24 13:04:51 -07:00
expect('testtext 1')
-- Test ":close" not hiding when 'hidden' not set in modified buffer
feed_command('sp Xtest3')
feed_command('set nohidden')
2015-05-24 13:04:51 -07:00
feed('A 3<Esc>:close<CR>')
expect('testtext 3 3 3')
-- Test ":close!" does hide when 'hidden' not set in modified buffer
feed('A 3<Esc>:close!<CR>')
feed_command('set nohidden')
2015-05-24 13:04:51 -07:00
expect('testtext 1')
-- Test ":all!" hides changed buffer
feed_command('sp Xtest4')
2015-05-24 13:04:51 -07:00
feed('GA 4<Esc>:all!<CR>')
feed_command('1wincmd w')
2015-05-24 13:04:51 -07:00
expect('testtext 2 2 2')
-- Test ":q!" and hidden buffer.
feed_command('bw! Xtest1 Xtest2 Xtest3 Xtest4')
feed_command('sp Xtest1')
feed_command('wincmd w')
feed_command('bw!')
feed_command('set modified')
feed_command('bot sp Xtest2')
feed_command('set modified')
feed_command('bot sp Xtest3')
feed_command('set modified')
feed_command('wincmd t')
feed_command('hide')
feed_command('q!')
expect('testtext 3')
feed_command('q!')
feed('<CR>')
expect('testtext 1')
expect_exit(
source,
[[
q!
" Now nvim should have exited
throw "Oh, Not finished yet."]]
)
2015-05-24 13:04:51 -07:00
end)
end)