Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1 | " Test editing line in Ex mode (see :help Q and :help gQ). |
| 2 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | 3b6d57f | 2020-11-01 21:56:40 +0100 | [diff] [blame] | 4 | source shared.vim |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 5 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 6 | " Helper function to test editing line in Q Ex mode |
| 7 | func Ex_Q(cmd) |
| 8 | " Is there a simpler way to test editing Ex line? |
| 9 | call feedkeys("Q" |
| 10 | \ .. "let s:test_ex =<< END\<CR>" |
| 11 | \ .. a:cmd .. "\<CR>" |
| 12 | \ .. "END\<CR>" |
| 13 | \ .. "visual\<CR>", 'tx') |
| 14 | return s:test_ex[0] |
| 15 | endfunc |
| 16 | |
| 17 | " Helper function to test editing line in gQ Ex mode |
| 18 | func Ex_gQ(cmd) |
| 19 | call feedkeys("gQ" .. a:cmd .. "\<C-b>\"\<CR>", 'tx') |
| 20 | let ret = @:[1:] " Remove leading quote. |
| 21 | call feedkeys("visual\<CR>", 'tx') |
| 22 | return ret |
| 23 | endfunc |
| 24 | |
| 25 | " Helper function to test editing line with both Q and gQ Ex mode. |
| 26 | func Ex(cmd) |
| 27 | return [Ex_Q(a:cmd), Ex_gQ(a:cmd)] |
| 28 | endfunc |
| 29 | |
| 30 | " Test editing line in Ex mode (both Q and gQ) |
| 31 | func Test_ex_mode() |
| 32 | let encoding_save = &encoding |
| 33 | set sw=2 |
| 34 | |
| 35 | for e in ['utf8', 'latin1'] |
| 36 | exe 'set encoding=' . e |
| 37 | |
| 38 | call assert_equal(['bar', 'bar'], Ex("foo bar\<C-u>bar"), e) |
| 39 | call assert_equal(["1\<C-u>2", "1\<C-u>2"], Ex("1\<C-v>\<C-u>2"), e) |
| 40 | call assert_equal(["1\<C-b>2\<C-e>3", '213'], Ex("1\<C-b>2\<C-e>3"), e) |
| 41 | call assert_equal(['0123', '2013'], Ex("01\<Home>2\<End>3"), e) |
| 42 | call assert_equal(['0123', '0213'], Ex("01\<Left>2\<Right>3"), e) |
| 43 | call assert_equal(['01234', '0342'], Ex("012\<Left>\<Left>\<Insert>3\<Insert>4"), e) |
| 44 | call assert_equal(["foo bar\<C-w>", 'foo '], Ex("foo bar\<C-w>"), e) |
| 45 | call assert_equal(['foo', 'foo'], Ex("fooba\<Del>\<Del>"), e) |
| 46 | call assert_equal(["foo\tbar", 'foobar'], Ex("foo\<Tab>bar"), e) |
| 47 | call assert_equal(["abbrev\t", 'abbreviate'], Ex("abbrev\<Tab>"), e) |
| 48 | call assert_equal([' 1', "1\<C-t>\<C-t>"], Ex("1\<C-t>\<C-t>"), e) |
| 49 | call assert_equal([' 1', "1\<C-t>\<C-t>"], Ex("1\<C-t>\<C-t>\<C-d>"), e) |
| 50 | call assert_equal([' foo', ' foo'], Ex(" foo\<C-d>"), e) |
| 51 | call assert_equal(['foo', ' foo0'], Ex(" foo0\<C-d>"), e) |
| 52 | call assert_equal(['foo', ' foo^'], Ex(" foo^\<C-d>"), e) |
Bram Moolenaar | 0546d7d | 2020-03-01 16:53:09 +0100 | [diff] [blame] | 53 | call assert_equal(['foo', 'foo'], |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 54 | \ Ex("\<BS>\<C-H>\<Del>\<kDel>foo"), e) |
| 55 | " default wildchar <Tab> interferes with this test |
| 56 | set wildchar=<c-e> |
| 57 | call assert_equal(["a\tb", "a\tb"], Ex("a\t\t\<C-H>b"), e) |
Bram Moolenaar | bd7206e | 2020-03-06 20:36:04 +0100 | [diff] [blame] | 58 | call assert_equal(["\t mn", "\tm\<C-T>n"], Ex("\tm\<C-T>n"), e) |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 59 | set wildchar& |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 60 | endfor |
| 61 | |
| 62 | set sw& |
| 63 | let &encoding = encoding_save |
| 64 | endfunc |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 65 | |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 66 | " Test substitute confirmation prompt :%s/pat/str/c in Ex mode |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 67 | func Test_Ex_substitute() |
| 68 | CheckRunVimInTerminal |
| 69 | let buf = RunVimInTerminal('', {'rows': 6}) |
| 70 | |
zeertzjq | 7d664bf | 2024-07-14 10:22:54 +0200 | [diff] [blame^] | 71 | call term_sendkeys(buf, ":call setline(1, repeat(['foo foo'], 4))\<CR>") |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 72 | call term_sendkeys(buf, ":set number\<CR>") |
| 73 | call term_sendkeys(buf, "gQ") |
| 74 | call WaitForAssert({-> assert_match(':', term_getline(buf, 6))}, 1000) |
| 75 | |
| 76 | call term_sendkeys(buf, "%s/foo/bar/gc\<CR>") |
| 77 | call WaitForAssert({-> assert_match(' 1 foo foo', term_getline(buf, 5))}, |
| 78 | \ 1000) |
| 79 | call WaitForAssert({-> assert_match(' ^^^', term_getline(buf, 6))}, 1000) |
Bram Moolenaar | e5b0b98 | 2021-04-07 19:42:57 +0200 | [diff] [blame] | 80 | call term_sendkeys(buf, "N\<CR>") |
| 81 | call term_wait(buf) |
| 82 | call WaitForAssert({-> assert_match(' ^^^', term_getline(buf, 6))}, 1000) |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 83 | call term_sendkeys(buf, "n\<CR>") |
| 84 | call WaitForAssert({-> assert_match(' ^^^', term_getline(buf, 6))}, |
| 85 | \ 1000) |
| 86 | call term_sendkeys(buf, "y\<CR>") |
| 87 | |
| 88 | call term_sendkeys(buf, "q\<CR>") |
| 89 | call WaitForAssert({-> assert_match(':', term_getline(buf, 6))}, 1000) |
| 90 | |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 91 | " Pressing enter in ex mode should print the current line |
| 92 | call term_sendkeys(buf, "\<CR>") |
zeertzjq | 7d664bf | 2024-07-14 10:22:54 +0200 | [diff] [blame^] | 93 | call WaitForAssert({-> assert_match(' 3 foo foo', term_getline(buf, 5))}, 1000) |
| 94 | call WaitForAssert({-> assert_match(':', term_getline(buf, 6))}, 1000) |
| 95 | |
| 96 | " The printed line should overwrite the colon |
| 97 | call term_sendkeys(buf, "\<CR>") |
| 98 | call WaitForAssert({-> assert_match(' 3 foo foo', term_getline(buf, 4))}, 1000) |
| 99 | call WaitForAssert({-> assert_match(' 4 foo foo', term_getline(buf, 5))}, 1000) |
| 100 | call WaitForAssert({-> assert_match(':', term_getline(buf, 6))}, 1000) |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 101 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 102 | call term_sendkeys(buf, ":vi\<CR>") |
| 103 | call WaitForAssert({-> assert_match('foo bar', term_getline(buf, 1))}, 1000) |
| 104 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 105 | call StopVimInTerminal(buf) |
| 106 | endfunc |
| 107 | |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 108 | " Test for displaying lines from an empty buffer in Ex mode |
| 109 | func Test_Ex_emptybuf() |
| 110 | new |
| 111 | call assert_fails('call feedkeys("Q\<CR>", "xt")', 'E749:') |
| 112 | call setline(1, "abc") |
| 113 | call assert_fails('call feedkeys("Q\<CR>", "xt")', 'E501:') |
| 114 | call assert_fails('call feedkeys("Q%d\<CR>", "xt")', 'E749:') |
| 115 | close! |
| 116 | endfunc |
| 117 | |
| 118 | " Test for the :open command |
| 119 | func Test_open_command() |
| 120 | new |
| 121 | call setline(1, ['foo foo', 'foo bar', 'foo baz']) |
| 122 | call feedkeys("Qopen\<CR>j", 'xt') |
| 123 | call assert_equal('foo bar', getline('.')) |
| 124 | call feedkeys("Qopen /bar/\<CR>", 'xt') |
| 125 | call assert_equal(5, col('.')) |
| 126 | call assert_fails('call feedkeys("Qopen /baz/\<CR>", "xt")', 'E479:') |
| 127 | close! |
| 128 | endfunc |
| 129 | |
Bram Moolenaar | e031fe9 | 2021-12-05 12:06:24 +0000 | [diff] [blame] | 130 | func Test_open_command_flush_line() |
| 131 | " this was accessing freed memory: the regexp match uses a pointer to the |
| 132 | " current line which becomes invalid when searching for the ') mark. |
| 133 | new |
| 134 | call setline(1, ['one', 'two. three']) |
| 135 | s/one/ONE |
| 136 | try |
| 137 | open /\%')/ |
| 138 | catch /E479/ |
| 139 | endtry |
| 140 | bwipe! |
| 141 | endfunc |
| 142 | |
Bram Moolenaar | 7ac5023 | 2023-03-07 21:05:04 +0000 | [diff] [blame] | 143 | " FIXME: this doesn't fail without the fix but hangs |
| 144 | func Skip_Test_open_command_state() |
| 145 | " Tricky script that failed because State was not set properly |
| 146 | let lines =<< trim END |
| 147 | !ls ƒ |
| 148 | 0scìi |
| 149 | so! Xsourced |
| 150 | set t_û0=0 |
| 151 | v/-/o |
| 152 | END |
| 153 | call writefile(lines, 'XopenScript', '') |
| 154 | |
| 155 | let sourced = ["!f\u0083\x02\<Esc>z=0"] |
| 156 | call writefile(sourced, 'Xsourced', 'b') |
| 157 | |
| 158 | CheckRunVimInTerminal |
| 159 | let buf = RunVimInTerminal('-u NONE -i NONE -n -m -X -Z -e -s -S XopenScript -c qa!', #{rows: 6, wait_for_ruler: 0, no_clean: 1}) |
| 160 | sleep 3 |
| 161 | |
| 162 | call StopVimInTerminal(buf) |
| 163 | endfunc |
| 164 | |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 165 | " Test for :g/pat/visual to run vi commands in Ex mode |
| 166 | " This used to hang Vim before 8.2.0274. |
| 167 | func Test_Ex_global() |
Bram Moolenaar | 9e2bcb5 | 2020-02-18 21:33:00 +0100 | [diff] [blame] | 168 | new |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 169 | call setline(1, ['', 'foo', 'bar', 'foo', 'bar', 'foo']) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 170 | call feedkeys("Q\<bs>g/bar/visual\<CR>$rxQ$ryQvisual\<CR>j", "xt") |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 171 | call assert_equal('bax', getline(3)) |
| 172 | call assert_equal('bay', getline(5)) |
Bram Moolenaar | 9e2bcb5 | 2020-02-18 21:33:00 +0100 | [diff] [blame] | 173 | bwipe! |
Mohamed Akram | f3daa45 | 2024-07-06 17:12:09 +0200 | [diff] [blame] | 174 | |
| 175 | new |
| 176 | call setline(1, ['foo', 'bar']) |
| 177 | call feedkeys("Qg/./i\\\na\\\n.\\\na\\\nb\\\n.", "xt") |
| 178 | call assert_equal(['a', 'b', 'foo', 'a', 'b', 'bar'], getline(1, '$')) |
| 179 | bwipe! |
| 180 | endfunc |
| 181 | |
| 182 | func Test_Ex_shell() |
| 183 | CheckUnix |
| 184 | |
| 185 | new |
| 186 | call feedkeys("Qr !echo foo\\\necho bar\n", 'xt') |
| 187 | call assert_equal(['', 'foo', 'bar'], getline(1, '$')) |
| 188 | bwipe! |
| 189 | |
| 190 | new |
| 191 | call feedkeys("Qr !echo foo\\\\\nbar\n", 'xt') |
| 192 | call assert_equal(['', 'foobar'], getline(1, '$')) |
| 193 | bwipe! |
| 194 | |
| 195 | new |
| 196 | call feedkeys("Qr !echo foo\\ \\\necho bar\n", 'xt') |
| 197 | call assert_equal(['', 'foo ', 'bar'], getline(1, '$')) |
| 198 | bwipe! |
| 199 | |
| 200 | new |
| 201 | call setline(1, ['bar', 'baz']) |
| 202 | call feedkeys("Qg/./!echo \\\ns/b/c/", "xt") |
| 203 | call assert_equal(['car', 'caz'], getline(1, '$')) |
| 204 | bwipe! |
Bram Moolenaar | 9e2bcb5 | 2020-02-18 21:33:00 +0100 | [diff] [blame] | 205 | endfunc |
| 206 | |
zeertzjq | f754fe6 | 2022-07-14 17:06:12 +0100 | [diff] [blame] | 207 | " Test for pressing Ctrl-C in :append inside a loop in Ex mode |
| 208 | " This used to hang Vim |
| 209 | func Test_Ex_append_in_loop() |
| 210 | CheckRunVimInTerminal |
| 211 | let buf = RunVimInTerminal('', {'rows': 6}) |
| 212 | |
| 213 | call term_sendkeys(buf, "gQ") |
| 214 | call term_sendkeys(buf, "for i in range(1)\<CR>") |
| 215 | call term_sendkeys(buf, "append\<CR>") |
| 216 | call WaitForAssert({-> assert_match(': append', term_getline(buf, 5))}, 1000) |
| 217 | call term_sendkeys(buf, "\<C-C>") |
zeertzjq | 3cfae39 | 2022-07-26 17:48:13 +0100 | [diff] [blame] | 218 | " Wait for input to be flushed |
zeertzjq | f754fe6 | 2022-07-14 17:06:12 +0100 | [diff] [blame] | 219 | call term_wait(buf) |
| 220 | call term_sendkeys(buf, "foo\<CR>") |
| 221 | call WaitForAssert({-> assert_match('foo', term_getline(buf, 5))}, 1000) |
| 222 | call term_sendkeys(buf, ".\<CR>") |
| 223 | call WaitForAssert({-> assert_match('.', term_getline(buf, 5))}, 1000) |
| 224 | call term_sendkeys(buf, "endfor\<CR>") |
| 225 | call term_sendkeys(buf, "vi\<CR>") |
| 226 | call WaitForAssert({-> assert_match('foo', term_getline(buf, 1))}, 1000) |
| 227 | |
| 228 | call StopVimInTerminal(buf) |
| 229 | endfunc |
| 230 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 231 | " In Ex-mode, a backslash escapes a newline |
| 232 | func Test_Ex_escape_enter() |
| 233 | call feedkeys("gQlet l = \"a\\\<kEnter>b\"\<cr>vi\<cr>", 'xt') |
| 234 | call assert_equal("a\rb", l) |
| 235 | endfunc |
| 236 | |
Bram Moolenaar | 0546d7d | 2020-03-01 16:53:09 +0100 | [diff] [blame] | 237 | " Test for :append! command in Ex mode |
| 238 | func Test_Ex_append() |
| 239 | new |
| 240 | call setline(1, "\t abc") |
| 241 | call feedkeys("Qappend!\npqr\nxyz\n.\nvisual\n", 'xt') |
| 242 | call assert_equal(["\t abc", "\t pqr", "\t xyz"], getline(1, '$')) |
| 243 | close! |
Bram Moolenaar | 0546d7d | 2020-03-01 16:53:09 +0100 | [diff] [blame] | 244 | |
Mohamed Akram | f3daa45 | 2024-07-06 17:12:09 +0200 | [diff] [blame] | 245 | new |
| 246 | call feedkeys("Qappend\na\\\n.", 'xt') |
| 247 | call assert_equal(['a\'], getline(1, '$')) |
| 248 | close! |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 249 | endfunc |
| 250 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 251 | func Test_ex_mode_errors() |
| 252 | " Not allowed to enter ex mode when text is locked |
| 253 | au InsertCharPre <buffer> normal! gQ<CR> |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 254 | let caught_e565 = 0 |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 255 | try |
| 256 | call feedkeys("ix\<esc>", 'xt') |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 257 | catch /^Vim\%((\a\+)\)\=:E565/ " catch E565 |
| 258 | let caught_e565 = 1 |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 259 | endtry |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 260 | call assert_equal(1, caught_e565) |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 261 | au! InsertCharPre |
Bram Moolenaar | 158ea17 | 2020-06-18 17:28:39 +0200 | [diff] [blame] | 262 | |
| 263 | new |
| 264 | au CmdLineEnter * call ExEnterFunc() |
| 265 | func ExEnterFunc() |
| 266 | |
| 267 | endfunc |
| 268 | call feedkeys("gQvi\r", 'xt') |
| 269 | |
| 270 | au! CmdLineEnter |
| 271 | delfunc ExEnterFunc |
Christian Brabandt | 590aae3 | 2023-06-25 22:34:22 +0100 | [diff] [blame] | 272 | |
| 273 | au CmdlineEnter * : |
| 274 | call feedkeys("gQecho 1\r", 'xt') |
| 275 | |
| 276 | au! CmdlineEnter |
| 277 | |
Bram Moolenaar | 158ea17 | 2020-06-18 17:28:39 +0200 | [diff] [blame] | 278 | quit |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 279 | endfunc |
| 280 | |
Bram Moolenaar | 3b6d57f | 2020-11-01 21:56:40 +0100 | [diff] [blame] | 281 | func Test_ex_mode_with_global() |
Bram Moolenaar | 399db04 | 2020-11-01 22:31:08 +0100 | [diff] [blame] | 282 | CheckNotGui |
Bram Moolenaar | 3b6d57f | 2020-11-01 21:56:40 +0100 | [diff] [blame] | 283 | CheckFeature timers |
| 284 | |
| 285 | " This will get stuck in Normal mode after the failed "J", use a timer to |
| 286 | " get going again. |
| 287 | let lines =<< trim END |
| 288 | call ch_logfile('logfile', 'w') |
| 289 | pedit |
| 290 | func FeedQ(id) |
| 291 | call feedkeys('Q', 't') |
| 292 | endfunc |
| 293 | call timer_start(10, 'FeedQ') |
| 294 | g/^/vi|HJ |
| 295 | call writefile(['done'], 'Xdidexmode') |
| 296 | qall! |
| 297 | END |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 298 | call writefile(lines, 'Xexmodescript', 'D') |
Bram Moolenaar | 3b6d57f | 2020-11-01 21:56:40 +0100 | [diff] [blame] | 299 | call assert_equal(1, RunVim([], [], '-e -s -S Xexmodescript')) |
| 300 | call assert_equal(['done'], readfile('Xdidexmode')) |
| 301 | |
Bram Moolenaar | f637bce | 2020-11-23 18:14:56 +0100 | [diff] [blame] | 302 | call delete('logfile') |
Bram Moolenaar | 3b6d57f | 2020-11-01 21:56:40 +0100 | [diff] [blame] | 303 | call delete('Xdidexmode') |
Bram Moolenaar | 3b6d57f | 2020-11-01 21:56:40 +0100 | [diff] [blame] | 304 | endfunc |
| 305 | |
Bram Moolenaar | 1d859e2 | 2021-01-28 17:24:58 +0100 | [diff] [blame] | 306 | func Test_ex_mode_count_overflow() |
Bram Moolenaar | 97202d9 | 2021-01-28 18:34:35 +0100 | [diff] [blame] | 307 | " The multiplication causes an integer overflow |
| 308 | CheckNotAsan |
| 309 | |
Bram Moolenaar | 1d859e2 | 2021-01-28 17:24:58 +0100 | [diff] [blame] | 310 | " this used to cause a crash |
| 311 | let lines =<< trim END |
| 312 | call feedkeys("\<Esc>Q\<CR>") |
| 313 | v9|9silent! vi|333333233333y32333333%O |
| 314 | call writefile(['done'], 'Xdidexmode') |
| 315 | qall! |
| 316 | END |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 317 | call writefile(lines, 'Xexmodescript', 'D') |
Bram Moolenaar | 1d859e2 | 2021-01-28 17:24:58 +0100 | [diff] [blame] | 318 | call assert_equal(1, RunVim([], [], '-e -s -S Xexmodescript -c qa')) |
| 319 | call assert_equal(['done'], readfile('Xdidexmode')) |
| 320 | |
| 321 | call delete('Xdidexmode') |
Bram Moolenaar | 1d859e2 | 2021-01-28 17:24:58 +0100 | [diff] [blame] | 322 | endfunc |
| 323 | |
Bram Moolenaar | 85b6747 | 2022-01-25 11:55:02 +0000 | [diff] [blame] | 324 | func Test_ex_mode_large_indent() |
| 325 | new |
| 326 | set ts=500 ai |
| 327 | call setline(1, "\t") |
| 328 | exe "normal gQi\<CR>." |
| 329 | set ts=8 noai |
| 330 | bwipe! |
| 331 | endfunc |
| 332 | |
Bram Moolenaar | f50808e | 2022-04-16 18:52:17 +0100 | [diff] [blame] | 333 | " This was accessing illegal memory when using "+" for eap->cmd. |
| 334 | func Test_empty_command_visual_mode() |
| 335 | let lines =<< trim END |
| 336 | r<sfile> |
| 337 | 0norm0V: |
| 338 | :qall! |
| 339 | END |
Bram Moolenaar | 5c645a2 | 2022-09-21 22:00:03 +0100 | [diff] [blame] | 340 | call writefile(lines, 'Xexmodescript', 'D') |
Bram Moolenaar | f50808e | 2022-04-16 18:52:17 +0100 | [diff] [blame] | 341 | call assert_equal(1, RunVim([], [], '-u NONE -e -s -S Xexmodescript')) |
| 342 | |
Bram Moolenaar | 217ea51 | 2022-06-14 17:13:59 +0100 | [diff] [blame] | 343 | " This may cause a dialog to be displayed for an empty command, ignore it. |
| 344 | call delete('guidialogfile') |
Bram Moolenaar | f50808e | 2022-04-16 18:52:17 +0100 | [diff] [blame] | 345 | endfunc |
| 346 | |
Mohamed Akram | f3daa45 | 2024-07-06 17:12:09 +0200 | [diff] [blame] | 347 | " Test using backslash in ex-mode |
| 348 | func Test_backslash_multiline() |
| 349 | new |
| 350 | call setline(1, 'enum') |
| 351 | call feedkeys('Qg/enum/i\
\
.', "xt") |
| 352 | call assert_equal(["", "enum"], getline(1, 2)) |
| 353 | endfunc |
Bram Moolenaar | 85b6747 | 2022-01-25 11:55:02 +0000 | [diff] [blame] | 354 | |
Christian Brabandt | 248efab | 2024-07-07 19:44:16 +0200 | [diff] [blame] | 355 | " Test using backslash in ex-mode after patch 9.1.0535 |
| 356 | func Test_backslash_multiline2() |
| 357 | new |
| 358 | call feedkeys('Qa
X \\
Y
.', "xt") |
| 359 | call assert_equal(['X \\', "Y"], getline(1, 2)) |
| 360 | endfunc |
| 361 | |
Mohamed Akram | c25a708 | 2024-07-12 20:17:55 +0200 | [diff] [blame] | 362 | " Testing implicit print command |
| 363 | func Test_implicit_print() |
| 364 | new |
| 365 | call setline(1, ['one', 'two', 'three']) |
| 366 | call feedkeys('Q:let a=execute(":1,2")', 'xt') |
| 367 | call feedkeys('Q:let b=execute(":3")', 'xt') |
| 368 | call assert_equal('one two', a->split('\n')->join(' ')) |
| 369 | call assert_equal('three', b->split('\n')->join(' ')) |
| 370 | bw! |
| 371 | endfunc |
| 372 | |
Mohamed Akram | 8c446da | 2024-07-13 18:49:55 +0200 | [diff] [blame] | 373 | " Test inserting text after the trailing bar |
| 374 | func Test_insert_after_trailing_bar() |
| 375 | new |
| 376 | call feedkeys("Qi|\nfoo\n.\na|bar\nbar\n.\nc|baz\n.", "xt") |
| 377 | call assert_equal(['', 'foo', 'bar', 'baz'], getline(1, '$')) |
| 378 | bwipe! |
| 379 | endfunc |
| 380 | |
Bram Moolenaar | e20b9ec | 2020-02-03 21:40:04 +0100 | [diff] [blame] | 381 | " vim: shiftwidth=2 sts=2 expandtab |