From ff3d04b75b4a9314815c37d53ebc4d035a043335 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 08:07:38 -0500 Subject: refactor(api): VALIDATE macros #22256 - VALIDATE() takes a format string - deduplicate check_string_array - VALIDATE_RANGE - validate UI args --- test/functional/api/highlight_spec.lua | 67 +++++++++++++++------------------- 1 file changed, 29 insertions(+), 38 deletions(-) (limited to 'test/functional/api/highlight_spec.lua') 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) -- cgit From 556f8646c01d1751cf39fe4df9c622899dceab9d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 14:19:28 -0500 Subject: refactor(api): consistent VALIDATE messages #22262 Problem: Validation messages are not consistently formatted. - Parameter names sometimes are NOT quoted. - Descriptive names (non-parameters) sometimes ARE quoted. Solution: Always quote the `name` value passed to a VALIDATE macro _unless_ the value has whitespace. --- test/functional/api/highlight_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 73551de42e..e1b3562329 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -240,7 +240,7 @@ describe("API: set 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", + eq("Invalid 'blend': expected Integer, got Array", pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='#FF00FF', blend={}})) end) -- cgit From 524e1a06432ed7a88c1e183d81812dd48dc18cfb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 23 Feb 2023 16:15:04 +0800 Subject: fix(highlight): avoid ORing underline flags (#22372) When combining attributes use the one that takes priority. For :highlight command use the last one specified. For API use a hard-coded order same as the order in docs. --- test/functional/api/highlight_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index e1b3562329..eb7d0f7b47 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -278,6 +278,20 @@ describe("API: set highlight", function() eq(highlight3_result_cterm, meths.get_hl_by_name('Test_hl', false)) end) + it("only allows one underline attribute #22371", function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', { + underdouble = true, + underdotted = true, + cterm = { + underline = true, + undercurl = true, + }, + }) + eq({ undercurl = true }, meths.get_hl_by_name('Test_hl', false)) + eq({ underdotted = true }, meths.get_hl_by_name('Test_hl', true)) + end) + 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', -- cgit From c0fe6c040e19ef9102a8507ffcbd88b83186326a Mon Sep 17 00:00:00 2001 From: Null Chilly <56817415+nullchilly@users.noreply.github.com> Date: Thu, 23 Mar 2023 16:31:39 +0700 Subject: feat(api): add nvim_get_hl (#22693) Problem: no way of getting all highlight group definitions in a namespace. Solution: add `nvim_get_hl()`, deprecate `nvim_get_hl_by_name()` and `nvim_get_hl_by_id()`. --- test/functional/api/highlight_spec.lua | 219 +++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index eb7d0f7b47..de3eb4e798 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -369,3 +369,222 @@ describe("API: set highlight", function() assert_alive() end) end) + +describe('API: get highlight', function() + local highlight_color = { + fg = tonumber('0xff0000'), + bg = tonumber('0x0032aa'), + ctermfg = 8, + ctermbg = 15, + } + local highlight1 = { + bg = highlight_color.bg, + fg = highlight_color.fg, + bold = true, + italic = true, + } + local highlight2 = { + ctermbg = highlight_color.ctermbg, + ctermfg = highlight_color.ctermfg, + underline = true, + reverse = true, + } + local highlight3_config = { + bg = highlight_color.bg, + fg = highlight_color.fg, + ctermbg = highlight_color.ctermbg, + ctermfg = highlight_color.ctermfg, + bold = true, + italic = true, + reverse = true, + underdashed = true, + strikethrough = true, + altfont = true, + cterm = { + italic = true, + reverse = true, + strikethrough = true, + altfont = true, + nocombine = true, + }, + } + local highlight3_result = { + bg = highlight_color.bg, + fg = highlight_color.fg, + ctermbg = highlight_color.ctermbg, + ctermfg = highlight_color.ctermfg, + bold = true, + italic = true, + nocombine = true, + reverse = true, + underdashed = true, + strikethrough = true, + altfont = true, + } + + local function get_ns() + -- Test namespace filtering behavior + local ns2 = meths.create_namespace('Another_namespace') + meths.set_hl(ns2, 'Test_hl', { ctermfg = 23 }) + meths.set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' }) + meths.set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' }) + meths.set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' }) + + local ns = meths.create_namespace('Test_set_hl') + meths.set_hl_ns(ns) + + return ns + end + + before_each(clear) + + it('validation', function() + eq( + 'Invalid highlight name: expected String, got Integer', + pcall_err(meths.get_hl, 0, { name = 177 }) + ) + eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { name = 'Test set hl' })) + end) + + it('can get all highlights in current namespace', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', { bg = '#B4BEFE' }) + meths.set_hl(ns, 'Test_hl_link', { link = 'Test_hl' }) + eq({ + Test_hl = { + bg = 11845374 + }, + Test_hl_link = { + link = 'Test_hl' + } + }, meths.get_hl(ns, {})) + end) + + it('can get gui highlight', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('can get cterm highlight', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', highlight2) + eq(highlight2, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('can get empty cterm attr', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', { cterm = {} }) + eq({}, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('cterm attr defaults to gui attr', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('can overwrite attr for cterm', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', highlight3_config) + eq(highlight3_result, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('only allows one underline attribute #22371', function() + local ns = get_ns() + meths.set_hl(ns, 'Test_hl', { + underdouble = true, + underdotted = true, + cterm = { + underline = true, + undercurl = true, + }, + }) + eq({ undercurl = true, underdotted = true }, meths.get_hl(ns, { name = 'Test_hl' })) + end) + + it('can get a highlight in the global namespace', function() + meths.set_hl(0, 'Test_hl', highlight2) + eq(highlight2, meths.get_hl(0, { name = 'Test_hl' })) + + meths.set_hl(0, 'Test_hl', { background = highlight_color.bg }) + eq({ + bg = 12970, + }, meths.get_hl(0, { name = 'Test_hl' })) + + meths.set_hl(0, 'Test_hl2', highlight3_config) + eq(highlight3_result, meths.get_hl(0, { name = 'Test_hl2' })) + + -- Colors are stored with the name they are defined, but + -- with canonical casing + meths.set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) + eq({ + bg = 16711680, + fg = 255, + }, meths.get_hl(0, { name = 'Test_hl3' })) + end) + + local expected_rgb = { + altfont = true, + bg = 16776960, + bold = true, + ctermbg = 10, + fg = 16711680, + italic = true, + nocombine = true, + reverse = true, + sp = 255, + strikethrough = true, + underline = true, + } + local expected = { + bg = 16776960, + bold = true, + ctermbg = 10, + fg = 16711680, + sp = 255, + underline = true, + } + local expected_undercurl = { + bg = 16776960, + ctermbg = 10, + fg = 16711680, + sp = 255, + undercurl = true, + underline = true, + } + + it('nvim_get_hl by id', function() + local hl_id = meths.get_hl_id_by_name('NewHighlight') + + command( + 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold' + ) + eq(expected, meths.get_hl(0, { id = hl_id })) + + -- Test 0 argument + eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { id = 0 })) + + eq( + 'Invalid highlight id: expected Integer, got String', + pcall_err(meths.get_hl, 0, { id = 'Test_set_hl' }) + ) + + -- Test all highlight properties. + command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') + eq(expected_rgb, meths.get_hl(0, { id = hl_id })) + + -- Test undercurl + command('hi NewHighlight gui=undercurl') + eq(expected_undercurl, meths.get_hl(0, { id = hl_id })) + end) + + it('can correctly detect links', function() + command('hi String guifg=#a6e3a1') + command('hi link @string string') + command('hi link @string.cpp @string') + eq({ fg = 10937249 }, meths.get_hl(0, { name = 'String' })) + eq({ link = 'String' }, meths.get_hl(0, { name = '@string' })) + eq({ fg = 10937249 }, meths.get_hl(0, { name = '@string.cpp', link = false })) + end) +end) -- cgit From 6d267ad30cf539f520b46e3c92939f7031ce116f Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 23 Mar 2023 12:44:05 +0100 Subject: fix(api): make nvim_get_hl return 'cterm' attrs properly --- test/functional/api/highlight_spec.lua | 64 ++++++++++------------------------ 1 file changed, 19 insertions(+), 45 deletions(-) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index de3eb4e798..65b13bebf7 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -380,14 +380,14 @@ describe('API: get highlight', function() local highlight1 = { bg = highlight_color.bg, fg = highlight_color.fg, - bold = true, - italic = true, + bold = true, italic = true, + cterm = {bold = true, italic = true}, } local highlight2 = { ctermbg = highlight_color.ctermbg, ctermfg = highlight_color.ctermfg, - underline = true, - reverse = true, + underline = true, reverse = true, + cterm = {underline = true, reverse = true}, } local highlight3_config = { bg = highlight_color.bg, @@ -413,13 +413,8 @@ describe('API: get highlight', function() fg = highlight_color.fg, ctermbg = highlight_color.ctermbg, ctermfg = highlight_color.ctermfg, - bold = true, - italic = true, - nocombine = true, - reverse = true, - underdashed = true, - strikethrough = true, - altfont = true, + bold = true, italic = true, reverse = true, underdashed = true, strikethrough = true, altfont = true, + cterm = {italic = true, nocombine = true, reverse = true, strikethrough = true, altfont = true} } local function get_ns() @@ -500,7 +495,8 @@ describe('API: get highlight', function() undercurl = true, }, }) - eq({ undercurl = true, underdotted = true }, meths.get_hl(ns, { name = 'Test_hl' })) + eq({ underdotted = true, cterm = { undercurl = true} }, + meths.get_hl(ns, { name = 'Test_hl' })) end) it('can get a highlight in the global namespace', function() @@ -524,43 +520,15 @@ describe('API: get highlight', function() }, meths.get_hl(0, { name = 'Test_hl3' })) end) - local expected_rgb = { - altfont = true, - bg = 16776960, - bold = true, - ctermbg = 10, - fg = 16711680, - italic = true, - nocombine = true, - reverse = true, - sp = 255, - strikethrough = true, - underline = true, - } - local expected = { - bg = 16776960, - bold = true, - ctermbg = 10, - fg = 16711680, - sp = 255, - underline = true, - } - local expected_undercurl = { - bg = 16776960, - ctermbg = 10, - fg = 16711680, - sp = 255, - undercurl = true, - underline = true, - } - it('nvim_get_hl by id', function() local hl_id = meths.get_hl_id_by_name('NewHighlight') command( 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold' ) - eq(expected, meths.get_hl(0, { id = hl_id })) + eq({ fg = 16711680, bg = 16776960, sp = 255, bold = true, + ctermbg = 10, cterm = { underline = true }, + }, meths.get_hl(0, { id = hl_id })) -- Test 0 argument eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { id = 0 })) @@ -572,11 +540,17 @@ describe('API: get highlight', function() -- Test all highlight properties. command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') - eq(expected_rgb, meths.get_hl(0, { id = hl_id })) + eq({ fg = 16711680, bg = 16776960, sp = 255, + altfont = true, bold = true, italic = true, nocombine = true, reverse = true, strikethrough = true, underline = true, + ctermbg = 10, cterm = {underline = true}, + }, meths.get_hl(0, { id = hl_id })) -- Test undercurl command('hi NewHighlight gui=undercurl') - eq(expected_undercurl, meths.get_hl(0, { id = hl_id })) + eq({ fg = 16711680, bg = 16776960, sp = 255, undercurl = true, + ctermbg = 10, + cterm = {underline = true}, + }, meths.get_hl(0, { id = hl_id })) end) it('can correctly detect links', function() -- cgit From b34097fe6d2ea5c84bcec65a834a430d9f58eb64 Mon Sep 17 00:00:00 2001 From: "Sindre T. Strøm" Date: Fri, 31 Mar 2023 12:52:53 +0200 Subject: fix(api): return both link and attributes with nvim_get_hl (#22824) Problem: No way to get the actual highlight attributes for a linked group through |nvim_get_hl()| (not the attributes from the link target). Solution: Return the actual attributes as well as the link target name. --- test/functional/api/highlight_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 65b13bebf7..a4bd574a56 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -561,4 +561,18 @@ describe('API: get highlight', function() eq({ link = 'String' }, meths.get_hl(0, { name = '@string' })) eq({ fg = 10937249 }, meths.get_hl(0, { name = '@string.cpp', link = false })) end) + + it('can get all attributes for a linked group', function() + command('hi Bar guifg=red') + command('hi Foo guifg=#00ff00 gui=bold,underline') + command('hi! link Foo Bar') + eq({ link = 'Bar', fg = tonumber('00ff00', 16), bold = true, underline = true }, meths.get_hl(0, { name = 'Foo', link = true })) + end) + + it('can set link as well as other attributes', function() + command('hi Bar guifg=red') + local hl = { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, cterm = { bold = true } } + meths.set_hl(0, 'Foo', hl) + eq(hl, meths.get_hl(0, { name = 'Foo', link = true })) + end) end) -- cgit From d05d63a18ff8394b31b3f3b85bfaebe2af358437 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 13 Apr 2023 14:08:36 +0200 Subject: fix(api): make nvim_get_hl not return non-existing groups fixes #23063 --- test/functional/api/highlight_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a4bd574a56..a6e9f9a42b 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -575,4 +575,25 @@ describe('API: get highlight', function() meths.set_hl(0, 'Foo', hl) eq(hl, meths.get_hl(0, { name = 'Foo', link = true })) end) + + it("doesn't contain unset groups", function() + local id = meths.get_hl_id_by_name "@foobar.hubbabubba" + ok(id > 0) + + local data = meths.get_hl(0, {}) + eq(nil, data["@foobar.hubbabubba"]) + eq(nil, data["@foobar"]) + + command 'hi @foobar.hubbabubba gui=bold' + data = meths.get_hl(0, {}) + eq({bold = true}, data["@foobar.hubbabubba"]) + eq(nil, data["@foobar"]) + + -- @foobar.hubbabubba was explicitly cleared and thus shows up + -- but @foobar was never touched, and thus doesn't + command 'hi clear @foobar.hubbabubba' + data = meths.get_hl(0, {}) + eq({}, data["@foobar.hubbabubba"]) + eq(nil, data["@foobar"]) + end) end) -- cgit From 1fe1bb084d0099fc4f9bfdc11189485d0f74b75a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 19 Dec 2022 16:37:45 +0000 Subject: refactor(options): deprecate nvim[_buf|_win]_[gs]et_option Co-authored-by: zeertzjq Co-authored-by: famiu --- test/functional/api/highlight_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a6e9f9a42b..1601184e1b 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -155,9 +155,9 @@ describe('API: highlight',function() it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function() command('vsplit file') - local err, _ = pcall(meths.buf_set_option, 1, 'undofile', false) + local err, _ = pcall(meths.set_option_value, 'undofile', false, { buf = 1 }) eq(true, err) - err, _ = pcall(meths.buf_set_option, 1, 'undolevels', -1) + err, _ = pcall(meths.set_option_value, 'undolevels', -1, { buf = 1 }) eq(true, err) err, _ = pcall(meths.buf_add_highlight, 1, -1, 'Question', 0, 0, -1) eq(true, err) -- cgit From b7708eac24c22a96676176c68569d6859a9f793f Mon Sep 17 00:00:00 2001 From: Null Chilly <56817415+nullchilly@users.noreply.github.com> Date: Mon, 22 May 2023 15:49:01 +0700 Subject: fix(api): nvim_get_hl should return default flag --- test/functional/api/highlight_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 1601184e1b..d3a79327ae 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -596,4 +596,9 @@ describe('API: get highlight', function() eq({}, data["@foobar.hubbabubba"]) eq(nil, data["@foobar"]) end) + + it('should return default flag', function() + meths.set_hl(0, 'Tried', { fg = "#00ff00", default = true }) + eq({ fg = tonumber('00ff00', 16), default = true }, meths.get_hl(0, { name = 'Tried' })) + end) end) -- cgit From 7bc93e0e2f246dd78026a3472d929a0fe450f70d Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 1 Aug 2023 14:01:19 +0200 Subject: refactor(api): use typed keysets Initially this is just for geting rid of boilerplate, but eventually the types could get exposed as metadata --- test/functional/api/highlight_spec.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index d3a79327ae..5fa2235018 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -434,10 +434,8 @@ describe('API: get highlight', function() before_each(clear) it('validation', function() - eq( - 'Invalid highlight name: expected String, got Integer', - pcall_err(meths.get_hl, 0, { name = 177 }) - ) + eq("Invalid 'name': expected String, got Integer", + pcall_err(meths.get_hl, 0, { name = 177 })) eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { name = 'Test set hl' })) end) @@ -534,7 +532,7 @@ describe('API: get highlight', function() eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { id = 0 })) eq( - 'Invalid highlight id: expected Integer, got String', + "Invalid 'id': expected Integer, got String", pcall_err(meths.get_hl, 0, { id = 'Test_set_hl' }) ) -- cgit From 8afb3a49c0762eb60368aee0314e6de261daa6ef Mon Sep 17 00:00:00 2001 From: glepnir Date: Thu, 7 Sep 2023 18:42:38 +0800 Subject: fix(highlight): add create param in nvim_get_hl --- test/functional/api/highlight_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 5fa2235018..492fd73223 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -439,6 +439,15 @@ describe('API: get highlight', function() eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { name = 'Test set hl' })) end) + it('nvim_get_hl with create flag', function() + eq({}, nvim("get_hl", 0, {name = 'Foo', create = false})) + eq(0, funcs.hlexists('Foo')) + meths.get_hl(0, {name = 'Bar', create = true}) + eq(1, funcs.hlexists('Bar')) + meths.get_hl(0, {name = 'FooBar'}) + eq(1, funcs.hlexists('FooBar')) + end) + it('can get all highlights in current namespace', function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', { bg = '#B4BEFE' }) -- cgit From 51836517738babaa406bc615fd9984129c5179a4 Mon Sep 17 00:00:00 2001 From: glepnir Date: Sat, 16 Sep 2023 19:08:40 +0800 Subject: fix(highlight): correct hi command output --- test/functional/api/highlight_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 492fd73223..5d6aaa57e6 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -608,4 +608,21 @@ describe('API: get highlight', function() meths.set_hl(0, 'Tried', { fg = "#00ff00", default = true }) eq({ fg = tonumber('00ff00', 16), default = true }, meths.get_hl(0, { name = 'Tried' })) end) + + it('should not output empty gui and cterm #23474', function() + meths.set_hl(0, 'Foo', {default = true}) + meths.set_hl(0, 'Bar', { default = true, fg = '#ffffff' }) + meths.set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = {bold = true} }) + meths.set_hl(0, 'FooBarA', { default = true, fg = '#ffffff', cterm = {bold = true,italic = true}}) + + eq('Foo xxx cleared', + exec_capture('highlight Foo')) + eq({default = true}, meths.get_hl(0, {name = 'Foo'})) + eq('Bar xxx guifg=#ffffff', + exec_capture('highlight Bar')) + eq('FooBar xxx cterm=bold guifg=#ffffff', + exec_capture('highlight FooBar')) + eq('FooBarA xxx cterm=bold,italic guifg=#ffffff', + exec_capture('highlight FooBarA')) + end) end) -- cgit From f8ea49cfe1f4f3ed30da160d346553f0949ec1de Mon Sep 17 00:00:00 2001 From: glepnir Date: Mon, 18 Sep 2023 14:50:27 +0800 Subject: fix(highlight): add force in nvim_set_hl --- test/functional/api/highlight_spec.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 5d6aaa57e6..1a054741ef 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -625,4 +625,15 @@ describe('API: get highlight', function() eq('FooBarA xxx cterm=bold,italic guifg=#ffffff', exec_capture('highlight FooBarA')) end) + + it('can override exist highlight group by force #20323', function() + local white = tonumber('ffffff', 16) + local green = tonumber('00ff00', 16) + meths.set_hl(0, 'Foo', { fg=white }) + meths.set_hl(0, 'Foo', { fg=green, force = true }) + eq({ fg = green },meths.get_hl(0, {name = 'Foo'})) + meths.set_hl(0, 'Bar', {link = 'Comment', default = true}) + meths.set_hl(0, 'Bar', {link = 'Foo',default = true, force = true}) + eq({link ='Foo', default = true}, meths.get_hl(0, {name = 'Bar'})) + end) end) -- cgit From 2615ed879e66a3d05920c47177e77383adc7aca0 Mon Sep 17 00:00:00 2001 From: Daniel Steinberg Date: Tue, 18 Jul 2023 17:02:45 -0400 Subject: feat(ui): allow to get the highlight namespace --- test/functional/api/highlight_spec.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 1a054741ef..7d7d07e30e 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -637,3 +637,19 @@ describe('API: get highlight', function() eq({link ='Foo', default = true}, meths.get_hl(0, {name = 'Bar'})) end) end) + +describe('API: set/get highlight namespace', function() + it('set/get highlight namespace', function() + eq(0, meths.get_hl_ns({})) + local ns = meths.create_namespace('') + meths.set_hl_ns(ns) + eq(ns, meths.get_hl_ns({})) + end) + + it('set/get window highlight namespace', function() + eq(-1, meths.get_hl_ns({winid = 0})) + local ns = meths.create_namespace('') + meths.win_set_hl_ns(0, ns) + eq(ns, meths.get_hl_ns({winid = 0})) + end) +end) -- cgit