blob: 37cc24cb4cfebefe7b4c7a3543a52930f78f06bb [file] [log] [blame]
Bram Moolenaar94f82cb2019-07-24 22:30:27 +02001" Tests for various Ex commands.
2
3func Test_ex_delete()
4 new
5 call setline(1, ['a', 'b', 'c'])
6 2
7 " :dl is :delete with the "l" flag, not :dlist
8 .dl
9 call assert_equal(['a', 'c'], getline(1, 2))
10endfunc
Bram Moolenaar0acae7a2019-08-06 21:29:29 +020011
12func Test_range_error()
13 call assert_fails(':.echo 1', 'E481:')
14 call assert_fails(':$echo 1', 'E481:')
15 call assert_fails(':1,2echo 1', 'E481:')
16 call assert_fails(':+1echo 1', 'E481:')
17 call assert_fails(':/1/echo 1', 'E481:')
18 call assert_fails(':\/echo 1', 'E481:')
19 normal vv
20 call assert_fails(":'<,'>echo 1", 'E481:')
21endfunc
Bram Moolenaar52410572019-10-27 05:12:45 +010022
23func Test_buffers_lastused()
24 call test_settime(localtime() - 2000) " middle
25 edit bufa
26 enew
27 call test_settime(localtime() - 10) " newest
28 edit bufb
29 enew
30 call test_settime(1550010000) " oldest
31 edit bufc
32 enew
33 call test_settime(0)
34 enew
35
36 let ls = split(execute('buffers t', 'silent!'), '\n')
37 let bufs = ls->map({i,v->split(v, '"\s*')[1:2]})
38 call assert_equal(['bufb', 'bufa', 'bufc'], bufs[1:]->map({i,v->v[0]}))
39 call assert_match('1[0-3] seconds ago', bufs[1][1])
40 call assert_match('\d\d:\d\d:\d\d', bufs[2][1])
41 call assert_match('2019/02/1\d \d\d:\d\d:00', bufs[3][1])
42
43 bwipeout bufa
44 bwipeout bufb
45 bwipeout bufc
46endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +010047
48" Test for the :copy command
49func Test_copy()
50 new
51
52 call setline(1, ['L1', 'L2', 'L3', 'L4'])
53 " copy lines in a range to inside the range
54 1,3copy 2
55 call assert_equal(['L1', 'L2', 'L1', 'L2', 'L3', 'L3', 'L4'], getline(1, 7))
56
57 close!
58endfunc
59
60" Test for the :file command
61func Test_file_cmd()
62 call assert_fails('3file', 'E474:')
63 call assert_fails('0,0file', 'E474:')
64 call assert_fails('0file abc', 'E474:')
65endfunc
66
67" Test for the :drop command
68func Test_drop_cmd()
69 call writefile(['L1', 'L2'], 'Xfile')
70 enew | only
71 drop Xfile
72 call assert_equal('L2', getline(2))
73 " Test for switching to an existing window
74 below new
75 drop Xfile
76 call assert_equal(1, winnr())
77 " Test for splitting the current window
78 enew | only
79 set modified
80 drop Xfile
81 call assert_equal(2, winnr('$'))
82 " Check for setting the argument list
83 call assert_equal(['Xfile'], argv())
84 enew | only!
85 call delete('Xfile')
86endfunc
87
88" Test for the :append command
89func Test_append_cmd()
90 new
91 call setline(1, [' L1'])
92 call feedkeys(":append\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
93 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$'))
94 %delete _
95 " append after a specific line
96 call setline(1, [' L1', ' L2', ' L3'])
97 call feedkeys(":2append\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
98 call assert_equal([' L1', ' L2', ' L4', ' L5', ' L3'], getline(1, '$'))
99 %delete _
100 " append with toggling 'autoindent'
101 call setline(1, [' L1'])
102 call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
103 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$'))
104 call assert_false(&autoindent)
105 %delete _
106 " append with 'autoindent' set and toggling 'autoindent'
107 set autoindent
108 call setline(1, [' L1'])
109 call feedkeys(":append!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
110 call assert_equal([' L1', ' L2', ' L3'], getline(1, '$'))
111 call assert_true(&autoindent)
112 set autoindent&
113 close!
114endfunc
115
116" Test for the :insert command
117func Test_insert_cmd()
118 new
119 call setline(1, [' L1'])
120 call feedkeys(":insert\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
121 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$'))
122 %delete _
123 " insert before a specific line
124 call setline(1, [' L1', ' L2', ' L3'])
125 call feedkeys(":2insert\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
126 call assert_equal([' L1', ' L4', ' L5', ' L2', ' L3'], getline(1, '$'))
127 %delete _
128 " insert with toggling 'autoindent'
129 call setline(1, [' L1'])
130 call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
131 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$'))
132 call assert_false(&autoindent)
133 %delete _
134 " insert with 'autoindent' set and toggling 'autoindent'
135 set autoindent
136 call setline(1, [' L1'])
137 call feedkeys(":insert!\<CR> L2\<CR> L3\<CR>.\<CR>", 'xt')
138 call assert_equal([' L2', ' L3', ' L1'], getline(1, '$'))
139 call assert_true(&autoindent)
140 set autoindent&
141 close!
142endfunc
143
144" Test for the :change command
145func Test_change_cmd()
146 new
147 call setline(1, [' L1', 'L2', 'L3'])
148 call feedkeys(":change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
149 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$'))
150 %delete _
151 " change a specific line
152 call setline(1, [' L1', ' L2', ' L3'])
153 call feedkeys(":2change\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
154 call assert_equal([' L1', ' L4', ' L5', ' L3'], getline(1, '$'))
155 %delete _
156 " change with toggling 'autoindent'
157 call setline(1, [' L1', 'L2', 'L3'])
158 call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
159 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$'))
160 call assert_false(&autoindent)
161 %delete _
162 " change with 'autoindent' set and toggling 'autoindent'
163 set autoindent
164 call setline(1, [' L1', 'L2', 'L3'])
165 call feedkeys(":change!\<CR> L4\<CR> L5\<CR>.\<CR>", 'xt')
166 call assert_equal([' L4', ' L5', 'L2', 'L3'], getline(1, '$'))
167 call assert_true(&autoindent)
168 set autoindent&
169 close!
170endfunc
171
172" vim: shiftwidth=2 sts=2 expandtab