From ba7277cfb4e2556f246446d06b53f3427f28130f Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Wed, 26 Jul 2017 23:28:26 +0200 Subject: Adds nvim_get_hl_by_name/by_id ...in order to retrieve highlights. Added test/functional/api/highlight_spec.lua HL_NORMAL is not really a good name, since it's more like an empty attribute than the normal's one. If one pays attention, syn_cterm_attr2entry is never called with attr=0 because it's always special cased before. I suggest in subsequent PRs we remove the ATTR_OFF and just insert an EMPTY ATTR/RESET_ATTR/UNINITIALIZED for id 0. --- test/functional/api/highlight_spec.lua | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/functional/api/highlight_spec.lua (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua new file mode 100644 index 0000000000..1aacfaed03 --- /dev/null +++ b/test/functional/api/highlight_spec.lua @@ -0,0 +1,54 @@ + +local helpers = require('test.functional.helpers')(after_each) +local clear, nvim = helpers.clear, helpers.nvim +local Screen = require('test.functional.ui.screen') +local eq, eval = helpers.eq, helpers.eval +local command = helpers.command +local ok = helpers.ok +local meths = helpers.meths + + +describe('highlight api', function() + + before_each(function() + clear('--cmd', 'set termguicolors') + end) + + it("nvim_get_hl_by_id", function() + local expected_hl = { background = Screen.colors.Yellow, + foreground = Screen.colors.Red, + special = Screen.colors.Blue + } + + command('hi NewHighlight guifg=red guibg=yellow guisp=blue') + + local hl_id = eval("hlID('NewHighlight')") + eq(expected_hl, nvim("get_hl_by_id", hl_id)) + + -- assume there is no hl with 30000 + local err, emsg = pcall(meths.get_hl_by_id, 30000) + eq(false, err) + ok(string.find(emsg, 'Invalid highlight id') ~= nil) + end) + + it("nvim_get_hl_by_name", function() + local expected_hl = { background = Screen.colors.Yellow, + foreground = Screen.colors.Red } + + -- test "Normal" hl defaults + eq({}, nvim("get_hl_by_name", 'Normal')) + + command('hi NewHighlight guifg=red guibg=yellow') + eq(expected_hl, nvim("get_hl_by_name", 'NewHighlight')) + + command('hi Normal guifg=red guibg=yellow') + eq(expected_hl, nvim("get_hl_by_name", 'Normal')) + local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight') + eq(false, err) + ok(string.find(emsg, 'Invalid highlight name') ~= nil) + end) + + + +end) + -- cgit From e3a2cca3878f44252eccdc1918cc8854145de860 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 27 Aug 2017 00:33:36 +0200 Subject: Increased test coverage for RGB and cterm --- test/functional/api/highlight_spec.lua | 42 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 1aacfaed03..a5d3871d13 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -8,47 +8,53 @@ local ok = helpers.ok local meths = helpers.meths -describe('highlight api', function() +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, + } before_each(function() - clear('--cmd', 'set termguicolors') + clear() + command("hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold") end) it("nvim_get_hl_by_id", function() - local expected_hl = { background = Screen.colors.Yellow, - foreground = Screen.colors.Red, - special = Screen.colors.Blue - } + local hl_id = eval("hlID('NewHighlight')") - command('hi NewHighlight guifg=red guibg=yellow guisp=blue') + eq(expected_cterm, nvim("get_hl_by_id", hl_id)) - local hl_id = eval("hlID('NewHighlight')") - eq(expected_hl, nvim("get_hl_by_id", hl_id)) + command('set termguicolors') + hl_id = eval("hlID('NewHighlight')") + eq(expected_rgb, nvim("get_hl_by_id", hl_id)) - -- assume there is no hl with 30000 + -- assume there is no hl with id 30000 local err, emsg = pcall(meths.get_hl_by_id, 30000) eq(false, err) ok(string.find(emsg, 'Invalid highlight id') ~= nil) end) it("nvim_get_hl_by_name", function() - local expected_hl = { background = Screen.colors.Yellow, + local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red } -- test "Normal" hl defaults eq({}, nvim("get_hl_by_name", 'Normal')) - command('hi NewHighlight guifg=red guibg=yellow') - eq(expected_hl, nvim("get_hl_by_name", 'NewHighlight')) + eq(expected_cterm, nvim("get_hl_by_name", 'NewHighlight')) + command('set termguicolors') + eq(expected_rgb, nvim("get_hl_by_name", 'NewHighlight')) command('hi Normal guifg=red guibg=yellow') - eq(expected_hl, nvim("get_hl_by_name", 'Normal')) + eq(expected_normal, nvim("get_hl_by_name", 'Normal')) + local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight') eq(false, err) ok(string.find(emsg, 'Invalid highlight name') ~= nil) end) - - - end) - -- cgit From 3a006486397d611234abd9b429bce0b44d6b7747 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 3 Sep 2017 05:25:57 +0200 Subject: Changed prototypes to accept a boolean "rgb" --- test/functional/api/highlight_spec.lua | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a5d3871d13..4082b0daf9 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -27,14 +27,13 @@ describe('highlight api',function() it("nvim_get_hl_by_id", function() local hl_id = eval("hlID('NewHighlight')") - eq(expected_cterm, nvim("get_hl_by_id", hl_id)) + eq(expected_cterm, nvim("get_hl_by_id", hl_id, false)) - command('set termguicolors') hl_id = eval("hlID('NewHighlight')") - eq(expected_rgb, nvim("get_hl_by_id", hl_id)) + eq(expected_rgb, nvim("get_hl_by_id", hl_id, true)) - -- assume there is no hl with id 30000 - local err, emsg = pcall(meths.get_hl_by_id, 30000) + -- assume there is no hl with id = 30000 + local err, emsg = pcall(meths.get_hl_by_id, 30000, false) eq(false, err) ok(string.find(emsg, 'Invalid highlight id') ~= nil) end) @@ -44,16 +43,15 @@ describe('highlight api',function() foreground = Screen.colors.Red } -- test "Normal" hl defaults - eq({}, nvim("get_hl_by_name", 'Normal')) + eq({}, nvim("get_hl_by_name", 'Normal', true)) - eq(expected_cterm, nvim("get_hl_by_name", 'NewHighlight')) - command('set termguicolors') - eq(expected_rgb, nvim("get_hl_by_name", 'NewHighlight')) + eq(expected_cterm, nvim("get_hl_by_name", 'NewHighlight', false)) + eq(expected_rgb, nvim("get_hl_by_name", 'NewHighlight', true)) command('hi Normal guifg=red guibg=yellow') - eq(expected_normal, nvim("get_hl_by_name", 'Normal')) + eq(expected_normal, nvim("get_hl_by_name", 'Normal', true)) - local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight') + local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight', false) eq(false, err) ok(string.find(emsg, 'Invalid highlight name') ~= nil) end) -- cgit From 52517321d1859c31fef14aa75d784615693fcecb Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Oct 2017 20:23:11 +0200 Subject: test: nvim_get_hl_by_name/by_id #7082 - test all properties - test failure modes --- test/functional/api/highlight_spec.lua | 77 +++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 15 deletions(-) (limited to 'test/functional/api') 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) -- cgit