aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/highlight_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2023-02-14 08:07:38 -0500
committerGitHub <noreply@github.com>2023-02-14 05:07:38 -0800
commitff3d04b75b4a9314815c37d53ebc4d035a043335 (patch)
tree435a61efa5c036060b72aa945166e76bee34d7de /test/functional/api/highlight_spec.lua
parent3a6a7add57d2ac141f474b54659bbbf596b76059 (diff)
downloadrneovim-ff3d04b75b4a9314815c37d53ebc4d035a043335.tar.gz
rneovim-ff3d04b75b4a9314815c37d53ebc4d035a043335.tar.bz2
rneovim-ff3d04b75b4a9314815c37d53ebc4d035a043335.zip
refactor(api): VALIDATE macros #22256
- VALIDATE() takes a format string - deduplicate check_string_array - VALIDATE_RANGE - validate UI args
Diffstat (limited to 'test/functional/api/highlight_spec.lua')
-rw-r--r--test/functional/api/highlight_spec.lua67
1 files changed, 29 insertions, 38 deletions
diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua
index 7f044977cb..73551de42e 100644
--- a/test/functional/api/highlight_spec.lua
+++ b/test/functional/api/highlight_spec.lua
@@ -57,9 +57,7 @@ describe('API: highlight',function()
eq(expected_rgb, nvim("get_hl_by_id", hl_id, true))
-- Test invalid id.
- local err, emsg = pcall(meths.get_hl_by_id, 30000, false)
- eq(false, err)
- eq('Invalid highlight id: 30000', string.match(emsg, 'Invalid.*'))
+ eq('Invalid highlight id: 30000', pcall_err(meths.get_hl_by_id, 30000, false))
-- Test all highlight properties.
command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine')
@@ -70,22 +68,14 @@ describe('API: highlight',function()
eq(expected_undercurl, nvim("get_hl_by_id", hl_id, true))
-- Test nil argument.
- err, emsg = pcall(meths.get_hl_by_id, { nil }, false)
- eq(false, err)
eq('Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer',
- string.match(emsg, 'Wrong.*'))
+ pcall_err(meths.get_hl_by_id, { nil }, false))
-- Test 0 argument.
- err, emsg = pcall(meths.get_hl_by_id, 0, false)
- eq(false, err)
- eq('Invalid highlight id: 0',
- string.match(emsg, 'Invalid.*'))
+ eq('Invalid highlight id: 0', pcall_err(meths.get_hl_by_id, 0, false))
-- Test -1 argument.
- err, emsg = pcall(meths.get_hl_by_id, -1, false)
- eq(false, err)
- eq('Invalid highlight id: -1',
- string.match(emsg, 'Invalid.*'))
+ eq('Invalid highlight id: -1', pcall_err(meths.get_hl_by_id, -1, false))
-- Test highlight group without ctermbg value.
command('hi Normal ctermfg=red ctermbg=yellow')
@@ -119,22 +109,16 @@ describe('API: highlight',function()
eq(expected_normal, nvim("get_hl_by_name", 'Normal', true))
-- Test invalid name.
- local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight', false)
- eq(false, err)
- eq('Invalid highlight name: unknown_highlight',
- string.match(emsg, 'Invalid.*'))
+ eq("Invalid highlight name: 'unknown_highlight'",
+ pcall_err(meths.get_hl_by_name , 'unknown_highlight', false))
-- Test nil argument.
- err, emsg = pcall(meths.get_hl_by_name , { nil }, false)
- eq(false, err)
eq('Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String',
- string.match(emsg, 'Wrong.*'))
+ pcall_err(meths.get_hl_by_name , { nil }, false))
-- Test empty string argument.
- err, emsg = pcall(meths.get_hl_by_name , '', false)
- eq(false, err)
- eq('Invalid highlight name: ',
- string.match(emsg, 'Invalid.*'))
+ eq('Invalid highlight name',
+ pcall_err(meths.get_hl_by_name , '', false))
-- Test "standout" attribute. #8054
eq({ underline = true, },
@@ -155,7 +139,7 @@ describe('API: highlight',function()
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("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")
@@ -253,25 +237,32 @@ describe("API: set highlight", function()
before_each(clear)
- it ("can set gui highlight", function()
+ it('validation', function()
+ eq("Invalid 'blend': out of range",
+ pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='#FF00FF', blend=999}))
+ eq("Invalid blend: expected Integer, got Array",
+ pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='#FF00FF', blend={}}))
+ end)
+
+ it("can set gui highlight", function()
local ns = get_ns()
meths.set_hl(ns, 'Test_hl', highlight1)
eq(highlight1, meths.get_hl_by_name('Test_hl', true))
end)
- it ("can set cterm highlight", function()
+ it("can set cterm highlight", function()
local ns = get_ns()
meths.set_hl(ns, 'Test_hl', highlight2_config)
eq(highlight2_result, meths.get_hl_by_name('Test_hl', false))
end)
- it ("can set empty cterm attr", function()
+ it("can set empty cterm attr", function()
local ns = get_ns()
meths.set_hl(ns, 'Test_hl', { cterm = {} })
eq({}, meths.get_hl_by_name('Test_hl', false))
end)
- it ("cterm attr defaults to gui attr", function()
+ it("cterm attr defaults to gui attr", function()
local ns = get_ns()
meths.set_hl(ns, 'Test_hl', highlight1)
eq({
@@ -280,14 +271,14 @@ describe("API: set highlight", function()
}, meths.get_hl_by_name('Test_hl', false))
end)
- it ("can overwrite attr for cterm", function()
+ it("can overwrite attr for cterm", function()
local ns = get_ns()
meths.set_hl(ns, 'Test_hl', highlight3_config)
eq(highlight3_result_gui, meths.get_hl_by_name('Test_hl', true))
eq(highlight3_result_cterm, meths.get_hl_by_name('Test_hl', false))
end)
- it ("can set a highlight in the global namespace", function()
+ it("can set a highlight in the global namespace", function()
meths.set_hl(0, 'Test_hl', highlight2_config)
eq('Test_hl xxx cterm=underline,reverse ctermfg=8 ctermbg=15 gui=underline,reverse',
exec_capture('highlight Test_hl'))
@@ -307,7 +298,7 @@ describe("API: set highlight", function()
exec_capture('highlight Test_hl3'))
end)
- it ("can modify a highlight in the global namespace", function()
+ it("can modify a highlight in the global namespace", function()
meths.set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue'})
eq('Test_hl3 xxx guifg=Blue guibg=Red',
exec_capture('highlight Test_hl3'))
@@ -328,17 +319,17 @@ describe("API: set highlight", function()
eq('Test_hl3 xxx ctermbg=9',
exec_capture('highlight Test_hl3'))
- eq("'redd' is not a valid color",
+ eq("Invalid highlight color: 'redd'",
pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='redd'}))
- eq("'bleu' is not a valid color",
+ eq("Invalid highlight color: 'bleu'",
pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='bleu'}))
meths.set_hl(0, 'Test_hl3', {fg='#FF00FF'})
eq('Test_hl3 xxx guifg=#ff00ff',
exec_capture('highlight Test_hl3'))
- eq("'#FF00FF' is not a valid color",
+ eq("Invalid highlight color: '#FF00FF'",
pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='#FF00FF'}))
for _, fg_val in ipairs{ nil, 'NONE', 'nOnE', '', -1 } do
@@ -353,14 +344,14 @@ describe("API: set highlight", function()
end)
- it ("correctly sets 'Normal' internal properties", function()
+ it("correctly sets 'Normal' internal properties", function()
-- Normal has some special handling internally. #18024
meths.set_hl(0, 'Normal', {fg='#000083', bg='#0000F3'})
eq({foreground = 131, background = 243}, nvim("get_hl_by_name", 'Normal', true))
end)
it('does not segfault on invalid group name #20009', function()
- eq('Invalid highlight name: foo bar', pcall_err(meths.set_hl, 0, 'foo bar', {bold = true}))
+ eq("Invalid highlight name: 'foo bar'", pcall_err(meths.set_hl, 0, 'foo bar', {bold = true}))
assert_alive()
end)
end)