blob: 987ed661d4c196f9b9cb385dcc2c16b82b5847bf [file] [log] [blame]
Bram Moolenaar209d3872017-11-16 21:52:51 +01001" Tests for 'listchars' display with 'list' and :list
2
3source view_util.vim
4
5func Test_listchars()
6 enew!
7 set ff=unix
8 set list
9
10 set listchars+=tab:>-,space:.,trail:<
11 call append(0, [
12 \ ' aa ',
13 \ ' bb ',
14 \ ' cccc ',
15 \ 'dd ee ',
16 \ ' '
17 \ ])
18 let expected = [
19 \ '>-------aa>-----$',
20 \ '..bb>---<<$',
21 \ '...cccc><$',
22 \ 'dd........ee<<>-$',
23 \ '<$'
24 \ ]
25 redraw!
26 for i in range(1, 5)
27 call cursor(i, 1)
Bram Moolenaarf92e58c2019-09-08 21:51:41 +020028 call assert_equal([expected[i - 1]], ScreenLines(i, '$'->virtcol()))
Bram Moolenaar209d3872017-11-16 21:52:51 +010029 endfor
30
31 set listchars-=trail:<
32 let expected = [
33 \ '>-------aa>-----$',
34 \ '..bb>---..$',
35 \ '...cccc>.$',
36 \ 'dd........ee..>-$',
37 \ '.$'
38 \ ]
39 redraw!
40 for i in range(1, 5)
41 call cursor(i, 1)
42 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
43 endfor
44
Bram Moolenaar83a52172019-01-16 22:41:54 +010045 " tab with 3rd character.
46 set listchars-=tab:>-
47 set listchars+=tab:<=>,trail:-
48 let expected = [
49 \ '<======>aa<====>$',
50 \ '..bb<==>--$',
51 \ '...cccc>-$',
52 \ 'dd........ee--<>$',
53 \ '-$'
54 \ ]
55 redraw!
56 for i in range(1, 5)
57 call cursor(i, 1)
58 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
59 endfor
60
Bram Moolenaar69cbbec2019-08-17 14:10:56 +020061 " tab with 3rd character and linebreak set
62 set listchars-=tab:<=>
63 set listchars+=tab:<·>
64 set linebreak
65 let expected = [
66 \ '<······>aa<····>$',
67 \ '..bb<··>--$',
68 \ '...cccc>-$',
69 \ 'dd........ee--<>$',
70 \ '-$'
71 \ ]
72 redraw!
73 for i in range(1, 5)
74 call cursor(i, 1)
75 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
76 endfor
77 set nolinebreak
78 set listchars-=tab:<·>
79 set listchars+=tab:<=>
80
Bram Moolenaar83a52172019-01-16 22:41:54 +010081 set listchars-=trail:-
82 let expected = [
83 \ '<======>aa<====>$',
84 \ '..bb<==>..$',
85 \ '...cccc>.$',
86 \ 'dd........ee..<>$',
87 \ '.$'
88 \ ]
89 redraw!
90 for i in range(1, 5)
91 call cursor(i, 1)
92 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
93 endfor
94
95 set listchars-=tab:<=>
96 set listchars+=tab:>-
Bram Moolenaar209d3872017-11-16 21:52:51 +010097 set listchars+=trail:<
98 set nolist
99 normal ggdG
100 call append(0, [
101 \ ' fff ',
102 \ ' gg ',
103 \ ' h ',
104 \ 'iii ',
105 \ ])
106 let l = split(execute("%list"), "\n")
107 call assert_equal([
108 \ '..fff>--<<$',
109 \ '>-------gg>-----$',
110 \ '.....h>-$',
111 \ 'iii<<<<><<$', '$'], l)
112
Bram Moolenaar895d9662019-01-31 21:57:21 +0100113
114 " test nbsp
115 normal ggdG
116 set listchars=nbsp:X,trail:Y
117 set list
118 " Non-breaking space
119 let nbsp = nr2char(0xa0)
120 call append(0, [ ">".nbsp."<" ])
121
122 let expected = '>X< '
123
124 redraw!
125 call cursor(1, 1)
126 call assert_equal([expected], ScreenLines(1, virtcol('$')))
127
128 set listchars=nbsp:X
129 redraw!
130 call cursor(1, 1)
131 call assert_equal([expected], ScreenLines(1, virtcol('$')))
132
Bram Moolenaara5c6a0b2019-05-08 20:20:46 +0200133 " test extends
134 normal ggdG
135 set listchars=extends:Z
136 set nowrap
137 set nolist
138 call append(0, [ repeat('A', &columns + 1) ])
139
140 let expected = repeat('A', &columns)
141
142 redraw!
143 call cursor(1, 1)
144 call assert_equal([expected], ScreenLines(1, &columns))
145
146 set list
147 let expected = expected[:-2] . 'Z'
148 redraw!
149 call cursor(1, 1)
150 call assert_equal([expected], ScreenLines(1, &columns))
151
Bram Moolenaar209d3872017-11-16 21:52:51 +0100152 enew!
153 set listchars& ff&
154endfunc
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100155
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200156" Test that unicode listchars characters get properly inserted
157func Test_listchars_unicode()
158 enew!
159 let oldencoding=&encoding
160 set encoding=utf-8
161 set ff=unix
162
163 set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→
164 set list
165
166 let nbsp = nr2char(0xa0)
167 call append(0, [
168 \ "a\tb c".nbsp."d"
169 \ ])
170 let expected = [
171 \ 'a←↔↔↔↔↔→b␣c≠d⇔'
172 \ ]
173 redraw!
174 call cursor(1, 1)
175 call assert_equal(expected, ScreenLines(1, virtcol('$')))
176 let &encoding=oldencoding
177 enew!
178 set listchars& ff&
179endfunction
180
181" Tests that space characters following composing character won't get replaced
182" by listchars.
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100183func Test_listchars_composing()
184 enew!
185 let oldencoding=&encoding
186 set encoding=utf-8
187 set ff=unix
188 set list
189
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200190 set listchars=eol:$,space:_,nbsp:=
191
192 let nbsp1 = nr2char(0xa0)
193 let nbsp2 = nr2char(0x202f)
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100194 call append(0, [
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200195 \ " \u3099\t \u309A".nbsp1.nbsp1."\u0302".nbsp2.nbsp2."\u0302",
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100196 \ ])
197 let expected = [
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200198 \ "_ \u3099^I \u309A=".nbsp1."\u0302=".nbsp2."\u0302$"
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100199 \ ]
200 redraw!
201 call cursor(1, 1)
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200202 call assert_equal(expected, ScreenLines(1, virtcol('$')))
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100203 let &encoding=oldencoding
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200204 enew!
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100205 set listchars& ff&
206endfunction