blob: 5df50103962cf547ceb2189bbb455b9b3ae87c7c [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)
28 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
29 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
61 set listchars-=trail:-
62 let expected = [
63 \ '<======>aa<====>$',
64 \ '..bb<==>..$',
65 \ '...cccc>.$',
66 \ 'dd........ee..<>$',
67 \ '.$'
68 \ ]
69 redraw!
70 for i in range(1, 5)
71 call cursor(i, 1)
72 call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
73 endfor
74
75 set listchars-=tab:<=>
76 set listchars+=tab:>-
Bram Moolenaar209d3872017-11-16 21:52:51 +010077 set listchars+=trail:<
78 set nolist
79 normal ggdG
80 call append(0, [
81 \ ' fff ',
82 \ ' gg ',
83 \ ' h ',
84 \ 'iii ',
85 \ ])
86 let l = split(execute("%list"), "\n")
87 call assert_equal([
88 \ '..fff>--<<$',
89 \ '>-------gg>-----$',
90 \ '.....h>-$',
91 \ 'iii<<<<><<$', '$'], l)
92
Bram Moolenaar895d9662019-01-31 21:57:21 +010093
94 " test nbsp
95 normal ggdG
96 set listchars=nbsp:X,trail:Y
97 set list
98 " Non-breaking space
99 let nbsp = nr2char(0xa0)
100 call append(0, [ ">".nbsp."<" ])
101
102 let expected = '>X< '
103
104 redraw!
105 call cursor(1, 1)
106 call assert_equal([expected], ScreenLines(1, virtcol('$')))
107
108 set listchars=nbsp:X
109 redraw!
110 call cursor(1, 1)
111 call assert_equal([expected], ScreenLines(1, virtcol('$')))
112
Bram Moolenaara5c6a0b2019-05-08 20:20:46 +0200113 " test extends
114 normal ggdG
115 set listchars=extends:Z
116 set nowrap
117 set nolist
118 call append(0, [ repeat('A', &columns + 1) ])
119
120 let expected = repeat('A', &columns)
121
122 redraw!
123 call cursor(1, 1)
124 call assert_equal([expected], ScreenLines(1, &columns))
125
126 set list
127 let expected = expected[:-2] . 'Z'
128 redraw!
129 call cursor(1, 1)
130 call assert_equal([expected], ScreenLines(1, &columns))
131
Bram Moolenaar209d3872017-11-16 21:52:51 +0100132 enew!
133 set listchars& ff&
134endfunc
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100135
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200136" Test that unicode listchars characters get properly inserted
137func Test_listchars_unicode()
138 enew!
139 let oldencoding=&encoding
140 set encoding=utf-8
141 set ff=unix
142
143 set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→
144 set list
145
146 let nbsp = nr2char(0xa0)
147 call append(0, [
148 \ "a\tb c".nbsp."d"
149 \ ])
150 let expected = [
151 \ 'a←↔↔↔↔↔→b␣c≠d⇔'
152 \ ]
153 redraw!
154 call cursor(1, 1)
155 call assert_equal(expected, ScreenLines(1, virtcol('$')))
156 let &encoding=oldencoding
157 enew!
158 set listchars& ff&
159endfunction
160
161" Tests that space characters following composing character won't get replaced
162" by listchars.
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100163func Test_listchars_composing()
164 enew!
165 let oldencoding=&encoding
166 set encoding=utf-8
167 set ff=unix
168 set list
169
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200170 set listchars=eol:$,space:_,nbsp:=
171
172 let nbsp1 = nr2char(0xa0)
173 let nbsp2 = nr2char(0x202f)
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100174 call append(0, [
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200175 \ " \u3099\t \u309A".nbsp1.nbsp1."\u0302".nbsp2.nbsp2."\u0302",
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100176 \ ])
177 let expected = [
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200178 \ "_ \u3099^I \u309A=".nbsp1."\u0302=".nbsp2."\u0302$"
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100179 \ ]
180 redraw!
181 call cursor(1, 1)
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200182 call assert_equal(expected, ScreenLines(1, virtcol('$')))
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100183 let &encoding=oldencoding
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200184 enew!
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100185 set listchars& ff&
186endfunction