local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed local meths = helpers.meths before_each(clear) describe('Ex mode', function() it('supports command line editing', function() local function test_ex_edit(expected, cmd) feed('gQ' .. cmd .. '"') local ret = eval('@:[1:]') -- Remove leading quote. feed('visual') eq(meths.replace_termcodes(expected, true, true, true), ret) end command('set sw=2') test_ex_edit('bar', 'foo barbar') test_ex_edit('12', '12') test_ex_edit('213', '123') test_ex_edit('2013', '0123') test_ex_edit('0213', '0123') test_ex_edit('0342', '01234') test_ex_edit('foo ', 'foo bar') test_ex_edit('foo', 'fooba') test_ex_edit('foobar', 'foobar') test_ex_edit('abbreviate', 'abbrev') test_ex_edit('1', '1') test_ex_edit('1', '1') test_ex_edit(' foo', ' foo') test_ex_edit(' foo0', ' foo0') test_ex_edit(' foo^', ' foo^') test_ex_edit('foo', 'foo') -- default wildchar interferes with this test command('set wildchar=') test_ex_edit('a\tb', 'a\t\tb') test_ex_edit('\tmn', '\tmn') command('set wildchar&') end) it('substitute confirmation prompt', function() command('set noincsearch nohlsearch inccommand=') local screen = Screen.new(60, 6) screen:set_default_attr_ids({ [0] = {bold = true, reverse = true}, -- MsgSeparator [1] = {foreground = Screen.colors.Brown}, -- LineNr [2] = {bold = true, foreground = Screen.colors.Blue}, -- NonText }) screen:attach() command([[call setline(1, ['foo foo', 'foo foo', 'foo foo'])]]) command([[set number]]) feed('gQ') screen:expect([[ {1: 1 }foo foo | {1: 2 }foo foo | {1: 3 }foo foo | {0: }| Entering Ex mode. Type "visual" to go to Normal mode. | :^ | ]]) feed('%s/foo/bar/gc') screen:expect([[ {1: 1 }foo foo | {0: }| Entering Ex mode. Type "visual" to go to Normal mode. | :%s/foo/bar/gc | {1: 1 }foo foo | ^^^^ | ]]) feed('N') screen:expect([[ Entering Ex mode. Type "visual" to go to Normal mode. | :%s/foo/bar/gc | {1: 1 }foo foo | ^^^N | {1: 1 }foo foo | ^^^^ | ]]) feed('n') screen:expect([[ {1: 1 }foo foo | ^^^N | {1: 1 }foo foo | ^^^n | {1: 1 }foo foo | ^^^^ | ]]) feed('y') feed('q') screen:expect([[ {1: 1 }foo foo | ^^^y | {1: 2 }foo foo | ^^^q | {1: 2 }foo foo | :^ | ]]) -- Pressing enter in ex mode should print the current line feed('') screen:expect([[ {1: 1 }foo foo | ^^^y | {1: 2 }foo foo | ^^^q | {1: 3 }foo foo | :^ | ]]) feed(':vi') screen:expect([[ {1: 1 }foo bar | {1: 2 }foo foo | {1: 3 }^foo foo | {2:~ }| {2:~ }| | ]]) end) end)