fillchars: make checks more strict and improve tests

This commit is contained in:
Björn Linse 2018-06-13 18:21:25 +02:00
parent a7bb63c55d
commit 5442f0b622
3 changed files with 37 additions and 11 deletions

View File

@ -180,7 +180,8 @@ Options:
'cpoptions' flags: |cpo-_|
'display' flag `msgsep` to minimize scrolling when showing messages
'guicursor' works in the terminal
'fillchars' flag `msgsep` (see 'display' above)
'fillchars' flags: `msgsep` (see 'display' above)
and `eob` for |EndOfBuffer| marker
'inccommand' shows interactive results for |:substitute|-like commands
'scrollback'
'statusline' supports unlimited alignment sections

View File

@ -3438,16 +3438,20 @@ static char_u *set_chars_option(char_u **varp)
&& p[len] == ':'
&& p[len + 1] != NUL) {
s = p + len + 1;
c1 = mb_ptr2char_adv((const char_u **)&s);
if (mb_char2cells(c1) > 1) {
// TODO(bfredl): use schar_T representation and utfc_ptr2len
int c1len = utf_ptr2len(s);
c1 = mb_cptr2char_adv((const char_u **)&s);
if (mb_char2cells(c1) > 1 || (c1len == 1 && c1 > 127)) {
continue;
}
if (tab[i].cp == &lcs_tab2) {
if (*s == NUL) {
continue;
}
c2 = mb_ptr2char_adv((const char_u **)&s);
if (mb_char2cells(c2) > 1) {
int c2len = utf_ptr2len(s);
c2 = mb_cptr2char_adv((const char_u **)&s);
if (mb_char2cells(c2) > 1 || (c2len == 1 && c2 > 127)) {
continue;
}
}

View File

@ -1,6 +1,9 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear, execute = helpers.clear, helpers.execute
local clear, command = helpers.clear, helpers.command
local eval = helpers.eval
local eq = helpers.eq
local exc_exec = helpers.exc_exec
describe("'fillchars'", function()
local screen
@ -15,8 +18,15 @@ describe("'fillchars'", function()
screen:detach()
end)
local function shouldfail(val,errval)
errval = errval or val
eq('Vim(set):E474: Invalid argument: fillchars='..errval,
exc_exec('set fillchars='..val))
end
describe('"eob" flag', function()
it('renders empty lines at the end of the buffer with eob', function()
it("uses '~' by default", function()
eq('', eval('&fillchars'))
screen:expect([[
^ |
~ |
@ -24,22 +34,33 @@ describe("'fillchars'", function()
~ |
|
]])
execute('set fillchars+=eob:\\ ')
end)
it('supports whitespace', function()
command('set fillchars=eob:\\ ')
screen:expect([[
^ |
|
|
|
:set fillchars+=eob:\ |
|
]])
execute('set fillchars+=eob:ñ')
end)
it('supports multibyte char', function()
command('set fillchars=eob:ñ')
screen:expect([[
^ |
ñ |
ñ |
ñ |
:set fillchars+=eob:ñ |
|
]])
end)
it('handles invalid values', function()
shouldfail('eob:') -- empty string
shouldfail('eob:馬') -- doublewidth char
shouldfail('eob:å̲') -- composing chars
shouldfail('eob:xy') -- two ascii chars
shouldfail('eob:\255', 'eob:<ff>') -- invalid UTF-8
end)
end)
end)