blob: 24bd25679a654e58357afebacba6f4fcbbe3c99d [file] [log] [blame]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +01001" Test for linebreak and list option (non-utf8)
2
3set encoding=latin1
4scriptencoding latin1
5
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02006source check.vim
7CheckOption linebreak
8CheckFeature conceal
Bram Moolenaar544d3bc2017-02-05 21:14:50 +01009
10source view_util.vim
11
12function s:screen_lines(lnum, width) abort
13 return ScreenLines(a:lnum, a:width)
14endfunction
15
Bram Moolenaar1e115362019-01-09 23:01:02 +010016func s:compare_lines(expect, actual)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010017 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
Bram Moolenaar1e115362019-01-09 23:01:02 +010018endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010019
20function s:test_windows(...)
21 call NewWindow(10, 20)
22 setl ts=8 sw=4 sts=4 linebreak sbr= wrap
23 exe get(a:000, 0, '')
24endfunction
25
26function s:close_windows(...)
27 call CloseWindow()
28 exe get(a:000, 0, '')
29endfunction
30
31func Test_set_linebreak()
32 call s:test_windows('setl ts=4 sbr=+')
33 call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ")
34 let lines = s:screen_lines([1, 4], winwidth(0))
35 let expect = [
36\ " abcdef ",
37\ "+hijklmn ",
38\ "+pqrstuvwxyz_1060ABC",
39\ "+DEFGHIJKLMNOP ",
40\ ]
41 call s:compare_lines(expect, lines)
42 call s:close_windows()
43endfunc
44
45func Test_linebreak_with_list()
Bram Moolenaareed9d462021-02-15 20:38:25 +010046 set listchars=
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010047 call s:test_windows('setl ts=4 sbr=+ list listchars=')
48 call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ")
49 let lines = s:screen_lines([1, 4], winwidth(0))
50 let expect = [
51\ "^Iabcdef hijklmn^I ",
52\ "+pqrstuvwxyz_1060ABC",
53\ "+DEFGHIJKLMNOP ",
54\ "~ ",
55\ ]
56 call s:compare_lines(expect, lines)
57 call s:close_windows()
Bram Moolenaareed9d462021-02-15 20:38:25 +010058 set listchars&vim
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010059endfunc
60
61func Test_linebreak_with_nolist()
62 call s:test_windows('setl ts=4 sbr=+ nolist')
63 call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ")
64 let lines = s:screen_lines([1, 4], winwidth(0))
65 let expect = [
66\ " abcdef ",
67\ "+hijklmn ",
68\ "+pqrstuvwxyz_1060ABC",
69\ "+DEFGHIJKLMNOP ",
70\ ]
71 call s:compare_lines(expect, lines)
72 call s:close_windows()
73endfunc
74
75func Test_should_break()
76 call s:test_windows('setl sbr=+ nolist')
77 call setline(1, "1\t" . repeat('a', winwidth(0)-2))
78 let lines = s:screen_lines([1, 4], winwidth(0))
79 let expect = [
80\ "1 ",
81\ "+aaaaaaaaaaaaaaaaaa ",
82\ "~ ",
83\ "~ ",
84\ ]
85 call s:compare_lines(expect, lines)
86 call s:close_windows()
87endfunc
88
89func Test_linebreak_with_conceal()
90 call s:test_windows('setl cpo&vim sbr=+ list conceallevel=2 concealcursor=nv listchars=tab:ab')
91 call setline(1, "_S_\t bla")
92 syn match ConcealVar contained /_/ conceal
93 syn match All /.*/ contains=ConcealVar
94 let lines = s:screen_lines([1, 4], winwidth(0))
95 let expect = [
96\ "Sabbbbbb bla ",
97\ "~ ",
98\ "~ ",
99\ "~ ",
100\ ]
101 call s:compare_lines(expect, lines)
102 call s:close_windows()
103endfunc
104
Bram Moolenaar03c3bd92020-01-23 20:58:09 +0100105func Test_linebreak_with_visual_operations()
106 call s:test_windows()
107 let line = '1234567890 2234567890 3234567890'
108 call setline(1, line)
109
110 " yank
111 exec "norm! ^w\<C-V>ey"
112 call assert_equal('2234567890', @@)
113 exec "norm! w\<C-V>ey"
114 call assert_equal('3234567890', @@)
115
116 " increment / decrement
117 exec "norm! ^w\<C-V>\<C-A>w\<C-V>\<C-X>"
118 call assert_equal('1234567890 3234567890 2234567890', getline(1))
119
120 " replace
121 exec "norm! ^w\<C-V>3lraw\<C-V>3lrb"
122 call assert_equal('1234567890 aaaa567890 bbbb567890', getline(1))
123
124 " tilde
125 exec "norm! ^w\<C-V>2l~w\<C-V>2l~"
126 call assert_equal('1234567890 AAAa567890 BBBb567890', getline(1))
127
128 " delete and insert
129 exec "norm! ^w\<C-V>3lc2345\<Esc>w\<C-V>3lc3456\<Esc>"
130 call assert_equal('1234567890 2345567890 3456567890', getline(1))
131 call assert_equal('BBBb', @@)
132
133 call s:close_windows()
134endfunc
135
Bram Moolenaar544d3bc2017-02-05 21:14:50 +0100136func Test_virtual_block()
137 call s:test_windows('setl sbr=+')
138 call setline(1, [
139\ "REMOVE: this not",
140\ "REMOVE: aaaaaaaaaaaaa",
141\ ])
142 exe "norm! 1/^REMOVE:"
143 exe "norm! 0\<C-V>jf x"
144 $put
145 let lines = s:screen_lines([1, 4], winwidth(0))
146 let expect = [
147\ "this not ",
148\ "aaaaaaaaaaaaa ",
149\ "REMOVE: ",
150\ "REMOVE: ",
151\ ]
152 call s:compare_lines(expect, lines)
153 call s:close_windows()
154endfunc
155
156func Test_virtual_block_and_vbA()
157 call s:test_windows()
158 call setline(1, "long line: " . repeat("foobar ", 40) . "TARGET at end")
159 exe "norm! $3B\<C-v>eAx\<Esc>"
160 let lines = s:screen_lines([1, 10], winwidth(0))
161 let expect = [
162\ "foobar foobar ",
163\ "foobar foobar ",
164\ "foobar foobar ",
165\ "foobar foobar ",
166\ "foobar foobar ",
167\ "foobar foobar ",
168\ "foobar foobar ",
169\ "foobar foobar ",
170\ "foobar foobar ",
171\ "foobar TARGETx at ",
172\ ]
173 call s:compare_lines(expect, lines)
174 call s:close_windows()
175endfunc
176
177func Test_virtual_char_and_block()
178 call s:test_windows()
179 call setline(1, "1111-1111-1111-11-1111-1111-1111")
180 exe "norm! 0f-lv3lc2222\<Esc>bgj."
181 let lines = s:screen_lines([1, 2], winwidth(0))
182 let expect = [
183\ "1111-2222-1111-11- ",
184\ "1111-2222-1111 ",
185\ ]
186 call s:compare_lines(expect, lines)
187 call s:close_windows()
188endfunc
189
190func Test_undo_after_block_visual()
191 call s:test_windows()
192 call setline(1, ["aaa", "aaa", "a"])
193 exe "norm! gg\<C-V>2j~e."
194 let lines = s:screen_lines([1, 3], winwidth(0))
195 let expect = [
196\ "AaA ",
197\ "AaA ",
198\ "A ",
199\ ]
200 call s:compare_lines(expect, lines)
201 call s:close_windows()
202endfunc
203
204func Test_norm_after_block_visual()
205 call s:test_windows()
206 call setline(1, ["abcd{ef", "ghijklm", "no}pgrs"])
207 exe "norm! ggf{\<C-V>\<C-V>c%"
208 let lines = s:screen_lines([1, 3], winwidth(0))
209 let expect = [
210\ "abcdpgrs ",
211\ "~ ",
212\ "~ ",
213\ ]
214 call s:compare_lines(expect, lines)
215 call s:close_windows()
216endfunc
217
218func Test_block_replace_after_wrapping()
219 call s:test_windows()
220 call setline(1, repeat("a", 150))
221 exe "norm! 0yypk147|\<C-V>jr0"
222 call assert_equal(repeat("a", 146) . "0aaa", getline(1))
223 call assert_equal(repeat("a", 146) . "0aaa", getline(2))
224 let lines = s:screen_lines([1, 10], winwidth(0))
225 let expect = [
226\ "aaaaaaaaaaaaaaaaaaaa",
227\ "aaaaaaaaaaaaaaaaaaaa",
228\ "aaaaaaaaaaaaaaaaaaaa",
229\ "aaaaaaaaaaaaaaaaaaaa",
230\ "aaaaaaaaaaaaaaaaaaaa",
231\ "aaaaaaaaaaaaaaaaaaaa",
232\ "aaaaaaaaaaaaaaaaaaaa",
233\ "aaaaaa0aaa ",
234\ "@ ",
235\ "@ ",
236\ ]
237 call s:compare_lines(expect, lines)
238 call s:close_windows()
239endfunc
240
241func Test_list_with_listchars()
242 call s:test_windows('setl list listchars=space:_,trail:-,tab:>-,eol:$')
243 call setline(1, "a aaaaaaaaaaaaaaaaaaaaaa\ta ")
244 let lines = s:screen_lines([1, 3], winwidth(0))
245 let expect = [
246\ "a_ ",
247\ "aaaaaaaaaaaaaaaaaaaa",
248\ "aa>-----a-$ ",
249\ ]
250 call s:compare_lines(expect, lines)
251 call s:close_windows()
252endfunc
Bram Moolenaarabc39ab2017-03-01 18:04:05 +0100253
254func Test_list_with_tab_and_skipping_first_chars()
255 call s:test_windows('setl list listchars=tab:>- ts=70 nowrap')
256 call setline(1, ["iiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa"])
257 call cursor(4,64)
258 norm! 2zl
259 let lines = s:screen_lines([1, 4], winwidth(0))
260 let expect = [
261\ "---------------aaaaa",
262\ "---------------aaaaa",
263\ "---------------aaaaa",
264\ "iiiiiiiii>-----aaaaa",
265\ ]
266 call s:compare_lines(expect, lines)
267 call s:close_windows()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200268endfunc
269
270" vim: shiftwidth=2 sts=2 expandtab