diff options
Diffstat (limited to 'test/functional/ui/screen_basic_spec.lua')
-rw-r--r-- | test/functional/ui/screen_basic_spec.lua | 269 |
1 files changed, 99 insertions, 170 deletions
diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index e511234e5e..b31d9cb32f 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -1,12 +1,13 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local spawn, set_session, clear = helpers.spawn, helpers.set_session, helpers.clear -local feed, execute = helpers.feed, helpers.execute +local feed, command = helpers.feed, helpers.command local insert = helpers.insert local eq = helpers.eq local eval = helpers.eval +local iswin = helpers.iswin -describe('Initial screen', function() +describe('screen', function() local screen local nvim_argv = {helpers.nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N', '--cmd', 'set shortmess+=I background=light noswapfile belloff= noshowcmd noruler', @@ -27,7 +28,7 @@ describe('Initial screen', function() screen:detach() end) - it('is the default initial screen', function() + it('default initial screen', function() screen:expect([[ ^ | {0:~ }| @@ -73,33 +74,29 @@ describe('Screen', function() describe(':suspend', function() it('is forwarded to the UI', function() local function check() - if not screen.suspended then - return 'Screen was not suspended' - end + eq(true, screen.suspended) end - execute('suspend') - screen:wait(check) + command('suspend') + screen:expect(check) screen.suspended = false feed('<c-z>') - screen:wait(check) + screen:expect(check) end) end) describe('bell/visual bell', function() it('is forwarded to the UI', function() feed('<left>') - screen:wait(function() - if not screen.bell or screen.visual_bell then - return 'Bell was not sent' - end + screen:expect(function() + eq(true, screen.bell) + eq(false, screen.visual_bell) end) screen.bell = false - execute('set visualbell') + command('set visualbell') feed('<left>') - screen:wait(function() - if not screen.visual_bell or screen.bell then - return 'Visual bell was not sent' - end + screen:expect(function() + eq(true, screen.visual_bell) + eq(false, screen.bell) end) end) end) @@ -107,36 +104,28 @@ describe('Screen', function() describe(':set title', function() it('is forwarded to the UI', function() local expected = 'test-title' - execute('set titlestring='..expected) - execute('set title') - screen:wait(function() - local actual = screen.title - if actual ~= expected then - return 'Expected title to be "'..expected..'" but was "'..actual..'"' - end + command('set titlestring='..expected) + command('set title') + screen:expect(function() + eq(expected, screen.title) end) end) it('has correct default title with unnamed file', function() local expected = '[No Name] - NVIM' - execute('set title') - screen:wait(function() - local actual = screen.title - if actual ~= expected then - return 'Expected title to be "'..expected..'" but was "'..actual..'"' - end + command('set title') + screen:expect(function() + eq(expected, screen.title) end) end) it('has correct default title with named file', function() - local expected = 'myfile (/mydir) - NVIM' - execute('set title') - execute('file /mydir/myfile') - screen:wait(function() - local actual = screen.title - if actual ~= expected then - return 'Expected title to be "'..expected..'" but was "'..actual..'"' - end + local expected = (iswin() and 'myfile (C:\\mydir) - NVIM' + or 'myfile (/mydir) - NVIM') + command('set title') + command(iswin() and 'file C:\\mydir\\myfile' or 'file /mydir/myfile') + screen:expect(function() + eq(expected, screen.title) end) end) end) @@ -144,13 +133,10 @@ describe('Screen', function() describe(':set icon', function() it('is forwarded to the UI', function() local expected = 'test-icon' - execute('set iconstring='..expected) - execute('set icon') - screen:wait(function() - local actual = screen.icon - if actual ~= expected then - return 'Expected title to be "'..expected..'" but was "'..actual..'"' - end + command('set iconstring='..expected) + command('set icon') + screen:expect(function() + eq(expected, screen.icon) end) end) end) @@ -158,7 +144,7 @@ describe('Screen', function() describe('window', function() describe('split', function() it('horizontal', function() - execute('sp') + command('sp') screen:expect([[ ^ | {0:~ }| @@ -173,13 +159,13 @@ describe('Screen', function() {0:~ }| {0:~ }| {3:[No Name] }| - :sp | + | ]]) end) it('horizontal and resize', function() - execute('sp') - execute('resize 8') + command('sp') + command('resize 8') screen:expect([[ ^ | {0:~ }| @@ -194,12 +180,14 @@ describe('Screen', function() {0:~ }| {0:~ }| {3:[No Name] }| - :resize 8 | + | ]]) end) it('horizontal and vertical', function() - execute('sp', 'vsp', 'vsp') + command('sp') + command('vsp') + command('vsp') screen:expect([[ ^ {3:|} {3:|} | {0:~ }{3:|}{0:~ }{3:|}{0:~ }| @@ -239,7 +227,9 @@ describe('Screen', function() describe('tabnew', function() it('creates a new buffer', function() - execute('sp', 'vsp', 'vsp') + command('sp') + command('vsp') + command('vsp') insert('hello') screen:expect([[ hell^o {3:|}hello {3:|}hello | @@ -257,7 +247,7 @@ describe('Screen', function() {3:[No Name] [+] }| | ]]) - execute('tabnew') + command('tabnew') insert('hello2') feed('h') screen:expect([[ @@ -276,7 +266,7 @@ describe('Screen', function() {0:~ }| | ]]) - execute('tabprevious') + command('tabprevious') screen:expect([[ {2: }{6:4}{2:+ [No Name] }{4: + [No Name] }{3: }{4:X}| hell^o {3:|}hello {3:|}hello | @@ -321,9 +311,9 @@ describe('Screen', function() describe('normal mode', function() -- https://code.google.com/p/vim/issues/detail?id=339 it("setting 'ruler' doesn't reset the preferred column", function() - execute('set virtualedit=') + command('set virtualedit=') feed('i0123456<cr>789<esc>kllj') - execute('set ruler') + command('set ruler') feed('k') screen:expect([[ 0123^456 | @@ -339,7 +329,7 @@ describe('Screen', function() {0:~ }| {0:~ }| {0:~ }| - :set ruler 1,5 All | + 1,5 All | ]]) end) end) @@ -404,7 +394,9 @@ describe('Screen', function() split windows ]]) - execute('sp', 'vsp', 'vsp') + command('sp') + command('vsp') + command('vsp') screen:expect([[ and {3:|}and {3:|}and | clearing {3:|}clearing {3:|}clearing | @@ -576,124 +568,61 @@ describe('Screen', function() end) end) - describe('mode change', function() - before_each(function() - screen:try_resize(25, 5) - end) - - it('works in normal mode', function() - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]],nil,nil,function () - eq("normal", screen.mode) - end) - end) - - it('works in insert mode', function() - feed('i') + describe('press enter', function() + it('does not crash on <F1> at “Press ENTER”', function() + command('nnoremap <F1> :echo "TEST"<CR>') + feed(':ls<CR>') screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {2:-- INSERT --} | - ]],nil,nil,function () - eq("insert", screen.mode) - end) - - feed('word<esc>') - screen:expect([[ - wor^d | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]], nil, nil, function () - eq("normal", screen.mode) - end) - end) - - it('works in replace mode', function() - feed('R') - screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - {2:-- REPLACE --} | - ]], nil, nil, function () - eq("replace", screen.mode) - end) - - feed('word<esc>') - screen:expect([[ - wor^d | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]], nil, nil, function () - eq("normal", screen.mode) - end) - end) - - it('works in cmdline mode', function() - feed(':') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - :^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - feed('<esc>/') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - /^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - - feed('<esc>?') - screen:expect([[ - | - {0:~ }| - {0:~ }| - {0:~ }| - ?^ | - ]],nil,nil,function () - eq("cmdline", screen.mode) - end) - - feed('<esc>') + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + :ls | + 1 %a "[No Name]" line 1 | + {7:Press ENTER or type command to continue}^ | + ]]) + feed('<F1>') screen:expect([[ - ^ | - {0:~ }| - {0:~ }| - {0:~ }| - | - ]],nil,nil,function () - eq("normal", screen.mode) - end) + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + TEST | + ]]) end) end) +end) - it('nvim_ui_attach() handles very large width/height #2180', function() - screen:detach() - screen = Screen.new(999, 999) +describe('nvim_ui_attach()', function() + before_each(function() + clear() + end) + it('handles very large width/height #2180', function() + local screen = Screen.new(999, 999) screen:attach() eq(999, eval('&lines')) eq(999, eval('&columns')) end) + it('invalid option returns error', function() + local screen = Screen.new() + local status, rv = pcall(function() screen:attach({foo={'foo'}}) end) + eq(false, status) + eq('No such ui option', rv:match("No such .*")) + end) end) |