blob: 00a35a3061697727a4136475c9c97ac728628bc7 [file] [log] [blame]
Bram Moolenaar59cb0412019-12-18 22:26:31 +01001" Test editing line in Ex mode (see :help Q and :help gQ).
2
3" Helper function to test editing line in Q Ex mode
4func Ex_Q(cmd)
5 " Is there a simpler way to test editing Ex line?
6 call feedkeys("Q"
7 \ .. "let s:test_ex =<< END\<CR>"
8 \ .. a:cmd .. "\<CR>"
9 \ .. "END\<CR>"
10 \ .. "visual\<CR>", 'tx')
11 return s:test_ex[0]
12endfunc
13
14" Helper function to test editing line in gQ Ex mode
15func Ex_gQ(cmd)
16 call feedkeys("gQ" .. a:cmd .. "\<C-b>\"\<CR>", 'tx')
17 let ret = @:[1:] " Remove leading quote.
18 call feedkeys("visual\<CR>", 'tx')
19 return ret
20endfunc
21
22" Helper function to test editing line with both Q and gQ Ex mode.
23func Ex(cmd)
24 return [Ex_Q(a:cmd), Ex_gQ(a:cmd)]
25endfunc
26
27" Test editing line in Ex mode (both Q and gQ)
28func Test_ex_mode()
29 let encoding_save = &encoding
30 set sw=2
31
32 for e in ['utf8', 'latin1']
33 exe 'set encoding=' . e
34
35 call assert_equal(['bar', 'bar'], Ex("foo bar\<C-u>bar"), e)
36 call assert_equal(["1\<C-u>2", "1\<C-u>2"], Ex("1\<C-v>\<C-u>2"), e)
37 call assert_equal(["1\<C-b>2\<C-e>3", '213'], Ex("1\<C-b>2\<C-e>3"), e)
38 call assert_equal(['0123', '2013'], Ex("01\<Home>2\<End>3"), e)
39 call assert_equal(['0123', '0213'], Ex("01\<Left>2\<Right>3"), e)
40 call assert_equal(['01234', '0342'], Ex("012\<Left>\<Left>\<Insert>3\<Insert>4"), e)
41 call assert_equal(["foo bar\<C-w>", 'foo '], Ex("foo bar\<C-w>"), e)
42 call assert_equal(['foo', 'foo'], Ex("fooba\<Del>\<Del>"), e)
43 call assert_equal(["foo\tbar", 'foobar'], Ex("foo\<Tab>bar"), e)
44 call assert_equal(["abbrev\t", 'abbreviate'], Ex("abbrev\<Tab>"), e)
45 call assert_equal([' 1', "1\<C-t>\<C-t>"], Ex("1\<C-t>\<C-t>"), e)
46 call assert_equal([' 1', "1\<C-t>\<C-t>"], Ex("1\<C-t>\<C-t>\<C-d>"), e)
47 call assert_equal([' foo', ' foo'], Ex(" foo\<C-d>"), e)
48 call assert_equal(['foo', ' foo0'], Ex(" foo0\<C-d>"), e)
49 call assert_equal(['foo', ' foo^'], Ex(" foo^\<C-d>"), e)
50 endfor
51
52 set sw&
53 let &encoding = encoding_save
54endfunc