ex_mode_spec.lua (7670B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 local Screen = require('test.functional.ui.screen') 4 5 local clear = n.clear 6 local command = n.command 7 local eq = t.eq 8 local eval = n.eval 9 local feed = n.feed 10 local api = n.api 11 local poke_eventloop = n.poke_eventloop 12 13 before_each(clear) 14 15 describe('Ex mode', function() 16 it('supports command line editing', function() 17 local function test_ex_edit(expected, cmd) 18 feed('gQ' .. cmd .. '<C-b>"<CR>') 19 local ret = eval('@:[1:]') -- Remove leading quote. 20 feed('visual<CR>') 21 eq(api.nvim_replace_termcodes(expected, true, true, true), ret) 22 end 23 command('set sw=2') 24 test_ex_edit('bar', 'foo bar<C-u>bar') 25 test_ex_edit('1<C-u>2', '1<C-v><C-u>2') 26 test_ex_edit('213', '1<C-b>2<C-e>3') 27 test_ex_edit('2013', '01<Home>2<End>3') 28 test_ex_edit('0213', '01<Left>2<Right>3') 29 test_ex_edit('0342', '012<Left><Left><Insert>3<Insert>4') 30 test_ex_edit('foo ', 'foo bar<C-w>') 31 test_ex_edit('foo', 'fooba<Del><Del>') 32 test_ex_edit('foobar', 'foo<Tab>bar') 33 test_ex_edit('abbreviate', 'abbrev<Tab>') 34 test_ex_edit('1<C-t><C-t>', '1<C-t><C-t>') 35 test_ex_edit('1<C-t><C-t>', '1<C-t><C-t><C-d>') 36 test_ex_edit(' foo', ' foo<C-d>') 37 test_ex_edit(' foo0', ' foo0<C-d>') 38 test_ex_edit(' foo^', ' foo^<C-d>') 39 test_ex_edit('foo', '<BS><C-H><Del><kDel>foo') 40 -- default wildchar <Tab> interferes with this test 41 command('set wildchar=<c-e>') 42 test_ex_edit('a\tb', 'a\t\t<C-H>b') 43 test_ex_edit('\tm<C-T>n', '\tm<C-T>n') 44 command('set wildchar&') 45 end) 46 47 it('substitute confirmation prompt', function() 48 command('set noincsearch nohlsearch inccommand=') 49 local screen = Screen.new(60, 6) 50 command([[call setline(1, repeat(['foo foo'], 4))]]) 51 command([[set number]]) 52 feed('gQ') 53 screen:expect([[ 54 {8: 1 }foo foo | 55 {8: 2 }foo foo | 56 {8: 3 }foo foo | 57 {3: }| 58 Entering Ex mode. Type "visual" to go to Normal mode. | 59 :^ | 60 ]]) 61 62 feed('%s/foo/bar/gc<CR>') 63 screen:expect([[ 64 {8: 1 }foo foo | 65 {3: }| 66 Entering Ex mode. Type "visual" to go to Normal mode. | 67 :%s/foo/bar/gc | 68 {8: 1 }foo foo | 69 ^^^^ | 70 ]]) 71 feed('N<CR>') 72 screen:expect([[ 73 Entering Ex mode. Type "visual" to go to Normal mode. | 74 :%s/foo/bar/gc | 75 {8: 1 }foo foo | 76 ^^^N | 77 {8: 1 }foo foo | 78 ^^^^ | 79 ]]) 80 feed('n<CR>') 81 screen:expect([[ 82 {8: 1 }foo foo | 83 ^^^N | 84 {8: 1 }foo foo | 85 ^^^n | 86 {8: 1 }foo foo | 87 ^^^^ | 88 ]]) 89 feed('y<CR>') 90 91 feed('q<CR>') 92 screen:expect([[ 93 {8: 1 }foo foo | 94 ^^^y | 95 {8: 2 }foo foo | 96 ^^^q | 97 {8: 2 }foo foo | 98 :^ | 99 ]]) 100 101 -- Pressing enter in ex mode should print the current line 102 feed('<CR>') 103 screen:expect([[ 104 ^^^y | 105 {8: 2 }foo foo | 106 ^^^q | 107 {8: 2 }foo foo | 108 {8: 3 }foo foo | 109 :^ | 110 ]]) 111 112 -- The printed line should overwrite the colon 113 feed('<CR>') 114 screen:expect([[ 115 {8: 2 }foo foo | 116 ^^^q | 117 {8: 2 }foo foo | 118 {8: 3 }foo foo | 119 {8: 4 }foo foo | 120 :^ | 121 ]]) 122 123 feed(':vi<CR>') 124 screen:expect([[ 125 {8: 1 }foo bar | 126 {8: 2 }foo foo | 127 {8: 3 }foo foo | 128 {8: 4 }^foo foo | 129 {1:~ }| 130 | 131 ]]) 132 end) 133 134 it('pressing Ctrl-C in :append inside a loop in Ex mode does not hang', function() 135 local screen = Screen.new(60, 6) 136 feed('gQ') 137 feed('for i in range(1)<CR>') 138 feed('append<CR>') 139 screen:expect([[ 140 {3: }| 141 Entering Ex mode. Type "visual" to go to Normal mode. | 142 :for i in range(1) | 143 | 144 : append | 145 ^ | 146 ]]) 147 feed('<C-C>') 148 poke_eventloop() -- Wait for input to be flushed 149 feed('foo<CR>') 150 screen:expect([[ 151 Entering Ex mode. Type "visual" to go to Normal mode. | 152 :for i in range(1) | 153 | 154 : append | 155 foo | 156 ^ | 157 ]]) 158 feed('.<CR>') 159 screen:expect([[ 160 :for i in range(1) | 161 | 162 : append | 163 foo | 164 . | 165 : ^ | 166 ]]) 167 feed('endfor<CR>') 168 feed('vi<CR>') 169 screen:expect([[ 170 ^foo | 171 {1:~ }|*4 172 | 173 ]]) 174 end) 175 end)