aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/highlight_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-10-08 20:23:11 +0200
committerJustin M. Keyes <justinkz@gmail.com>2017-10-08 21:17:20 +0200
commit52517321d1859c31fef14aa75d784615693fcecb (patch)
tree09852c72ed400db8396ba268ed480187fa48d91b /test/functional/api/highlight_spec.lua
parent04187a1c74e79abfb46c0b9c1e522b61f1cedcae (diff)
downloadrneovim-52517321d1859c31fef14aa75d784615693fcecb.tar.gz
rneovim-52517321d1859c31fef14aa75d784615693fcecb.tar.bz2
rneovim-52517321d1859c31fef14aa75d784615693fcecb.zip
test: nvim_get_hl_by_name/by_id #7082
- test all properties - test failure modes
Diffstat (limited to 'test/functional/api/highlight_spec.lua')
-rw-r--r--test/functional/api/highlight_spec.lua77
1 files changed, 62 insertions, 15 deletions
diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua
index c482128a31..2297a0760f 100644
--- a/test/functional/api/highlight_spec.lua
+++ b/test/functional/api/highlight_spec.lua
@@ -6,15 +6,26 @@ local command = helpers.command
local meths = helpers.meths
describe('highlight api',function()
- local expected_rgb = { background = Screen.colors.Yellow,
- foreground = Screen.colors.Red,
- special = Screen.colors.Blue,
- bold = true,
- }
-
- local expected_cterm = { background = 10,
- underline = true,
- }
+ local expected_rgb = {
+ background = Screen.colors.Yellow,
+ foreground = Screen.colors.Red,
+ special = Screen.colors.Blue,
+ bold = true,
+ }
+ local expected_cterm = {
+ background = 10,
+ underline = true,
+ }
+ local expected_rgb2 = {
+ background = Screen.colors.Yellow,
+ foreground = Screen.colors.Red,
+ special = Screen.colors.Blue,
+ bold = true,
+ italic = true,
+ reverse = true,
+ undercurl = true,
+ underline = true,
+ }
before_each(function()
clear()
@@ -26,31 +37,67 @@ describe('highlight api',function()
eq(expected_cterm, nvim("get_hl_by_id", hl_id, false))
hl_id = eval("hlID('NewHighlight')")
+ -- Test valid id.
eq(expected_rgb, nvim("get_hl_by_id", hl_id, true))
- local expected_error = 'Invalid highlight id'
- -- Assume there is no hl id 30000.
+ -- Test invalid id.
local err, emsg = pcall(meths.get_hl_by_id, 30000, false)
eq(false, err)
- eq(expected_error, string.match(emsg, expected_error))
+ eq('Invalid highlight id: 30000', string.match(emsg, 'Invalid.*'))
+
+ -- Test all highlight properties.
+ command('hi NewHighlight gui=underline,bold,undercurl,italic,reverse')
+ eq(expected_rgb2, 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, expecting Integer',
+ string.match(emsg, 'Wrong.*'))
+
+ -- 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.*'))
+
+ -- 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.*'))
end)
it("nvim_get_hl_by_name", function()
local expected_normal = { background = Screen.colors.Yellow,
foreground = Screen.colors.Red }
- -- Test "Normal" hl defaults.
+ -- Test `Normal` default values.
eq({}, nvim("get_hl_by_name", 'Normal', true))
eq(expected_cterm, nvim("get_hl_by_name", 'NewHighlight', false))
eq(expected_rgb, nvim("get_hl_by_name", 'NewHighlight', true))
+ -- Test `Normal` modified values.
command('hi Normal guifg=red guibg=yellow')
eq(expected_normal, nvim("get_hl_by_name", 'Normal', true))
- local expected_error = 'Invalid highlight name'
+ -- Test invalid name.
local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight', false)
eq(false, err)
- eq(expected_error, string.match(emsg, expected_error))
+ eq('Invalid highlight name: unknown_highlight',
+ string.match(emsg, 'Invalid.*'))
+
+ -- Test nil argument.
+ err, emsg = pcall(meths.get_hl_by_name , { nil }, false)
+ eq(false, err)
+ eq('Wrong type for argument 1, expecting String',
+ string.match(emsg, 'Wrong.*'))
+
+ -- Test empty string argument.
+ err, emsg = pcall(meths.get_hl_by_name , '', false)
+ eq(false, err)
+ eq('Invalid highlight name: ',
+ string.match(emsg, 'Invalid.*'))
end)
end)