blob: 6f12b5f5366778b96f59910db819d57b931408e5 [file] [log] [blame]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +01001" Test for linebreak and list option in utf-8 mode
2
3set encoding=utf-8
4scriptencoding utf-8
5
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02006source check.vim
7CheckOption linebreak
8CheckFeature conceal
9CheckFeature signs
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010010
11source view_util.vim
12
Bram Moolenaar1e115362019-01-09 23:01:02 +010013func s:screen_lines(lnum, width) abort
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010014 return ScreenLines(a:lnum, a:width)
Bram Moolenaar1e115362019-01-09 23:01:02 +010015endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010016
Bram Moolenaar1e115362019-01-09 23:01:02 +010017func s:compare_lines(expect, actual)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010018 call assert_equal(a:expect, a:actual)
Bram Moolenaar1e115362019-01-09 23:01:02 +010019endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010020
Bram Moolenaar1e115362019-01-09 23:01:02 +010021func s:screen_attr(lnum, chars, ...) abort
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010022 let line = getline(a:lnum)
23 let attr = []
24 let prefix = get(a:000, 0, 0)
25 for i in range(a:chars[0], a:chars[1])
26 let scol = strdisplaywidth(strcharpart(line, 0, i-1)) + 1
27 let attr += [screenattr(a:lnum, scol + prefix)]
28 endfor
29 return attr
Bram Moolenaar1e115362019-01-09 23:01:02 +010030endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010031
Bram Moolenaar1e115362019-01-09 23:01:02 +010032func s:test_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010033 call NewWindow(10, 20)
34 setl ts=4 sw=4 sts=4 linebreak sbr=+ wrap
35 exe get(a:000, 0, '')
Bram Moolenaar1e115362019-01-09 23:01:02 +010036endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010037
Bram Moolenaar1e115362019-01-09 23:01:02 +010038func s:close_windows(...)
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010039 call CloseWindow()
40 exe get(a:000, 0, '')
Bram Moolenaar1e115362019-01-09 23:01:02 +010041endfunc
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010042
43func Test_linebreak_with_fancy_listchars()
44 call s:test_windows("setl list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
45 call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP ")
46 redraw!
47 let lines = s:screen_lines([1, 4], winwidth(0))
48 let expect = [
49\ "▕———abcdef ",
50\ "+hijklmn▕——— ",
51\ "+pqrstuvwxyz1060ABC",
52\ "+DEFGHIJKLMNOPˑ¶ ",
53\ ]
54 call s:compare_lines(expect, lines)
55 call s:close_windows()
56endfunc
57
58func Test_nolinebreak_with_list()
59 call s:test_windows("setl nolinebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
60 call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP ")
61 redraw!
62 let lines = s:screen_lines([1, 4], winwidth(0))
63 let expect = [
64\ "▕———abcdef hijklmn▕—",
65\ "+pqrstuvwxyz1060ABC",
66\ "+DEFGHIJKLMNOPˑ¶ ",
67\ "~ ",
68\ ]
69 call s:compare_lines(expect, lines)
70 call s:close_windows()
71endfunc
72
73func Test_linebreak_with_nolist()
74 call s:test_windows('setl nolist')
75 call setline(1, "\t*mask = nil;")
76 redraw!
77 let lines = s:screen_lines([1, 4], winwidth(0))
78 let expect = [
79\ " *mask = nil; ",
80\ "~ ",
81\ "~ ",
82\ "~ ",
83\ ]
84 call s:compare_lines(expect, lines)
85 call s:close_windows()
86endfunc
87
88func Test_list_and_concealing1()
89 call s:test_windows('setl list listchars=tab:>- cole=1')
90 call setline(1, [
91\ "#define ABCDE\t\t1",
92\ "#define ABCDEF\t\t1",
93\ "#define ABCDEFG\t\t1",
94\ "#define ABCDEFGH\t1",
95\ "#define MSG_MODE_FILE\t\t\t1",
96\ "#define MSG_MODE_CONSOLE\t\t2",
97\ "#define MSG_MODE_FILE_AND_CONSOLE\t3",
98\ "#define MSG_MODE_FILE_THEN_CONSOLE\t4",
99\ ])
100 vert resize 40
101 syn match Conceal conceal cchar=>'AB\|MSG_MODE'
102 redraw!
103 let lines = s:screen_lines([1, 7], winwidth(0))
104 let expect = [
105\ "#define ABCDE>-->---1 ",
106\ "#define >CDEF>-->---1 ",
107\ "#define >CDEFG>->---1 ",
108\ "#define >CDEFGH>----1 ",
109\ "#define >_FILE>--------->--->---1 ",
110\ "#define >_CONSOLE>---------->---2 ",
111\ "#define >_FILE_AND_CONSOLE>---------3 ",
112\ ]
113 call s:compare_lines(expect, lines)
114 call s:close_windows()
115endfunc
116
117func Test_list_and_concealing2()
118 call s:test_windows('setl nowrap ts=2 list listchars=tab:>- cole=2 concealcursor=n')
119 call setline(1, "bbeeeeee\t\t;\tsome text")
120 vert resize 40
121 syn clear
122 syn match meaning /;\s*\zs.*/
123 syn match hasword /^\x\{8}/ contains=word
124 syn match word /\<\x\{8}\>/ contains=beginword,endword contained
125 syn match beginword /\<\x\x/ contained conceal
126 syn match endword /\x\{6}\>/ contained
127 hi meaning guibg=blue
128 hi beginword guibg=green
129 hi endword guibg=red
130 redraw!
131 let lines = s:screen_lines([1, 1], winwidth(0))
132 let expect = [
133\ "eeeeee>--->-;>some text ",
134\ ]
135 call s:compare_lines(expect, lines)
136 call s:close_windows()
137endfunc
138
139func Test_screenattr_for_comment()
140 call s:test_windows("setl ft=c ts=7 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
141 call setline(1, " /*\t\t and some more */")
142 norm! gg0
143 syntax on
144 hi SpecialKey term=underline ctermfg=red guifg=red
145 redraw!
146 let line = getline(1)
147 let attr = s:screen_attr(1, [1, 6])
148 call assert_notequal(attr[0], attr[1])
149 call assert_notequal(attr[1], attr[3])
150 call assert_notequal(attr[3], attr[5])
151 call s:close_windows()
152endfunc
153
154func Test_visual_block_and_selection_exclusive()
155 call s:test_windows('setl selection=exclusive')
156 call setline(1, "long line: " . repeat("foobar ", 40) . "TARGETÃ' at end")
157 exe "norm! $3B\<C-v>eAx\<Esc>"
158 let lines = s:screen_lines([1, 10], winwidth(0))
159 let expect = [
160\ "+foobar foobar ",
161\ "+foobar foobar ",
162\ "+foobar foobar ",
163\ "+foobar foobar ",
164\ "+foobar foobar ",
165\ "+foobar foobar ",
166\ "+foobar foobar ",
167\ "+foobar foobar ",
168\ "+foobar foobar ",
169\ "+foobar TARGETÃx' ",
170\ ]
171 call s:compare_lines(expect, lines)
172 call s:close_windows()
173endfunc
174
175func Test_multibyte_sign_and_colorcolumn()
176 call s:test_windows("setl nolinebreak cc=3 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6")
177 call setline(1, ["", "a b c", "a b c"])
178 exe "sign define foo text=\uff0b"
179 exe "sign place 1 name=foo line=2 buffer=" . bufnr('%')
180 redraw!
181 norm! ggj0
182 let signwidth = strdisplaywidth("\uff0b")
183 let attr1 = s:screen_attr(2, [1, 3], signwidth)
184 let attr2 = s:screen_attr(3, [1, 3], signwidth)
185 call assert_equal(attr1[0], attr2[0])
186 call assert_equal(attr1[1], attr2[1])
187 call assert_equal(attr1[2], attr2[2])
188 let lines = s:screen_lines([1, 3], winwidth(0))
189 let expect = [
190\ " ",
191\ "a b c ",
192\ " a b c ",
193\ ]
194 call s:compare_lines(expect, lines)
195 call s:close_windows()
196endfunc
Bram Moolenaar38632fa2017-02-26 19:40:59 +0100197
Bram Moolenaar774e5a92017-06-25 18:03:37 +0200198func Test_colorcolumn_priority()
199 call s:test_windows('setl cc=4 cuc hls')
200 call setline(1, ["xxyy", ""])
201 norm! gg
202 exe "normal! /xxyy\<CR>"
203 norm! G
204 redraw!
205 let line_attr = s:screen_attr(1, [1, &cc])
206 " Search wins over CursorColumn
207 call assert_equal(line_attr[1], line_attr[0])
208 " Search wins over Colorcolumn
209 call assert_equal(line_attr[2], line_attr[3])
210 call s:close_windows('setl hls&vim')
211endfunc
212
Bram Moolenaar38632fa2017-02-26 19:40:59 +0100213func Test_illegal_byte_and_breakat()
214 call s:test_windows("setl sbr= brk+=<")
215 vert resize 18
216 call setline(1, repeat("\x80", 6))
217 redraw!
218 let lines = s:screen_lines([1, 2], winwidth(0))
219 let expect = [
220\ "<80><80><80><80><8",
221\ "0><80> ",
222\ ]
223 call s:compare_lines(expect, lines)
224 call s:close_windows('setl brk&vim')
225endfunc
226
227func Test_multibyte_wrap_and_breakat()
228 call s:test_windows("setl sbr= brk+=>")
229 call setline(1, repeat('a', 17) . repeat('あ', 2))
230 redraw!
231 let lines = s:screen_lines([1, 2], winwidth(0))
232 let expect = [
233\ "aaaaaaaaaaaaaaaaaあ>",
234\ " ",
235\ ]
236 call s:compare_lines(expect, lines)
237 call s:close_windows('setl brk&vim')
238endfunc
Bram Moolenaarabc39ab2017-03-01 18:04:05 +0100239
240func Test_chinese_char_on_wrap_column()
241 call s:test_windows("setl nolbr wrap sbr=")
242 syntax off
243 call setline(1, [
244\ 'aaaaaaaaaaaaaaaaaaa中'.
245\ 'aaaaaaaaaaaaaaaaa中'.
246\ 'aaaaaaaaaaaaaaaaa中'.
247\ 'aaaaaaaaaaaaaaaaa中'.
248\ 'aaaaaaaaaaaaaaaaa中'.
249\ 'aaaaaaaaaaaaaaaaa中'.
250\ 'aaaaaaaaaaaaaaaaa中'.
251\ 'aaaaaaaaaaaaaaaaa中'.
252\ 'aaaaaaaaaaaaaaaaa中'.
253\ 'aaaaaaaaaaaaaaaaa中'.
254\ 'hello'])
255 call cursor(1,1)
256 norm! $
257 redraw!
258 let expect=[
259\ '中aaaaaaaaaaaaaaaaa>',
260\ '中aaaaaaaaaaaaaaaaa>',
261\ '中aaaaaaaaaaaaaaaaa>',
262\ '中aaaaaaaaaaaaaaaaa>',
263\ '中aaaaaaaaaaaaaaaaa>',
264\ '中aaaaaaaaaaaaaaaaa>',
265\ '中aaaaaaaaaaaaaaaaa>',
266\ '中aaaaaaaaaaaaaaaaa>',
267\ '中aaaaaaaaaaaaaaaaa>',
268\ '中hello ']
269 let lines = s:screen_lines([1, 10], winwidth(0))
270 call s:compare_lines(expect, lines)
271 call s:close_windows()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200272endfunc
273
274" vim: shiftwidth=2 sts=2 expandtab