chars_spec.lua (7889B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 local Screen = require('test.functional.ui.screen') 4 5 local clear, command = n.clear, n.command 6 local pcall_err = t.pcall_err 7 local eval = n.eval 8 local eq = t.eq 9 local insert = n.insert 10 local feed = n.feed 11 local api = n.api 12 13 describe("'fillchars'", function() 14 local screen 15 16 before_each(function() 17 clear() 18 screen = Screen.new(25, 5) 19 end) 20 21 describe('"eob" flag', function() 22 it("uses '~' by default", function() 23 eq('', eval('&fillchars')) 24 screen:expect([[ 25 ^ | 26 {1:~ }|*3 27 | 28 ]]) 29 end) 30 31 it('supports whitespace', function() 32 screen:expect([[ 33 ^ | 34 {1:~ }|*3 35 | 36 ]]) 37 command('set fillchars=eob:\\ ') 38 screen:expect([[ 39 ^ | 40 {1: }|*3 41 | 42 ]]) 43 end) 44 45 it('supports multibyte char', function() 46 command('set fillchars=eob:ñ') 47 screen:expect([[ 48 ^ | 49 {1:ñ }|*3 50 | 51 ]]) 52 end) 53 54 it('supports composing multibyte char', function() 55 command('set fillchars=eob:å̲') 56 screen:expect([[ 57 ^ | 58 {1:å̲ }|*3 59 | 60 ]]) 61 end) 62 63 it('handles invalid values', function() 64 eq( 65 'Vim(set):E1511: Wrong number of characters for field "eob": fillchars=eob:', 66 pcall_err(command, 'set fillchars=eob:') -- empty string 67 ) 68 eq( 69 'Vim(set):E1512: Wrong character width for field "eob": fillchars=eob:馬', 70 pcall_err(command, 'set fillchars=eob:馬') -- doublewidth char 71 ) 72 eq( 73 'Vim(set):E1511: Wrong number of characters for field "eob": fillchars=eob:xy', 74 pcall_err(command, 'set fillchars=eob:xy') -- two ascii chars 75 ) 76 eq( 77 'Vim(set):E1512: Wrong character width for field "eob": fillchars=eob:<ff>', 78 pcall_err(command, 'set fillchars=eob:\255') -- invalid UTF-8 79 ) 80 end) 81 end) 82 83 it('"diff" flag', function() 84 screen:try_resize(45, 8) 85 screen:set_default_attr_ids({ 86 [1] = { background = Screen.colors.Grey, foreground = Screen.colors.DarkBlue }, 87 [2] = { background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1 }, 88 [3] = { background = Screen.colors.LightBlue }, 89 [4] = { reverse = true }, 90 [5] = { reverse = true, bold = true }, 91 }) 92 command('set fillchars=diff:…') 93 insert('a\nb\nc\nd\ne') 94 command('vnew') 95 insert('a\nd\ne\nf') 96 command('windo diffthis') 97 screen:expect([[ 98 {1: }a │{1: }a | 99 {1: }{2:……………………………………………………}│{1: }{3:b }| 100 {1: }{2:……………………………………………………}│{1: }{3:c }| 101 {1: }d │{1: }d | 102 {1: }e │{1: }^e | 103 {1: }{3:f }│{1: }{2:……………………………………………………}| 104 {4:[No Name] [+] }{5:[No Name] [+] }| 105 | 106 ]]) 107 end) 108 109 it('has global value', function() 110 screen:try_resize(50, 5) 111 insert('foo\nbar') 112 command('set laststatus=0') 113 command('1,2fold') 114 command('vsplit') 115 command('set fillchars=fold:x') 116 screen:expect([[ 117 {13:^+-- 2 lines: fooxxxxxxxx}│{13:+-- 2 lines: fooxxxxxxx}| 118 {1:~ }│{1:~ }|*3 119 | 120 ]]) 121 end) 122 123 it('has window-local value', function() 124 screen:try_resize(50, 5) 125 insert('foo\nbar') 126 command('set laststatus=0') 127 command('1,2fold') 128 command('vsplit') 129 command('setl fillchars=fold:x') 130 screen:expect([[ 131 {13:^+-- 2 lines: fooxxxxxxxx}│{13:+-- 2 lines: foo·······}| 132 {1:~ }│{1:~ }|*3 133 | 134 ]]) 135 end) 136 137 it('using :set clears window-local value', function() 138 screen:try_resize(50, 5) 139 insert('foo\nbar') 140 command('set laststatus=0') 141 command('setl fillchars=fold:x') 142 command('1,2fold') 143 command('vsplit') 144 command('set fillchars&') 145 screen:expect([[ 146 {13:^+-- 2 lines: foo········}│{13:+-- 2 lines: fooxxxxxxx}| 147 {1:~ }│{1:~ }|*3 148 | 149 ]]) 150 end) 151 end) 152 153 describe("'listchars'", function() 154 local screen 155 156 before_each(function() 157 clear() 158 screen = Screen.new(50, 5) 159 end) 160 161 it('has global value', function() 162 feed('i<tab><tab><tab><esc>') 163 command('set list laststatus=0') 164 command('vsplit') 165 command('set listchars=tab:<->') 166 screen:expect([[ 167 {1:<------><------>^<------>} │{1:<------><------><------>}| 168 {1:~ }│{1:~ }|*3 169 | 170 ]]) 171 end) 172 173 it('has window-local value', function() 174 feed('i<tab><tab><tab><esc>') 175 command('set list laststatus=0') 176 command('setl listchars=tab:<->') 177 command('vsplit') 178 command('setl listchars<') 179 screen:expect([[ 180 {1:> > ^> } │{1:<------><------><------>}| 181 {1:~ }│{1:~ }|*3 182 | 183 ]]) 184 end) 185 186 it('using :set clears window-local value', function() 187 feed('i<tab><tab><tab><esc>') 188 command('set list laststatus=0') 189 command('setl listchars=tab:<->') 190 command('vsplit') 191 command('set listchars=tab:>-,eol:$') 192 screen:expect([[ 193 {1:>------->-------^>-------$}│{1:<------><------><------>}| 194 {1:~ }│{1:~ }|*3 195 | 196 ]]) 197 end) 198 199 it('supports composing chars', function() 200 screen:set_default_attr_ids { 201 [1] = { foreground = Screen.colors.Blue1, bold = true }, 202 } 203 feed('i<tab><tab><tab>x<esc>') 204 command('set list laststatus=0') 205 -- tricky: the tab value forms three separate one-cell chars, 206 -- thus it should be accepted despite being a mess. 207 command('set listchars=tab:d̞̄̃̒̉̎ò́̌̌̂̐l̞̀̄̆̌̚,eol:å̲') 208 screen:expect([[ 209 {1:d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚}^x{1:å̲} | 210 {1:~ }|*3 211 | 212 ]]) 213 214 api.nvim__invalidate_glyph_cache() 215 screen:_reset() 216 screen:expect([[ 217 {1:d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚}^x{1:å̲} | 218 {1:~ }|*3 219 | 220 ]]) 221 end) 222 end)