blob: 3eef75d28935629e98f49848afe0fade13624823 [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 Moolenaar209d3872017-11-16 21:52:51 +0100113 enew!
114 set listchars& ff&
115endfunc
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100116
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200117" Test that unicode listchars characters get properly inserted
118func Test_listchars_unicode()
119 enew!
120 let oldencoding=&encoding
121 set encoding=utf-8
122 set ff=unix
123
124 set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→
125 set list
126
127 let nbsp = nr2char(0xa0)
128 call append(0, [
129 \ "a\tb c".nbsp."d"
130 \ ])
131 let expected = [
132 \ 'a←↔↔↔↔↔→b␣c≠d⇔'
133 \ ]
134 redraw!
135 call cursor(1, 1)
136 call assert_equal(expected, ScreenLines(1, virtcol('$')))
137 let &encoding=oldencoding
138 enew!
139 set listchars& ff&
140endfunction
141
142" Tests that space characters following composing character won't get replaced
143" by listchars.
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100144func Test_listchars_composing()
145 enew!
146 let oldencoding=&encoding
147 set encoding=utf-8
148 set ff=unix
149 set list
150
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200151 set listchars=eol:$,space:_,nbsp:=
152
153 let nbsp1 = nr2char(0xa0)
154 let nbsp2 = nr2char(0x202f)
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100155 call append(0, [
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200156 \ " \u3099\t \u309A".nbsp1.nbsp1."\u0302".nbsp2.nbsp2."\u0302",
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100157 \ ])
158 let expected = [
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200159 \ "_ \u3099^I \u309A=".nbsp1."\u0302=".nbsp2."\u0302$"
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100160 \ ]
161 redraw!
162 call cursor(1, 1)
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200163 call assert_equal(expected, ScreenLines(1, virtcol('$')))
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100164 let &encoding=oldencoding
Bram Moolenaare5e4e222019-04-04 13:28:45 +0200165 enew!
Bram Moolenaar5f8069b2019-03-30 15:34:47 +0100166 set listchars& ff&
167endfunction