blob: 5af4133ec8edde1aa39c36b28083933aa19ca613 [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 Moolenaarb0f94c12019-06-13 22:19:53 +02006if !exists("+linebreak")
7 throw 'Skipped, linebreak option missing'
8endif
9if !has("conceal")
10 throw 'Skipped, conceal feature missing'
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010011endif
12
13source view_util.vim
14
15function s:screen_lines(lnum, width) abort
16 return ScreenLines(a:lnum, a:width)
17endfunction
18
Bram Moolenaar1e115362019-01-09 23:01:02 +010019func s:compare_lines(expect, actual)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010020 call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
Bram Moolenaar1e115362019-01-09 23:01:02 +010021endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010022
23function s:test_windows(...)
24 call NewWindow(10, 20)
25 setl ts=8 sw=4 sts=4 linebreak sbr= wrap
26 exe get(a:000, 0, '')
27endfunction
28
29function s:close_windows(...)
30 call CloseWindow()
31 exe get(a:000, 0, '')
32endfunction
33
34func Test_set_linebreak()
35 call s:test_windows('setl ts=4 sbr=+')
36 call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ")
37 let lines = s:screen_lines([1, 4], winwidth(0))
38 let expect = [
39\ " abcdef ",
40\ "+hijklmn ",
41\ "+pqrstuvwxyz_1060ABC",
42\ "+DEFGHIJKLMNOP ",
43\ ]
44 call s:compare_lines(expect, lines)
45 call s:close_windows()
46endfunc
47
48func Test_linebreak_with_list()
49 call s:test_windows('setl ts=4 sbr=+ list listchars=')
50 call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ")
51 let lines = s:screen_lines([1, 4], winwidth(0))
52 let expect = [
53\ "^Iabcdef hijklmn^I ",
54\ "+pqrstuvwxyz_1060ABC",
55\ "+DEFGHIJKLMNOP ",
56\ "~ ",
57\ ]
58 call s:compare_lines(expect, lines)
59 call s:close_windows()
60endfunc
61
62func Test_linebreak_with_nolist()
63 call s:test_windows('setl ts=4 sbr=+ nolist')
64 call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ")
65 let lines = s:screen_lines([1, 4], winwidth(0))
66 let expect = [
67\ " abcdef ",
68\ "+hijklmn ",
69\ "+pqrstuvwxyz_1060ABC",
70\ "+DEFGHIJKLMNOP ",
71\ ]
72 call s:compare_lines(expect, lines)
73 call s:close_windows()
74endfunc
75
76func Test_should_break()
77 call s:test_windows('setl sbr=+ nolist')
78 call setline(1, "1\t" . repeat('a', winwidth(0)-2))
79 let lines = s:screen_lines([1, 4], winwidth(0))
80 let expect = [
81\ "1 ",
82\ "+aaaaaaaaaaaaaaaaaa ",
83\ "~ ",
84\ "~ ",
85\ ]
86 call s:compare_lines(expect, lines)
87 call s:close_windows()
88endfunc
89
90func Test_linebreak_with_conceal()
91 call s:test_windows('setl cpo&vim sbr=+ list conceallevel=2 concealcursor=nv listchars=tab:ab')
92 call setline(1, "_S_\t bla")
93 syn match ConcealVar contained /_/ conceal
94 syn match All /.*/ contains=ConcealVar
95 let lines = s:screen_lines([1, 4], winwidth(0))
96 let expect = [
97\ "Sabbbbbb bla ",
98\ "~ ",
99\ "~ ",
100\ "~ ",
101\ ]
102 call s:compare_lines(expect, lines)
103 call s:close_windows()
104endfunc
105
106func Test_virtual_block()
107 call s:test_windows('setl sbr=+')
108 call setline(1, [
109\ "REMOVE: this not",
110\ "REMOVE: aaaaaaaaaaaaa",
111\ ])
112 exe "norm! 1/^REMOVE:"
113 exe "norm! 0\<C-V>jf x"
114 $put
115 let lines = s:screen_lines([1, 4], winwidth(0))
116 let expect = [
117\ "this not ",
118\ "aaaaaaaaaaaaa ",
119\ "REMOVE: ",
120\ "REMOVE: ",
121\ ]
122 call s:compare_lines(expect, lines)
123 call s:close_windows()
124endfunc
125
126func Test_virtual_block_and_vbA()
127 call s:test_windows()
128 call setline(1, "long line: " . repeat("foobar ", 40) . "TARGET at end")
129 exe "norm! $3B\<C-v>eAx\<Esc>"
130 let lines = s:screen_lines([1, 10], winwidth(0))
131 let expect = [
132\ "foobar foobar ",
133\ "foobar foobar ",
134\ "foobar foobar ",
135\ "foobar foobar ",
136\ "foobar foobar ",
137\ "foobar foobar ",
138\ "foobar foobar ",
139\ "foobar foobar ",
140\ "foobar foobar ",
141\ "foobar TARGETx at ",
142\ ]
143 call s:compare_lines(expect, lines)
144 call s:close_windows()
145endfunc
146
147func Test_virtual_char_and_block()
148 call s:test_windows()
149 call setline(1, "1111-1111-1111-11-1111-1111-1111")
150 exe "norm! 0f-lv3lc2222\<Esc>bgj."
151 let lines = s:screen_lines([1, 2], winwidth(0))
152 let expect = [
153\ "1111-2222-1111-11- ",
154\ "1111-2222-1111 ",
155\ ]
156 call s:compare_lines(expect, lines)
157 call s:close_windows()
158endfunc
159
160func Test_undo_after_block_visual()
161 call s:test_windows()
162 call setline(1, ["aaa", "aaa", "a"])
163 exe "norm! gg\<C-V>2j~e."
164 let lines = s:screen_lines([1, 3], winwidth(0))
165 let expect = [
166\ "AaA ",
167\ "AaA ",
168\ "A ",
169\ ]
170 call s:compare_lines(expect, lines)
171 call s:close_windows()
172endfunc
173
174func Test_norm_after_block_visual()
175 call s:test_windows()
176 call setline(1, ["abcd{ef", "ghijklm", "no}pgrs"])
177 exe "norm! ggf{\<C-V>\<C-V>c%"
178 let lines = s:screen_lines([1, 3], winwidth(0))
179 let expect = [
180\ "abcdpgrs ",
181\ "~ ",
182\ "~ ",
183\ ]
184 call s:compare_lines(expect, lines)
185 call s:close_windows()
186endfunc
187
188func Test_block_replace_after_wrapping()
189 call s:test_windows()
190 call setline(1, repeat("a", 150))
191 exe "norm! 0yypk147|\<C-V>jr0"
192 call assert_equal(repeat("a", 146) . "0aaa", getline(1))
193 call assert_equal(repeat("a", 146) . "0aaa", getline(2))
194 let lines = s:screen_lines([1, 10], winwidth(0))
195 let expect = [
196\ "aaaaaaaaaaaaaaaaaaaa",
197\ "aaaaaaaaaaaaaaaaaaaa",
198\ "aaaaaaaaaaaaaaaaaaaa",
199\ "aaaaaaaaaaaaaaaaaaaa",
200\ "aaaaaaaaaaaaaaaaaaaa",
201\ "aaaaaaaaaaaaaaaaaaaa",
202\ "aaaaaaaaaaaaaaaaaaaa",
203\ "aaaaaa0aaa ",
204\ "@ ",
205\ "@ ",
206\ ]
207 call s:compare_lines(expect, lines)
208 call s:close_windows()
209endfunc
210
211func Test_list_with_listchars()
212 call s:test_windows('setl list listchars=space:_,trail:-,tab:>-,eol:$')
213 call setline(1, "a aaaaaaaaaaaaaaaaaaaaaa\ta ")
214 let lines = s:screen_lines([1, 3], winwidth(0))
215 let expect = [
216\ "a_ ",
217\ "aaaaaaaaaaaaaaaaaaaa",
218\ "aa>-----a-$ ",
219\ ]
220 call s:compare_lines(expect, lines)
221 call s:close_windows()
222endfunc
Bram Moolenaarabc39ab2017-03-01 18:04:05 +0100223
224func Test_list_with_tab_and_skipping_first_chars()
225 call s:test_windows('setl list listchars=tab:>- ts=70 nowrap')
226 call setline(1, ["iiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa"])
227 call cursor(4,64)
228 norm! 2zl
229 let lines = s:screen_lines([1, 4], winwidth(0))
230 let expect = [
231\ "---------------aaaaa",
232\ "---------------aaaaa",
233\ "---------------aaaaa",
234\ "iiiiiiiii>-----aaaaa",
235\ ]
236 call s:compare_lines(expect, lines)
237 call s:close_windows()
238endfu