diff options
Diffstat (limited to 'test/functional/api/highlight_spec.lua')
-rw-r--r-- | test/functional/api/highlight_spec.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 5297c6454e..a9d4c72d31 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -4,6 +4,9 @@ local Screen = require('test.functional.ui.screen') local eq, eval = helpers.eq, helpers.eval local command = helpers.command local meths = helpers.meths +local funcs = helpers.funcs +local pcall_err = helpers.pcall_err +local ok = helpers.ok describe('API: highlight',function() local expected_rgb = { @@ -67,6 +70,22 @@ describe('API: highlight',function() eq(false, err) eq('Invalid highlight id: -1', string.match(emsg, 'Invalid.*')) + + -- Test highlight group without ctermbg value. + command('hi Normal ctermfg=red ctermbg=yellow') + command('hi NewConstant ctermfg=green guifg=white guibg=blue') + hl_id = eval("hlID('NewConstant')") + eq({foreground = 10,}, meths.get_hl_by_id(hl_id, false)) + + -- Test highlight group without ctermfg value. + command('hi clear NewConstant') + command('hi NewConstant ctermbg=Magenta guifg=white guibg=blue') + eq({background = 13,}, meths.get_hl_by_id(hl_id, false)) + + -- Test highlight group with ctermfg and ctermbg values. + command('hi clear NewConstant') + command('hi NewConstant ctermfg=green ctermbg=Magenta guifg=white guibg=blue') + eq({foreground = 10, background = 13,}, meths.get_hl_by_id(hl_id, false)) end) it("nvim_get_hl_by_name", function() @@ -110,4 +129,20 @@ describe('API: highlight',function() meths.get_hl_by_name('cursorline', 0)); end) + + it('nvim_get_hl_id_by_name', function() + -- precondition: use a hl group that does not yet exist + eq('Invalid highlight name: Shrubbery', pcall_err(meths.get_hl_by_name, "Shrubbery", true)) + eq(0, funcs.hlID("Shrubbery")) + + local hl_id = meths.get_hl_id_by_name("Shrubbery") + ok(hl_id > 0) + eq(hl_id, funcs.hlID("Shrubbery")) + + command('hi Shrubbery guifg=#888888 guibg=#888888') + eq({foreground=tonumber("0x888888"), background=tonumber("0x888888")}, + meths.get_hl_by_id(hl_id, true)) + eq({foreground=tonumber("0x888888"), background=tonumber("0x888888")}, + meths.get_hl_by_name("Shrubbery", true)) + end) end) |