diff options
author | bfredl <bjorn.linse@gmail.com> | 2024-01-03 13:31:39 +0100 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2024-01-08 14:37:55 +0100 |
commit | aeb053907d2f27713764e345b00a6618e23220d8 (patch) | |
tree | dd881a61c8c515600b201ed2685ec6ae591f42f9 /test | |
parent | fbe40caa7cc1786dc58210a82901307417ba0654 (diff) | |
download | rneovim-aeb053907d2f27713764e345b00a6618e23220d8.tar.gz rneovim-aeb053907d2f27713764e345b00a6618e23220d8.tar.bz2 rneovim-aeb053907d2f27713764e345b00a6618e23220d8.zip |
refactor(options): use schar_T representation for fillchars and listchars
A bit big, but practically it was a lot simpler to change over all
fillchars and all listchars at once, to not need to maintain two
parallel implementations.
This is mostly an internal refactor, but it also removes an arbitrary
limitation: that 'fillchars' and 'listchars' values can only be
single-codepoint characters. Now any character which fits into a single
screen cell can be used.
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/options/chars_spec.lua | 35 | ||||
-rw-r--r-- | test/unit/statusline_spec.lua | 24 |
2 files changed, 48 insertions, 11 deletions
diff --git a/test/functional/options/chars_spec.lua b/test/functional/options/chars_spec.lua index 3e43fbbecd..d23dc2ed88 100644 --- a/test/functional/options/chars_spec.lua +++ b/test/functional/options/chars_spec.lua @@ -6,6 +6,7 @@ local eq = helpers.eq local exc_exec = helpers.exc_exec local insert = helpers.insert local feed = helpers.feed +local meths = helpers.meths describe("'fillchars'", function() local screen @@ -53,10 +54,18 @@ describe("'fillchars'", function() ]]) end) + it('supports composing multibyte char', function() + command('set fillchars=eob:å̲') + screen:expect([[ + ^ | + å̲ |*3 + | + ]]) + 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) @@ -178,4 +187,28 @@ describe("'listchars'", function() | ]]) end) + + it('supports composing chars', function() + screen:set_default_attr_ids { + [1] = { foreground = Screen.colors.Blue1, bold = true }, + } + feed('i<tab><tab><tab>x<esc>') + command('set list laststatus=0') + -- tricky: the tab value forms three separate one-cell chars, + -- thus it should be accepted despite being a mess. + command('set listchars=tab:d̞̄̃̒̉̎ò́̌̌̂̐l̞̀̄̆̌̚,eol:å̲') + screen:expect([[ + {1:d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚}^x{1:å̲} | + {1:~ }|*3 + | + ]]) + + meths._invalidate_glyph_cache() + screen:_reset() + screen:expect([[ + {1:d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚d̞̄̃̒̉̎ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐ò́̌̌̂̐l̞̀̄̆̌̚}^x{1:å̲} | + {1:~ }|*3 + | + ]]) + end) end) diff --git a/test/unit/statusline_spec.lua b/test/unit/statusline_spec.lua index ffcfec18ef..f1294e6b5a 100644 --- a/test/unit/statusline_spec.lua +++ b/test/unit/statusline_spec.lua @@ -9,6 +9,7 @@ local NULL = helpers.NULL local buffer = helpers.cimport('./src/nvim/buffer.h') local globals = helpers.cimport('./src/nvim/globals.h') local stl = helpers.cimport('./src/nvim/statusline.h') +local grid = helpers.cimport('./src/nvim/grid.h') describe('build_stl_str_hl', function() local buffer_byte_size = 100 @@ -25,8 +26,11 @@ describe('build_stl_str_hl', function() output_buffer = to_cstr(string.rep(' ', buffer_byte_size)) local pat = arg.pat or '' - local fillchar = arg.fillchar or (' '):byte() + local fillchar = arg.fillchar or ' ' local maximum_cell_count = arg.maximum_cell_count or buffer_byte_size + if type(fillchar) == type('') then + fillchar = grid.schar_from_str(fillchar) + end return stl.build_stl_str_hl( globals.curwin, @@ -61,7 +65,7 @@ describe('build_stl_str_hl', function() -- so we either fill in option with arg or an empty dictionary local option = arg or {} - local fillchar = option.fillchar or (' '):byte() + local fillchar = option.fillchar or ' ' local expected_cell_count = option.expected_cell_count or statusline_cell_count local expected_byte_length = option.expected_byte_length or #expected_stl @@ -110,35 +114,35 @@ describe('build_stl_str_hl', function() 10, 'abcde%=', 'abcde!!!!!', - { fillchar = ('!'):byte() } + { fillchar = '!' } ) statusline_test( 'should handle `~` as a fillchar', 10, '%=abcde', '~~~~~abcde', - { fillchar = ('~'):byte() } + { fillchar = '~' } ) statusline_test( 'should put fillchar `!` in between text', 10, 'abc%=def', 'abc!!!!def', - { fillchar = ('!'):byte() } + { fillchar = '!' } ) statusline_test( 'should put fillchar `~` in between text', 10, 'abc%=def', 'abc~~~~def', - { fillchar = ('~'):byte() } + { fillchar = '~' } ) statusline_test( 'should put fillchar `━` in between text', 10, 'abc%=def', 'abc━━━━def', - { fillchar = 0x2501 } + { fillchar = '━' } ) statusline_test( 'should handle zero-fillchar as a space', @@ -249,7 +253,7 @@ describe('build_stl_str_hl', function() expected_stl:gsub('%~', ' '), arg ) - arg.fillchar = ('!'):byte() + arg.fillchar = '!' statusline_test( description .. ' with fillchar `!`', statusline_cell_count, @@ -257,7 +261,7 @@ describe('build_stl_str_hl', function() expected_stl:gsub('%~', '!'), arg ) - arg.fillchar = 0x2501 + arg.fillchar = '━' statusline_test( description .. ' with fillchar `━`', statusline_cell_count, @@ -456,7 +460,7 @@ describe('build_stl_str_hl', function() 10, 'Ą%=mid%=end', 'Ą@mid@@end', - { fillchar = ('@'):byte() } + { fillchar = '@' } ) -- escaping % testing |