robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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