From 64a14026d76ba1798d91e15a941fcb6af7cbc5ad Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Wed, 29 Nov 2023 22:16:09 +0200 Subject: feat(highlight): update default color scheme Problem: Default color scheme is suboptimal. Solution: Start using new color scheme. Introduce new `vim` color scheme for opt-in backward compatibility. ------ Main design ideas - Be "Neovim branded". - Be minimal for 256 colors with a bit more shades for true colors. - Be accessible through high enough contrast ratios. - Be suitable for dark and light backgrounds via exchange of dark and light palettes. ------ Palettes - Have dark and light variants. Implemented through exporeted `NvimDark*` and `NvimLight*` hex colors. - Palettes have 4 shades of grey for UI elements and 6 colors (red, yellow, green, cyan, blue, magenta). - Actual values are computed procedurally in Oklch color space based on a handful of hyperparameters. - Each color has a 256 colors variant with perceptually closest color. ------ Highlight groups Use: - Grey shades for general UI according to their design. - Bold text for keywords (`Statement` highlight group). This is an important choice to increase accessibility for people with color deficiencies, as it doesn't rely on actual color. - Green for strings, `DiffAdd` (as background), `DiagnosticOk`, and some minor text UI elements. - Cyan as main syntax color, i.e. for function usage (`Function` highlight group), `DiffText`, `DiagnosticInfo`, and some minor text UI elements. - Red to generally mean high user attention, i.e. errors; in particular for `ErrorMsg`, `DiffDelete`, `DiagnosticError`. - Yellow very sparingly only with true colors to mean mild user attention, i.e. warnings. That is, `DiagnosticWarn` and `WarningMsg`. - Blue very sparingly only with true colors as `DiagnosticHint` and some additional important syntax group (like `Identifier`). - Magenta very carefully (if at all). ------ Notes - To make tests work without relatively larege updates, each one is prepended with an equivalent of the call `:colorscheme vim`. Plus some tests which spawn new Neovim instances also now use 'vim' color scheme. In some cases tests are updated to fit new default color scheme. --- 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 7d7d07e30e..c9edbf825d 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -561,7 +561,7 @@ describe('API: get highlight', function() end) it('can correctly detect links', function() - command('hi String guifg=#a6e3a1') + command('hi String guifg=#a6e3a1 ctermfg=NONE') command('hi link @string string') command('hi link @string.cpp @string') eq({ fg = 10937249 }, meths.get_hl(0, { name = 'String' })) -- cgit From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/api/highlight_spec.lua | 344 +++++++++++++++++++-------------- 1 file changed, 194 insertions(+), 150 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 c9edbf825d..fe9e2a7727 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -10,7 +10,7 @@ local pcall_err = helpers.pcall_err local ok = helpers.ok local assert_alive = helpers.assert_alive -describe('API: highlight',function() +describe('API: highlight', function() clear() Screen.new() -- initialize Screen.colors @@ -45,31 +45,35 @@ describe('API: highlight',function() before_each(function() clear() - command("hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold") + command( + 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold' + ) end) - it("nvim_get_hl_by_id", function() + it('nvim_get_hl_by_id', function() local hl_id = eval("hlID('NewHighlight')") - eq(expected_cterm, nvim("get_hl_by_id", hl_id, false)) + 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)) + eq(expected_rgb, nvim('get_hl_by_id', hl_id, true)) -- Test invalid id. 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') - eq(expected_rgb2, nvim("get_hl_by_id", hl_id, true)) + eq(expected_rgb2, nvim('get_hl_by_id', hl_id, true)) -- Test undercurl command('hi NewHighlight gui=undercurl') - eq(expected_undercurl, nvim("get_hl_by_id", hl_id, true)) + eq(expected_undercurl, nvim('get_hl_by_id', hl_id, true)) -- Test nil argument. - eq('Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer', - pcall_err(meths.get_hl_by_id, { nil }, false)) + eq( + 'Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer', + pcall_err(meths.get_hl_by_id, { nil }, false) + ) -- Test 0 argument. eq('Invalid highlight id: 0', pcall_err(meths.get_hl_by_id, 0, false)) @@ -81,76 +85,83 @@ describe('API: highlight',function() 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)) + 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)) + 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)) + eq({ foreground = 10, background = 13 }, meths.get_hl_by_id(hl_id, false)) end) - it("nvim_get_hl_by_name", function() - local expected_normal = { background = Screen.colors.Yellow, - foreground = Screen.colors.Red } + it('nvim_get_hl_by_name', function() + local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red } -- Test `Normal` default values. - eq({}, nvim("get_hl_by_name", 'Normal', true)) + 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)) + 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)) + eq(expected_normal, nvim('get_hl_by_name', 'Normal', true)) -- Test invalid name. - eq("Invalid highlight name: 'unknown_highlight'", - pcall_err(meths.get_hl_by_name , 'unknown_highlight', false)) + eq( + "Invalid highlight name: 'unknown_highlight'", + pcall_err(meths.get_hl_by_name, 'unknown_highlight', false) + ) -- Test nil argument. - eq('Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String', - pcall_err(meths.get_hl_by_name , { nil }, false)) + eq( + 'Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String', + pcall_err(meths.get_hl_by_name, { nil }, false) + ) -- Test empty string argument. - eq('Invalid highlight name', - pcall_err(meths.get_hl_by_name , '', false)) + eq('Invalid highlight name', pcall_err(meths.get_hl_by_name, '', false)) -- Test "standout" attribute. #8054 - eq({ underline = true, }, - meths.get_hl_by_name('cursorline', 0)); + eq({ underline = true }, meths.get_hl_by_name('cursorline', 0)) command('hi CursorLine cterm=standout,underline term=standout,underline gui=standout,underline') command('set cursorline') - eq({ underline = true, standout = true, }, - meths.get_hl_by_name('cursorline', 0)); + eq({ underline = true, standout = true }, meths.get_hl_by_name('cursorline', 0)) -- Test cterm & Normal values. #18024 (tail) & #18980 -- Ensure Normal, and groups that match Normal return their fg & bg cterm values - meths.set_hl(0, 'Normal', {ctermfg = 17, ctermbg = 213}) - meths.set_hl(0, 'NotNormal', {ctermfg = 17, ctermbg = 213, nocombine = true}) + meths.set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) + meths.set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) -- Note colors are "cterm" values, not rgb-as-ints - eq({foreground = 17, background = 213}, nvim("get_hl_by_name", 'Normal', false)) - eq({foreground = 17, background = 213, nocombine = true}, nvim("get_hl_by_name", 'NotNormal', false)) + eq({ foreground = 17, background = 213 }, nvim('get_hl_by_name', 'Normal', false)) + eq( + { foreground = 17, background = 213, nocombine = true }, + nvim('get_hl_by_name', 'NotNormal', false) + ) 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")) + 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") + local hl_id = meths.get_hl_id_by_name('Shrubbery') ok(hl_id > 0) - eq(hl_id, funcs.hlID("Shrubbery")) + 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)) + 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) it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function() @@ -165,7 +176,7 @@ describe('API: highlight',function() end) end) -describe("API: set highlight", function() +describe('API: set highlight', function() local highlight_color = { fg = tonumber('0xff0000'), bg = tonumber('0x0032aa'), @@ -207,7 +218,7 @@ describe("API: set highlight", function() strikethrough = true, altfont = true, nocombine = true, - } + }, } local highlight3_result_gui = { background = highlight_color.bg, @@ -238,31 +249,35 @@ describe("API: set highlight", function() before_each(clear) 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={}})) + 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() + 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({ @@ -271,14 +286,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("only allows one underline attribute #22371", function() + it('only allows one underline attribute #22371', function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', { underdouble = true, @@ -292,80 +307,76 @@ describe("API: set highlight", function() eq({ underdotted = true }, meths.get_hl_by_name('Test_hl', true)) 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')) + eq( + 'Test_hl xxx cterm=underline,reverse ctermfg=8 ctermbg=15 gui=underline,reverse', + exec_capture('highlight Test_hl') + ) meths.set_hl(0, 'Test_hl', { background = highlight_color.bg }) - eq('Test_hl xxx guibg=#0032aa', - exec_capture('highlight Test_hl')) + eq('Test_hl xxx guibg=#0032aa', exec_capture('highlight Test_hl')) meths.set_hl(0, 'Test_hl2', highlight3_config) - eq('Test_hl2 xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underdashed,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa', - exec_capture('highlight Test_hl2')) + eq( + 'Test_hl2 xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underdashed,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa', + exec_capture('highlight 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('Test_hl3 xxx guifg=Blue guibg=Red', - exec_capture('highlight Test_hl3')) + meths.set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) + eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) end) - 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')) + 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')) meths.set_hl(0, 'Test_hl3', { bg = 'red' }) - eq('Test_hl3 xxx guibg=Red', - exec_capture('highlight Test_hl3')) + eq('Test_hl3 xxx guibg=Red', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12}) - eq('Test_hl3 xxx ctermfg=12 ctermbg=9', - exec_capture('highlight Test_hl3')) + meths.set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12 }) + eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { ctermbg = 'red' , ctermfg = 'blue'}) - eq('Test_hl3 xxx ctermfg=12 ctermbg=9', - exec_capture('highlight Test_hl3')) + meths.set_hl(0, 'Test_hl3', { ctermbg = 'red', ctermfg = 'blue' }) + eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) meths.set_hl(0, 'Test_hl3', { ctermbg = 9 }) - eq('Test_hl3 xxx ctermbg=9', - exec_capture('highlight Test_hl3')) + eq('Test_hl3 xxx ctermbg=9', exec_capture('highlight Test_hl3')) - eq("Invalid highlight color: 'redd'", - pcall_err(meths.set_hl, 0, 'Test_hl3', {fg='redd'})) + eq("Invalid highlight color: 'redd'", pcall_err(meths.set_hl, 0, 'Test_hl3', { fg = 'redd' })) - eq("Invalid highlight color: 'bleu'", - pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='bleu'})) + 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')) + meths.set_hl(0, 'Test_hl3', { fg = '#FF00FF' }) + eq('Test_hl3 xxx guifg=#ff00ff', exec_capture('highlight Test_hl3')) - eq("Invalid highlight color: '#FF00FF'", - pcall_err(meths.set_hl, 0, 'Test_hl3', {ctermfg='#FF00FF'})) + 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 - meths.set_hl(0, 'Test_hl3', {fg = fg_val}) - eq('Test_hl3 xxx cleared', - exec_capture('highlight Test_hl3')) + for _, fg_val in ipairs { nil, 'NONE', 'nOnE', '', -1 } do + meths.set_hl(0, 'Test_hl3', { fg = fg_val }) + eq('Test_hl3 xxx cleared', exec_capture('highlight Test_hl3')) end - meths.set_hl(0, 'Test_hl3', {fg='#FF00FF', blend=50}) - eq('Test_hl3 xxx guifg=#ff00ff blend=50', - exec_capture('highlight Test_hl3')) - + meths.set_hl(0, 'Test_hl3', { fg = '#FF00FF', blend = 50 }) + eq('Test_hl3 xxx guifg=#ff00ff blend=50', exec_capture('highlight Test_hl3')) end) 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)) + 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) @@ -380,14 +391,16 @@ describe('API: get highlight', function() local highlight1 = { bg = highlight_color.bg, fg = highlight_color.fg, - bold = true, italic = true, - cterm = {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, - cterm = {underline = true, reverse = true}, + underline = true, + reverse = true, + cterm = { underline = true, reverse = true }, } local highlight3_config = { bg = highlight_color.bg, @@ -413,8 +426,19 @@ describe('API: get highlight', function() 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, nocombine = true, reverse = 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() @@ -434,17 +458,16 @@ describe('API: get highlight', function() before_each(clear) it('validation', function() - eq("Invalid '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) it('nvim_get_hl with create flag', function() - eq({}, nvim("get_hl", 0, {name = 'Foo', create = false})) + eq({}, nvim('get_hl', 0, { name = 'Foo', create = false })) eq(0, funcs.hlexists('Foo')) - meths.get_hl(0, {name = 'Bar', create = true}) + meths.get_hl(0, { name = 'Bar', create = true }) eq(1, funcs.hlexists('Bar')) - meths.get_hl(0, {name = 'FooBar'}) + meths.get_hl(0, { name = 'FooBar' }) eq(1, funcs.hlexists('FooBar')) end) @@ -454,11 +477,11 @@ describe('API: get highlight', function() meths.set_hl(ns, 'Test_hl_link', { link = 'Test_hl' }) eq({ Test_hl = { - bg = 11845374 + bg = 11845374, }, Test_hl_link = { - link = 'Test_hl' - } + link = 'Test_hl', + }, }, meths.get_hl(ns, {})) end) @@ -502,8 +525,7 @@ describe('API: get highlight', function() undercurl = true, }, }) - eq({ underdotted = true, cterm = { undercurl = 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() @@ -533,8 +555,13 @@ describe('API: get highlight', function() command( 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold' ) - eq({ fg = 16711680, bg = 16776960, sp = 255, bold = true, - ctermbg = 10, cterm = { underline = true }, + eq({ + fg = 16711680, + bg = 16776960, + sp = 255, + bold = true, + ctermbg = 10, + cterm = { underline = true }, }, meths.get_hl(0, { id = hl_id })) -- Test 0 argument @@ -547,16 +574,30 @@ describe('API: get highlight', function() -- Test all highlight properties. command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') - 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}, + 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({ fg = 16711680, bg = 16776960, sp = 255, undercurl = true, - ctermbg = 10, - cterm = {underline = true}, + eq({ + fg = 16711680, + bg = 16776960, + sp = 255, + undercurl = true, + ctermbg = 10, + cterm = { underline = true }, }, meths.get_hl(0, { id = hl_id })) end) @@ -573,7 +614,10 @@ describe('API: get highlight', 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 })) + 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() @@ -584,57 +628,57 @@ describe('API: get highlight', function() end) it("doesn't contain unset groups", function() - local id = meths.get_hl_id_by_name "@foobar.hubbabubba" + 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"]) + 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"]) + 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"]) + eq({}, data['@foobar.hubbabubba']) + eq(nil, data['@foobar']) end) it('should return default flag', function() - meths.set_hl(0, 'Tried', { fg = "#00ff00", default = true }) + 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, '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}}) + 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')) + 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) 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'})) + 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) @@ -647,9 +691,9 @@ describe('API: set/get highlight namespace', function() end) it('set/get window highlight namespace', function() - eq(-1, meths.get_hl_ns({winid = 0})) + 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})) + eq(ns, meths.get_hl_ns({ winid = 0 })) end) end) -- cgit From c30f2e3182e3b50e7c03932027ac55edfc8ada4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:44:54 +0000 Subject: test: typing for helpers.meths --- test/functional/api/highlight_spec.lua | 269 +++++++++++++++++---------------- 1 file changed, 142 insertions(+), 127 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 fe9e2a7727..07ce9d0c54 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -59,7 +59,7 @@ describe('API: highlight', function() eq(expected_rgb, nvim('get_hl_by_id', hl_id, true)) -- Test invalid id. - eq('Invalid highlight id: 30000', pcall_err(meths.get_hl_by_id, 30000, false)) + eq('Invalid highlight id: 30000', pcall_err(meths.nvim_get_hl_by_id, 30000, false)) -- Test all highlight properties. command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') @@ -72,30 +72,30 @@ describe('API: highlight', function() -- Test nil argument. eq( 'Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer', - pcall_err(meths.get_hl_by_id, { nil }, false) + pcall_err(meths.nvim_get_hl_by_id, { nil }, false) ) -- Test 0 argument. - eq('Invalid highlight id: 0', pcall_err(meths.get_hl_by_id, 0, false)) + eq('Invalid highlight id: 0', pcall_err(meths.nvim_get_hl_by_id, 0, false)) -- Test -1 argument. - eq('Invalid highlight id: -1', pcall_err(meths.get_hl_by_id, -1, false)) + eq('Invalid highlight id: -1', pcall_err(meths.nvim_get_hl_by_id, -1, false)) -- 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)) + eq({ foreground = 10 }, meths.nvim_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)) + eq({ background = 13 }, meths.nvim_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)) + eq({ foreground = 10, background = 13 }, meths.nvim_get_hl_by_id(hl_id, false)) end) it('nvim_get_hl_by_name', function() @@ -114,28 +114,28 @@ describe('API: highlight', function() -- Test invalid name. eq( "Invalid highlight name: 'unknown_highlight'", - pcall_err(meths.get_hl_by_name, 'unknown_highlight', false) + pcall_err(meths.nvim_get_hl_by_name, 'unknown_highlight', false) ) -- Test nil argument. eq( 'Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String', - pcall_err(meths.get_hl_by_name, { nil }, false) + pcall_err(meths.nvim_get_hl_by_name, { nil }, false) ) -- Test empty string argument. - eq('Invalid highlight name', pcall_err(meths.get_hl_by_name, '', false)) + eq('Invalid highlight name', pcall_err(meths.nvim_get_hl_by_name, '', false)) -- Test "standout" attribute. #8054 - eq({ underline = true }, meths.get_hl_by_name('cursorline', 0)) + eq({ underline = true }, meths.nvim_get_hl_by_name('cursorline', 0)) command('hi CursorLine cterm=standout,underline term=standout,underline gui=standout,underline') command('set cursorline') - eq({ underline = true, standout = true }, meths.get_hl_by_name('cursorline', 0)) + eq({ underline = true, standout = true }, meths.nvim_get_hl_by_name('cursorline', 0)) -- Test cterm & Normal values. #18024 (tail) & #18980 -- Ensure Normal, and groups that match Normal return their fg & bg cterm values - meths.set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) - meths.set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) + meths.nvim_set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) + meths.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) -- Note colors are "cterm" values, not rgb-as-ints eq({ foreground = 17, background = 213 }, nvim('get_hl_by_name', 'Normal', false)) eq( @@ -146,31 +146,34 @@ 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.nvim_get_hl_by_name, 'Shrubbery', true) + ) eq(0, funcs.hlID('Shrubbery')) - local hl_id = meths.get_hl_id_by_name('Shrubbery') + local hl_id = meths.nvim_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) + meths.nvim_get_hl_by_id(hl_id, true) ) eq( { foreground = tonumber('0x888888'), background = tonumber('0x888888') }, - meths.get_hl_by_name('Shrubbery', true) + meths.nvim_get_hl_by_name('Shrubbery', true) ) end) it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function() command('vsplit file') - local err, _ = pcall(meths.set_option_value, 'undofile', false, { buf = 1 }) + local err, _ = pcall(meths.nvim_set_option_value, 'undofile', false, { buf = 1 }) eq(true, err) - err, _ = pcall(meths.set_option_value, 'undolevels', -1, { buf = 1 }) + err, _ = pcall(meths.nvim_set_option_value, 'undolevels', -1, { buf = 1 }) eq(true, err) - err, _ = pcall(meths.buf_add_highlight, 1, -1, 'Question', 0, 0, -1) + err, _ = pcall(meths.nvim_buf_add_highlight, 1, -1, 'Question', 0, 0, -1) eq(true, err) assert_alive() end) @@ -241,8 +244,8 @@ describe('API: set highlight', function() } local function get_ns() - local ns = meths.create_namespace('Test_set_hl') - meths.set_hl_ns(ns) + local ns = meths.nvim_create_namespace('Test_set_hl') + meths.nvim_set_hl_ns(ns) return ns end @@ -251,51 +254,51 @@ 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 }) + pcall_err(meths.nvim_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 = {} }) + pcall_err(meths.nvim_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)) + meths.nvim_set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, meths.nvim_get_hl_by_name('Test_hl', true)) end) 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)) + meths.nvim_set_hl(ns, 'Test_hl', highlight2_config) + eq(highlight2_result, meths.nvim_get_hl_by_name('Test_hl', false)) end) 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)) + meths.nvim_set_hl(ns, 'Test_hl', { cterm = {} }) + eq({}, meths.nvim_get_hl_by_name('Test_hl', false)) end) it('cterm attr defaults to gui attr', function() local ns = get_ns() - meths.set_hl(ns, 'Test_hl', highlight1) + meths.nvim_set_hl(ns, 'Test_hl', highlight1) eq({ bold = true, italic = true, - }, meths.get_hl_by_name('Test_hl', false)) + }, meths.nvim_get_hl_by_name('Test_hl', false)) end) 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)) + meths.nvim_set_hl(ns, 'Test_hl', highlight3_config) + eq(highlight3_result_gui, meths.nvim_get_hl_by_name('Test_hl', true)) + eq(highlight3_result_cterm, meths.nvim_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', { + meths.nvim_set_hl(ns, 'Test_hl', { underdouble = true, underdotted = true, cterm = { @@ -303,21 +306,21 @@ describe('API: set highlight', function() undercurl = true, }, }) - eq({ undercurl = true }, meths.get_hl_by_name('Test_hl', false)) - eq({ underdotted = true }, meths.get_hl_by_name('Test_hl', true)) + eq({ undercurl = true }, meths.nvim_get_hl_by_name('Test_hl', false)) + eq({ underdotted = true }, meths.nvim_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) + meths.nvim_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') ) - meths.set_hl(0, 'Test_hl', { background = highlight_color.bg }) + meths.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg }) eq('Test_hl xxx guibg=#0032aa', exec_capture('highlight Test_hl')) - meths.set_hl(0, 'Test_hl2', highlight3_config) + meths.nvim_set_hl(0, 'Test_hl2', highlight3_config) eq( 'Test_hl2 xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underdashed,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa', exec_capture('highlight Test_hl2') @@ -325,58 +328,64 @@ describe('API: set highlight', function() -- Colors are stored with the name they are defined, but -- with canonical casing - meths.set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) + meths.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) end) it('can modify a highlight in the global namespace', function() - meths.set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue' }) + meths.nvim_set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue' }) eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { bg = 'red' }) + meths.nvim_set_hl(0, 'Test_hl3', { bg = 'red' }) eq('Test_hl3 xxx guibg=Red', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12 }) + meths.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12 }) eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { ctermbg = 'red', ctermfg = 'blue' }) + meths.nvim_set_hl(0, 'Test_hl3', { ctermbg = 'red', ctermfg = 'blue' }) eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) - meths.set_hl(0, 'Test_hl3', { ctermbg = 9 }) + meths.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9 }) eq('Test_hl3 xxx ctermbg=9', exec_capture('highlight Test_hl3')) - eq("Invalid highlight color: 'redd'", pcall_err(meths.set_hl, 0, 'Test_hl3', { fg = 'redd' })) + eq( + "Invalid highlight color: 'redd'", + pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { fg = 'redd' }) + ) eq( "Invalid highlight color: 'bleu'", - pcall_err(meths.set_hl, 0, 'Test_hl3', { ctermfg = 'bleu' }) + pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { ctermfg = 'bleu' }) ) - meths.set_hl(0, 'Test_hl3', { fg = '#FF00FF' }) + meths.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF' }) eq('Test_hl3 xxx guifg=#ff00ff', exec_capture('highlight Test_hl3')) eq( "Invalid highlight color: '#FF00FF'", - pcall_err(meths.set_hl, 0, 'Test_hl3', { ctermfg = '#FF00FF' }) + pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { ctermfg = '#FF00FF' }) ) for _, fg_val in ipairs { nil, 'NONE', 'nOnE', '', -1 } do - meths.set_hl(0, 'Test_hl3', { fg = fg_val }) + meths.nvim_set_hl(0, 'Test_hl3', { fg = fg_val }) eq('Test_hl3 xxx cleared', exec_capture('highlight Test_hl3')) end - meths.set_hl(0, 'Test_hl3', { fg = '#FF00FF', blend = 50 }) + meths.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF', blend = 50 }) eq('Test_hl3 xxx guifg=#ff00ff blend=50', exec_capture('highlight Test_hl3')) end) it("correctly sets 'Normal' internal properties", function() -- Normal has some special handling internally. #18024 - meths.set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' }) + meths.nvim_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.nvim_set_hl, 0, 'foo bar', { bold = true }) + ) assert_alive() end) end) @@ -443,14 +452,14 @@ describe('API: get highlight', function() 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 ns2 = meths.nvim_create_namespace('Another_namespace') + meths.nvim_set_hl(ns2, 'Test_hl', { ctermfg = 23 }) + meths.nvim_set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' }) + meths.nvim_set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' }) + meths.nvim_set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' }) - local ns = meths.create_namespace('Test_set_hl') - meths.set_hl_ns(ns) + local ns = meths.nvim_create_namespace('Test_set_hl') + meths.nvim_set_hl_ns(ns) return ns end @@ -458,23 +467,26 @@ describe('API: get highlight', function() before_each(clear) it('validation', function() - 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' })) + eq( + "Invalid 'name': expected String, got Integer", + pcall_err(meths.nvim_get_hl, 0, { name = 177 }) + ) + eq('Highlight id out of bounds', pcall_err(meths.nvim_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 }) + meths.nvim_get_hl(0, { name = 'Bar', create = true }) eq(1, funcs.hlexists('Bar')) - meths.get_hl(0, { name = 'FooBar' }) + meths.nvim_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' }) - meths.set_hl(ns, 'Test_hl_link', { link = 'Test_hl' }) + meths.nvim_set_hl(ns, 'Test_hl', { bg = '#B4BEFE' }) + meths.nvim_set_hl(ns, 'Test_hl_link', { link = 'Test_hl' }) eq({ Test_hl = { bg = 11845374, @@ -482,42 +494,42 @@ describe('API: get highlight', function() Test_hl_link = { link = 'Test_hl', }, - }, meths.get_hl(ns, {})) + }, meths.nvim_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' })) + meths.nvim_set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, meths.nvim_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' })) + meths.nvim_set_hl(ns, 'Test_hl', highlight2) + eq(highlight2, meths.nvim_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' })) + meths.nvim_set_hl(ns, 'Test_hl', { cterm = {} }) + eq({}, meths.nvim_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' })) + meths.nvim_set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, meths.nvim_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' })) + meths.nvim_set_hl(ns, 'Test_hl', highlight3_config) + eq(highlight3_result, meths.nvim_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', { + meths.nvim_set_hl(ns, 'Test_hl', { underdouble = true, underdotted = true, cterm = { @@ -525,32 +537,35 @@ describe('API: get highlight', function() undercurl = true, }, }) - eq({ underdotted = true, cterm = { undercurl = true } }, meths.get_hl(ns, { name = 'Test_hl' })) + eq( + { underdotted = true, cterm = { undercurl = true } }, + meths.nvim_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.nvim_set_hl(0, 'Test_hl', highlight2) + eq(highlight2, meths.nvim_get_hl(0, { name = 'Test_hl' })) - meths.set_hl(0, 'Test_hl', { background = highlight_color.bg }) + meths.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg }) eq({ bg = 12970, - }, meths.get_hl(0, { name = 'Test_hl' })) + }, meths.nvim_get_hl(0, { name = 'Test_hl' })) - meths.set_hl(0, 'Test_hl2', highlight3_config) - eq(highlight3_result, meths.get_hl(0, { name = 'Test_hl2' })) + meths.nvim_set_hl(0, 'Test_hl2', highlight3_config) + eq(highlight3_result, meths.nvim_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' }) + meths.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) eq({ bg = 16711680, fg = 255, - }, meths.get_hl(0, { name = 'Test_hl3' })) + }, meths.nvim_get_hl(0, { name = 'Test_hl3' })) end) it('nvim_get_hl by id', function() - local hl_id = meths.get_hl_id_by_name('NewHighlight') + local hl_id = meths.nvim_get_hl_id_by_name('NewHighlight') command( 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold' @@ -562,14 +577,14 @@ describe('API: get highlight', function() bold = true, ctermbg = 10, cterm = { underline = true }, - }, meths.get_hl(0, { id = hl_id })) + }, meths.nvim_get_hl(0, { id = hl_id })) -- Test 0 argument - eq('Highlight id out of bounds', pcall_err(meths.get_hl, 0, { id = 0 })) + eq('Highlight id out of bounds', pcall_err(meths.nvim_get_hl, 0, { id = 0 })) eq( "Invalid 'id': expected Integer, got String", - pcall_err(meths.get_hl, 0, { id = 'Test_set_hl' }) + pcall_err(meths.nvim_get_hl, 0, { id = 'Test_set_hl' }) ) -- Test all highlight properties. @@ -587,7 +602,7 @@ describe('API: get highlight', function() underline = true, ctermbg = 10, cterm = { underline = true }, - }, meths.get_hl(0, { id = hl_id })) + }, meths.nvim_get_hl(0, { id = hl_id })) -- Test undercurl command('hi NewHighlight gui=undercurl') @@ -598,16 +613,16 @@ describe('API: get highlight', function() undercurl = true, ctermbg = 10, cterm = { underline = true }, - }, meths.get_hl(0, { id = hl_id })) + }, meths.nvim_get_hl(0, { id = hl_id })) end) it('can correctly detect links', function() command('hi String guifg=#a6e3a1 ctermfg=NONE') 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 })) + eq({ fg = 10937249 }, meths.nvim_get_hl(0, { name = 'String' })) + eq({ link = 'String' }, meths.nvim_get_hl(0, { name = '@string' })) + eq({ fg = 10937249 }, meths.nvim_get_hl(0, { name = '@string.cpp', link = false })) end) it('can get all attributes for a linked group', function() @@ -616,55 +631,55 @@ describe('API: get highlight', function() command('hi! link Foo Bar') eq( { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, underline = true }, - meths.get_hl(0, { name = 'Foo', link = true }) + meths.nvim_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 })) + meths.nvim_set_hl(0, 'Foo', hl) + eq(hl, meths.nvim_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' + local id = meths.nvim_get_hl_id_by_name '@foobar.hubbabubba' ok(id > 0) - local data = meths.get_hl(0, {}) + local data = meths.nvim_get_hl(0, {}) eq(nil, data['@foobar.hubbabubba']) eq(nil, data['@foobar']) command 'hi @foobar.hubbabubba gui=bold' - data = meths.get_hl(0, {}) + data = meths.nvim_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, {}) + data = meths.nvim_get_hl(0, {}) 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' })) + meths.nvim_set_hl(0, 'Tried', { fg = '#00ff00', default = true }) + eq({ fg = tonumber('00ff00', 16), default = true }, meths.nvim_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( + meths.nvim_set_hl(0, 'Foo', { default = true }) + meths.nvim_set_hl(0, 'Bar', { default = true, fg = '#ffffff' }) + meths.nvim_set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = { bold = true } }) + meths.nvim_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({ default = true }, meths.nvim_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')) @@ -673,27 +688,27 @@ describe('API: get highlight', function() 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' })) + meths.nvim_set_hl(0, 'Foo', { fg = white }) + meths.nvim_set_hl(0, 'Foo', { fg = green, force = true }) + eq({ fg = green }, meths.nvim_get_hl(0, { name = 'Foo' })) + meths.nvim_set_hl(0, 'Bar', { link = 'Comment', default = true }) + meths.nvim_set_hl(0, 'Bar', { link = 'Foo', default = true, force = true }) + eq({ link = 'Foo', default = true }, meths.nvim_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({})) + eq(0, meths.nvim_get_hl_ns({})) + local ns = meths.nvim_create_namespace('') + meths.nvim_set_hl_ns(ns) + eq(ns, meths.nvim_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 })) + eq(-1, meths.nvim_get_hl_ns({ winid = 0 })) + local ns = meths.nvim_create_namespace('') + meths.nvim_win_set_hl_ns(0, ns) + eq(ns, meths.nvim_get_hl_ns({ winid = 0 })) end) end) -- cgit From 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 13:11:28 +0000 Subject: test: normalise nvim bridge functions - remove helpers.cur*meths - remove helpers.nvim --- test/functional/api/highlight_spec.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 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 07ce9d0c54..b86fe550a1 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -1,5 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, nvim = helpers.clear, helpers.nvim +local clear = helpers.clear local Screen = require('test.functional.ui.screen') local eq, eval = helpers.eq, helpers.eval local command = helpers.command @@ -52,22 +52,22 @@ describe('API: highlight', function() it('nvim_get_hl_by_id', function() local hl_id = eval("hlID('NewHighlight')") - eq(expected_cterm, nvim('get_hl_by_id', hl_id, false)) + eq(expected_cterm, meths.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)) + eq(expected_rgb, meths.nvim_get_hl_by_id(hl_id, true)) -- Test invalid id. eq('Invalid highlight id: 30000', pcall_err(meths.nvim_get_hl_by_id, 30000, false)) -- Test all highlight properties. command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') - eq(expected_rgb2, nvim('get_hl_by_id', hl_id, true)) + eq(expected_rgb2, meths.nvim_get_hl_by_id(hl_id, true)) -- Test undercurl command('hi NewHighlight gui=undercurl') - eq(expected_undercurl, nvim('get_hl_by_id', hl_id, true)) + eq(expected_undercurl, meths.nvim_get_hl_by_id(hl_id, true)) -- Test nil argument. eq( @@ -102,14 +102,14 @@ describe('API: highlight', function() local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red } -- Test `Normal` default values. - eq({}, nvim('get_hl_by_name', 'Normal', true)) + eq({}, meths.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)) + eq(expected_cterm, meths.nvim_get_hl_by_name('NewHighlight', false)) + eq(expected_rgb, meths.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)) + eq(expected_normal, meths.nvim_get_hl_by_name('Normal', true)) -- Test invalid name. eq( @@ -137,10 +137,10 @@ describe('API: highlight', function() meths.nvim_set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) meths.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) -- Note colors are "cterm" values, not rgb-as-ints - eq({ foreground = 17, background = 213 }, nvim('get_hl_by_name', 'Normal', false)) + eq({ foreground = 17, background = 213 }, meths.nvim_get_hl_by_name('Normal', false)) eq( { foreground = 17, background = 213, nocombine = true }, - nvim('get_hl_by_name', 'NotNormal', false) + meths.nvim_get_hl_by_name('NotNormal', false) ) end) @@ -378,7 +378,7 @@ describe('API: set highlight', function() it("correctly sets 'Normal' internal properties", function() -- Normal has some special handling internally. #18024 meths.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' }) - eq({ foreground = 131, background = 243 }, nvim('get_hl_by_name', 'Normal', true)) + eq({ foreground = 131, background = 243 }, meths.nvim_get_hl_by_name('Normal', true)) end) it('does not segfault on invalid group name #20009', function() @@ -475,7 +475,7 @@ describe('API: get highlight', function() end) it('nvim_get_hl with create flag', function() - eq({}, nvim('get_hl', 0, { name = 'Foo', create = false })) + eq({}, meths.nvim_get_hl(0, { name = 'Foo', create = false })) eq(0, funcs.hlexists('Foo')) meths.nvim_get_hl(0, { name = 'Bar', create = true }) eq(1, funcs.hlexists('Bar')) -- cgit From 795f896a5772d5e0795f86642bdf90c82efac45c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 17:59:57 +0000 Subject: test: rename (meths, funcs) -> (api, fn) --- test/functional/api/highlight_spec.lua | 295 ++++++++++++++++----------------- 1 file changed, 146 insertions(+), 149 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 b86fe550a1..1973d3e1c7 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -4,8 +4,8 @@ local Screen = require('test.functional.ui.screen') local eq, eval = helpers.eq, helpers.eval local command = helpers.command local exec_capture = helpers.exec_capture -local meths = helpers.meths -local funcs = helpers.funcs +local api = helpers.api +local fn = helpers.fn local pcall_err = helpers.pcall_err local ok = helpers.ok local assert_alive = helpers.assert_alive @@ -52,128 +52,125 @@ describe('API: highlight', function() it('nvim_get_hl_by_id', function() local hl_id = eval("hlID('NewHighlight')") - eq(expected_cterm, meths.nvim_get_hl_by_id(hl_id, false)) + eq(expected_cterm, api.nvim_get_hl_by_id(hl_id, false)) hl_id = eval("hlID('NewHighlight')") -- Test valid id. - eq(expected_rgb, meths.nvim_get_hl_by_id(hl_id, true)) + eq(expected_rgb, api.nvim_get_hl_by_id(hl_id, true)) -- Test invalid id. - eq('Invalid highlight id: 30000', pcall_err(meths.nvim_get_hl_by_id, 30000, false)) + eq('Invalid highlight id: 30000', pcall_err(api.nvim_get_hl_by_id, 30000, false)) -- Test all highlight properties. command('hi NewHighlight gui=underline,bold,italic,reverse,strikethrough,altfont,nocombine') - eq(expected_rgb2, meths.nvim_get_hl_by_id(hl_id, true)) + eq(expected_rgb2, api.nvim_get_hl_by_id(hl_id, true)) -- Test undercurl command('hi NewHighlight gui=undercurl') - eq(expected_undercurl, meths.nvim_get_hl_by_id(hl_id, true)) + eq(expected_undercurl, api.nvim_get_hl_by_id(hl_id, true)) -- Test nil argument. eq( 'Wrong type for argument 1 when calling nvim_get_hl_by_id, expecting Integer', - pcall_err(meths.nvim_get_hl_by_id, { nil }, false) + pcall_err(api.nvim_get_hl_by_id, { nil }, false) ) -- Test 0 argument. - eq('Invalid highlight id: 0', pcall_err(meths.nvim_get_hl_by_id, 0, false)) + eq('Invalid highlight id: 0', pcall_err(api.nvim_get_hl_by_id, 0, false)) -- Test -1 argument. - eq('Invalid highlight id: -1', pcall_err(meths.nvim_get_hl_by_id, -1, false)) + eq('Invalid highlight id: -1', pcall_err(api.nvim_get_hl_by_id, -1, false)) -- 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.nvim_get_hl_by_id(hl_id, false)) + eq({ foreground = 10 }, api.nvim_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.nvim_get_hl_by_id(hl_id, false)) + eq({ background = 13 }, api.nvim_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.nvim_get_hl_by_id(hl_id, false)) + eq({ foreground = 10, background = 13 }, api.nvim_get_hl_by_id(hl_id, false)) end) it('nvim_get_hl_by_name', function() local expected_normal = { background = Screen.colors.Yellow, foreground = Screen.colors.Red } -- Test `Normal` default values. - eq({}, meths.nvim_get_hl_by_name('Normal', true)) + eq({}, api.nvim_get_hl_by_name('Normal', true)) - eq(expected_cterm, meths.nvim_get_hl_by_name('NewHighlight', false)) - eq(expected_rgb, meths.nvim_get_hl_by_name('NewHighlight', true)) + eq(expected_cterm, api.nvim_get_hl_by_name('NewHighlight', false)) + eq(expected_rgb, api.nvim_get_hl_by_name('NewHighlight', true)) -- Test `Normal` modified values. command('hi Normal guifg=red guibg=yellow') - eq(expected_normal, meths.nvim_get_hl_by_name('Normal', true)) + eq(expected_normal, api.nvim_get_hl_by_name('Normal', true)) -- Test invalid name. eq( "Invalid highlight name: 'unknown_highlight'", - pcall_err(meths.nvim_get_hl_by_name, 'unknown_highlight', false) + pcall_err(api.nvim_get_hl_by_name, 'unknown_highlight', false) ) -- Test nil argument. eq( 'Wrong type for argument 1 when calling nvim_get_hl_by_name, expecting String', - pcall_err(meths.nvim_get_hl_by_name, { nil }, false) + pcall_err(api.nvim_get_hl_by_name, { nil }, false) ) -- Test empty string argument. - eq('Invalid highlight name', pcall_err(meths.nvim_get_hl_by_name, '', false)) + eq('Invalid highlight name', pcall_err(api.nvim_get_hl_by_name, '', false)) -- Test "standout" attribute. #8054 - eq({ underline = true }, meths.nvim_get_hl_by_name('cursorline', 0)) + eq({ underline = true }, api.nvim_get_hl_by_name('cursorline', 0)) command('hi CursorLine cterm=standout,underline term=standout,underline gui=standout,underline') command('set cursorline') - eq({ underline = true, standout = true }, meths.nvim_get_hl_by_name('cursorline', 0)) + eq({ underline = true, standout = true }, api.nvim_get_hl_by_name('cursorline', 0)) -- Test cterm & Normal values. #18024 (tail) & #18980 -- Ensure Normal, and groups that match Normal return their fg & bg cterm values - meths.nvim_set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) - meths.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) + api.nvim_set_hl(0, 'Normal', { ctermfg = 17, ctermbg = 213 }) + api.nvim_set_hl(0, 'NotNormal', { ctermfg = 17, ctermbg = 213, nocombine = true }) -- Note colors are "cterm" values, not rgb-as-ints - eq({ foreground = 17, background = 213 }, meths.nvim_get_hl_by_name('Normal', false)) + eq({ foreground = 17, background = 213 }, api.nvim_get_hl_by_name('Normal', false)) eq( { foreground = 17, background = 213, nocombine = true }, - meths.nvim_get_hl_by_name('NotNormal', false) + api.nvim_get_hl_by_name('NotNormal', false) ) 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.nvim_get_hl_by_name, 'Shrubbery', true) - ) - eq(0, funcs.hlID('Shrubbery')) + eq("Invalid highlight name: 'Shrubbery'", pcall_err(api.nvim_get_hl_by_name, 'Shrubbery', true)) + eq(0, fn.hlID('Shrubbery')) - local hl_id = meths.nvim_get_hl_id_by_name('Shrubbery') + local hl_id = api.nvim_get_hl_id_by_name('Shrubbery') ok(hl_id > 0) - eq(hl_id, funcs.hlID('Shrubbery')) + eq(hl_id, fn.hlID('Shrubbery')) command('hi Shrubbery guifg=#888888 guibg=#888888') eq( { foreground = tonumber('0x888888'), background = tonumber('0x888888') }, - meths.nvim_get_hl_by_id(hl_id, true) + api.nvim_get_hl_by_id(hl_id, true) ) eq( { foreground = tonumber('0x888888'), background = tonumber('0x888888') }, - meths.nvim_get_hl_by_name('Shrubbery', true) + api.nvim_get_hl_by_name('Shrubbery', true) ) end) it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function() command('vsplit file') - local err, _ = pcall(meths.nvim_set_option_value, 'undofile', false, { buf = 1 }) + local err, _ = pcall(api.nvim_set_option_value, 'undofile', false, { buf = 1 }) eq(true, err) - err, _ = pcall(meths.nvim_set_option_value, 'undolevels', -1, { buf = 1 }) + err, _ = pcall(api.nvim_set_option_value, 'undolevels', -1, { buf = 1 }) eq(true, err) - err, _ = pcall(meths.nvim_buf_add_highlight, 1, -1, 'Question', 0, 0, -1) + err, _ = pcall(api.nvim_buf_add_highlight, 1, -1, 'Question', 0, 0, -1) eq(true, err) assert_alive() end) @@ -244,8 +241,8 @@ describe('API: set highlight', function() } local function get_ns() - local ns = meths.nvim_create_namespace('Test_set_hl') - meths.nvim_set_hl_ns(ns) + local ns = api.nvim_create_namespace('Test_set_hl') + api.nvim_set_hl_ns(ns) return ns end @@ -254,51 +251,51 @@ describe('API: set highlight', function() it('validation', function() eq( "Invalid 'blend': out of range", - pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = 999 }) + pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = 999 }) ) eq( "Invalid 'blend': expected Integer, got Array", - pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = {} }) + pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { fg = '#FF00FF', blend = {} }) ) end) it('can set gui highlight', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', highlight1) - eq(highlight1, meths.nvim_get_hl_by_name('Test_hl', true)) + api.nvim_set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, api.nvim_get_hl_by_name('Test_hl', true)) end) it('can set cterm highlight', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', highlight2_config) - eq(highlight2_result, meths.nvim_get_hl_by_name('Test_hl', false)) + api.nvim_set_hl(ns, 'Test_hl', highlight2_config) + eq(highlight2_result, api.nvim_get_hl_by_name('Test_hl', false)) end) it('can set empty cterm attr', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', { cterm = {} }) - eq({}, meths.nvim_get_hl_by_name('Test_hl', false)) + api.nvim_set_hl(ns, 'Test_hl', { cterm = {} }) + eq({}, api.nvim_get_hl_by_name('Test_hl', false)) end) it('cterm attr defaults to gui attr', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', highlight1) + api.nvim_set_hl(ns, 'Test_hl', highlight1) eq({ bold = true, italic = true, - }, meths.nvim_get_hl_by_name('Test_hl', false)) + }, api.nvim_get_hl_by_name('Test_hl', false)) end) it('can overwrite attr for cterm', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', highlight3_config) - eq(highlight3_result_gui, meths.nvim_get_hl_by_name('Test_hl', true)) - eq(highlight3_result_cterm, meths.nvim_get_hl_by_name('Test_hl', false)) + api.nvim_set_hl(ns, 'Test_hl', highlight3_config) + eq(highlight3_result_gui, api.nvim_get_hl_by_name('Test_hl', true)) + eq(highlight3_result_cterm, api.nvim_get_hl_by_name('Test_hl', false)) end) it('only allows one underline attribute #22371', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', { + api.nvim_set_hl(ns, 'Test_hl', { underdouble = true, underdotted = true, cterm = { @@ -306,21 +303,21 @@ describe('API: set highlight', function() undercurl = true, }, }) - eq({ undercurl = true }, meths.nvim_get_hl_by_name('Test_hl', false)) - eq({ underdotted = true }, meths.nvim_get_hl_by_name('Test_hl', true)) + eq({ undercurl = true }, api.nvim_get_hl_by_name('Test_hl', false)) + eq({ underdotted = true }, api.nvim_get_hl_by_name('Test_hl', true)) end) it('can set a highlight in the global namespace', function() - meths.nvim_set_hl(0, 'Test_hl', highlight2_config) + api.nvim_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') ) - meths.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg }) + api.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg }) eq('Test_hl xxx guibg=#0032aa', exec_capture('highlight Test_hl')) - meths.nvim_set_hl(0, 'Test_hl2', highlight3_config) + api.nvim_set_hl(0, 'Test_hl2', highlight3_config) eq( 'Test_hl2 xxx cterm=italic,reverse,strikethrough,altfont,nocombine ctermfg=8 ctermbg=15 gui=bold,underdashed,italic,reverse,strikethrough,altfont guifg=#ff0000 guibg=#0032aa', exec_capture('highlight Test_hl2') @@ -328,63 +325,63 @@ describe('API: set highlight', function() -- Colors are stored with the name they are defined, but -- with canonical casing - meths.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) + api.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) end) it('can modify a highlight in the global namespace', function() - meths.nvim_set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue' }) + api.nvim_set_hl(0, 'Test_hl3', { bg = 'red', fg = 'blue' }) eq('Test_hl3 xxx guifg=Blue guibg=Red', exec_capture('highlight Test_hl3')) - meths.nvim_set_hl(0, 'Test_hl3', { bg = 'red' }) + api.nvim_set_hl(0, 'Test_hl3', { bg = 'red' }) eq('Test_hl3 xxx guibg=Red', exec_capture('highlight Test_hl3')) - meths.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12 }) + api.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9, ctermfg = 12 }) eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) - meths.nvim_set_hl(0, 'Test_hl3', { ctermbg = 'red', ctermfg = 'blue' }) + api.nvim_set_hl(0, 'Test_hl3', { ctermbg = 'red', ctermfg = 'blue' }) eq('Test_hl3 xxx ctermfg=12 ctermbg=9', exec_capture('highlight Test_hl3')) - meths.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9 }) + api.nvim_set_hl(0, 'Test_hl3', { ctermbg = 9 }) eq('Test_hl3 xxx ctermbg=9', exec_capture('highlight Test_hl3')) eq( "Invalid highlight color: 'redd'", - pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { fg = 'redd' }) + pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { fg = 'redd' }) ) eq( "Invalid highlight color: 'bleu'", - pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { ctermfg = 'bleu' }) + pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { ctermfg = 'bleu' }) ) - meths.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF' }) + api.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF' }) eq('Test_hl3 xxx guifg=#ff00ff', exec_capture('highlight Test_hl3')) eq( "Invalid highlight color: '#FF00FF'", - pcall_err(meths.nvim_set_hl, 0, 'Test_hl3', { ctermfg = '#FF00FF' }) + pcall_err(api.nvim_set_hl, 0, 'Test_hl3', { ctermfg = '#FF00FF' }) ) for _, fg_val in ipairs { nil, 'NONE', 'nOnE', '', -1 } do - meths.nvim_set_hl(0, 'Test_hl3', { fg = fg_val }) + api.nvim_set_hl(0, 'Test_hl3', { fg = fg_val }) eq('Test_hl3 xxx cleared', exec_capture('highlight Test_hl3')) end - meths.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF', blend = 50 }) + api.nvim_set_hl(0, 'Test_hl3', { fg = '#FF00FF', blend = 50 }) eq('Test_hl3 xxx guifg=#ff00ff blend=50', exec_capture('highlight Test_hl3')) end) it("correctly sets 'Normal' internal properties", function() -- Normal has some special handling internally. #18024 - meths.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' }) - eq({ foreground = 131, background = 243 }, meths.nvim_get_hl_by_name('Normal', true)) + api.nvim_set_hl(0, 'Normal', { fg = '#000083', bg = '#0000F3' }) + eq({ foreground = 131, background = 243 }, api.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.nvim_set_hl, 0, 'foo bar', { bold = true }) + pcall_err(api.nvim_set_hl, 0, 'foo bar', { bold = true }) ) assert_alive() end) @@ -452,14 +449,14 @@ describe('API: get highlight', function() local function get_ns() -- Test namespace filtering behavior - local ns2 = meths.nvim_create_namespace('Another_namespace') - meths.nvim_set_hl(ns2, 'Test_hl', { ctermfg = 23 }) - meths.nvim_set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' }) - meths.nvim_set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' }) - meths.nvim_set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' }) + local ns2 = api.nvim_create_namespace('Another_namespace') + api.nvim_set_hl(ns2, 'Test_hl', { ctermfg = 23 }) + api.nvim_set_hl(ns2, 'Test_another_hl', { link = 'Test_hl' }) + api.nvim_set_hl(ns2, 'Test_hl_link', { link = 'Test_another_hl' }) + api.nvim_set_hl(ns2, 'Test_another_hl_link', { link = 'Test_hl_link' }) - local ns = meths.nvim_create_namespace('Test_set_hl') - meths.nvim_set_hl_ns(ns) + local ns = api.nvim_create_namespace('Test_set_hl') + api.nvim_set_hl_ns(ns) return ns end @@ -469,24 +466,24 @@ describe('API: get highlight', function() it('validation', function() eq( "Invalid 'name': expected String, got Integer", - pcall_err(meths.nvim_get_hl, 0, { name = 177 }) + pcall_err(api.nvim_get_hl, 0, { name = 177 }) ) - eq('Highlight id out of bounds', pcall_err(meths.nvim_get_hl, 0, { name = 'Test set hl' })) + eq('Highlight id out of bounds', pcall_err(api.nvim_get_hl, 0, { name = 'Test set hl' })) end) it('nvim_get_hl with create flag', function() - eq({}, meths.nvim_get_hl(0, { name = 'Foo', create = false })) - eq(0, funcs.hlexists('Foo')) - meths.nvim_get_hl(0, { name = 'Bar', create = true }) - eq(1, funcs.hlexists('Bar')) - meths.nvim_get_hl(0, { name = 'FooBar' }) - eq(1, funcs.hlexists('FooBar')) + eq({}, api.nvim_get_hl(0, { name = 'Foo', create = false })) + eq(0, fn.hlexists('Foo')) + api.nvim_get_hl(0, { name = 'Bar', create = true }) + eq(1, fn.hlexists('Bar')) + api.nvim_get_hl(0, { name = 'FooBar' }) + eq(1, fn.hlexists('FooBar')) end) it('can get all highlights in current namespace', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', { bg = '#B4BEFE' }) - meths.nvim_set_hl(ns, 'Test_hl_link', { link = 'Test_hl' }) + api.nvim_set_hl(ns, 'Test_hl', { bg = '#B4BEFE' }) + api.nvim_set_hl(ns, 'Test_hl_link', { link = 'Test_hl' }) eq({ Test_hl = { bg = 11845374, @@ -494,42 +491,42 @@ describe('API: get highlight', function() Test_hl_link = { link = 'Test_hl', }, - }, meths.nvim_get_hl(ns, {})) + }, api.nvim_get_hl(ns, {})) end) it('can get gui highlight', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', highlight1) - eq(highlight1, meths.nvim_get_hl(ns, { name = 'Test_hl' })) + api.nvim_set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, api.nvim_get_hl(ns, { name = 'Test_hl' })) end) it('can get cterm highlight', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', highlight2) - eq(highlight2, meths.nvim_get_hl(ns, { name = 'Test_hl' })) + api.nvim_set_hl(ns, 'Test_hl', highlight2) + eq(highlight2, api.nvim_get_hl(ns, { name = 'Test_hl' })) end) it('can get empty cterm attr', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', { cterm = {} }) - eq({}, meths.nvim_get_hl(ns, { name = 'Test_hl' })) + api.nvim_set_hl(ns, 'Test_hl', { cterm = {} }) + eq({}, api.nvim_get_hl(ns, { name = 'Test_hl' })) end) it('cterm attr defaults to gui attr', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', highlight1) - eq(highlight1, meths.nvim_get_hl(ns, { name = 'Test_hl' })) + api.nvim_set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, api.nvim_get_hl(ns, { name = 'Test_hl' })) end) it('can overwrite attr for cterm', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', highlight3_config) - eq(highlight3_result, meths.nvim_get_hl(ns, { name = 'Test_hl' })) + api.nvim_set_hl(ns, 'Test_hl', highlight3_config) + eq(highlight3_result, api.nvim_get_hl(ns, { name = 'Test_hl' })) end) it('only allows one underline attribute #22371', function() local ns = get_ns() - meths.nvim_set_hl(ns, 'Test_hl', { + api.nvim_set_hl(ns, 'Test_hl', { underdouble = true, underdotted = true, cterm = { @@ -539,33 +536,33 @@ describe('API: get highlight', function() }) eq( { underdotted = true, cterm = { undercurl = true } }, - meths.nvim_get_hl(ns, { name = 'Test_hl' }) + api.nvim_get_hl(ns, { name = 'Test_hl' }) ) end) it('can get a highlight in the global namespace', function() - meths.nvim_set_hl(0, 'Test_hl', highlight2) - eq(highlight2, meths.nvim_get_hl(0, { name = 'Test_hl' })) + api.nvim_set_hl(0, 'Test_hl', highlight2) + eq(highlight2, api.nvim_get_hl(0, { name = 'Test_hl' })) - meths.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg }) + api.nvim_set_hl(0, 'Test_hl', { background = highlight_color.bg }) eq({ bg = 12970, - }, meths.nvim_get_hl(0, { name = 'Test_hl' })) + }, api.nvim_get_hl(0, { name = 'Test_hl' })) - meths.nvim_set_hl(0, 'Test_hl2', highlight3_config) - eq(highlight3_result, meths.nvim_get_hl(0, { name = 'Test_hl2' })) + api.nvim_set_hl(0, 'Test_hl2', highlight3_config) + eq(highlight3_result, api.nvim_get_hl(0, { name = 'Test_hl2' })) -- Colors are stored with the name they are defined, but -- with canonical casing - meths.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) + api.nvim_set_hl(0, 'Test_hl3', { bg = 'reD', fg = 'bLue' }) eq({ bg = 16711680, fg = 255, - }, meths.nvim_get_hl(0, { name = 'Test_hl3' })) + }, api.nvim_get_hl(0, { name = 'Test_hl3' })) end) it('nvim_get_hl by id', function() - local hl_id = meths.nvim_get_hl_id_by_name('NewHighlight') + local hl_id = api.nvim_get_hl_id_by_name('NewHighlight') command( 'hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold' @@ -577,14 +574,14 @@ describe('API: get highlight', function() bold = true, ctermbg = 10, cterm = { underline = true }, - }, meths.nvim_get_hl(0, { id = hl_id })) + }, api.nvim_get_hl(0, { id = hl_id })) -- Test 0 argument - eq('Highlight id out of bounds', pcall_err(meths.nvim_get_hl, 0, { id = 0 })) + eq('Highlight id out of bounds', pcall_err(api.nvim_get_hl, 0, { id = 0 })) eq( "Invalid 'id': expected Integer, got String", - pcall_err(meths.nvim_get_hl, 0, { id = 'Test_set_hl' }) + pcall_err(api.nvim_get_hl, 0, { id = 'Test_set_hl' }) ) -- Test all highlight properties. @@ -602,7 +599,7 @@ describe('API: get highlight', function() underline = true, ctermbg = 10, cterm = { underline = true }, - }, meths.nvim_get_hl(0, { id = hl_id })) + }, api.nvim_get_hl(0, { id = hl_id })) -- Test undercurl command('hi NewHighlight gui=undercurl') @@ -613,16 +610,16 @@ describe('API: get highlight', function() undercurl = true, ctermbg = 10, cterm = { underline = true }, - }, meths.nvim_get_hl(0, { id = hl_id })) + }, api.nvim_get_hl(0, { id = hl_id })) end) it('can correctly detect links', function() command('hi String guifg=#a6e3a1 ctermfg=NONE') command('hi link @string string') command('hi link @string.cpp @string') - eq({ fg = 10937249 }, meths.nvim_get_hl(0, { name = 'String' })) - eq({ link = 'String' }, meths.nvim_get_hl(0, { name = '@string' })) - eq({ fg = 10937249 }, meths.nvim_get_hl(0, { name = '@string.cpp', link = false })) + eq({ fg = 10937249 }, api.nvim_get_hl(0, { name = 'String' })) + eq({ link = 'String' }, api.nvim_get_hl(0, { name = '@string' })) + eq({ fg = 10937249 }, api.nvim_get_hl(0, { name = '@string.cpp', link = false })) end) it('can get all attributes for a linked group', function() @@ -631,55 +628,55 @@ describe('API: get highlight', function() command('hi! link Foo Bar') eq( { link = 'Bar', fg = tonumber('00ff00', 16), bold = true, underline = true }, - meths.nvim_get_hl(0, { name = 'Foo', link = true }) + api.nvim_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.nvim_set_hl(0, 'Foo', hl) - eq(hl, meths.nvim_get_hl(0, { name = 'Foo', link = true })) + api.nvim_set_hl(0, 'Foo', hl) + eq(hl, api.nvim_get_hl(0, { name = 'Foo', link = true })) end) it("doesn't contain unset groups", function() - local id = meths.nvim_get_hl_id_by_name '@foobar.hubbabubba' + local id = api.nvim_get_hl_id_by_name '@foobar.hubbabubba' ok(id > 0) - local data = meths.nvim_get_hl(0, {}) + local data = api.nvim_get_hl(0, {}) eq(nil, data['@foobar.hubbabubba']) eq(nil, data['@foobar']) command 'hi @foobar.hubbabubba gui=bold' - data = meths.nvim_get_hl(0, {}) + data = api.nvim_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.nvim_get_hl(0, {}) + data = api.nvim_get_hl(0, {}) eq({}, data['@foobar.hubbabubba']) eq(nil, data['@foobar']) end) it('should return default flag', function() - meths.nvim_set_hl(0, 'Tried', { fg = '#00ff00', default = true }) - eq({ fg = tonumber('00ff00', 16), default = true }, meths.nvim_get_hl(0, { name = 'Tried' })) + api.nvim_set_hl(0, 'Tried', { fg = '#00ff00', default = true }) + eq({ fg = tonumber('00ff00', 16), default = true }, api.nvim_get_hl(0, { name = 'Tried' })) end) it('should not output empty gui and cterm #23474', function() - meths.nvim_set_hl(0, 'Foo', { default = true }) - meths.nvim_set_hl(0, 'Bar', { default = true, fg = '#ffffff' }) - meths.nvim_set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = { bold = true } }) - meths.nvim_set_hl( + api.nvim_set_hl(0, 'Foo', { default = true }) + api.nvim_set_hl(0, 'Bar', { default = true, fg = '#ffffff' }) + api.nvim_set_hl(0, 'FooBar', { default = true, fg = '#ffffff', cterm = { bold = true } }) + api.nvim_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.nvim_get_hl(0, { name = 'Foo' })) + eq({ default = true }, api.nvim_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')) @@ -688,27 +685,27 @@ describe('API: get highlight', function() it('can override exist highlight group by force #20323', function() local white = tonumber('ffffff', 16) local green = tonumber('00ff00', 16) - meths.nvim_set_hl(0, 'Foo', { fg = white }) - meths.nvim_set_hl(0, 'Foo', { fg = green, force = true }) - eq({ fg = green }, meths.nvim_get_hl(0, { name = 'Foo' })) - meths.nvim_set_hl(0, 'Bar', { link = 'Comment', default = true }) - meths.nvim_set_hl(0, 'Bar', { link = 'Foo', default = true, force = true }) - eq({ link = 'Foo', default = true }, meths.nvim_get_hl(0, { name = 'Bar' })) + api.nvim_set_hl(0, 'Foo', { fg = white }) + api.nvim_set_hl(0, 'Foo', { fg = green, force = true }) + eq({ fg = green }, api.nvim_get_hl(0, { name = 'Foo' })) + api.nvim_set_hl(0, 'Bar', { link = 'Comment', default = true }) + api.nvim_set_hl(0, 'Bar', { link = 'Foo', default = true, force = true }) + eq({ link = 'Foo', default = true }, api.nvim_get_hl(0, { name = 'Bar' })) end) end) describe('API: set/get highlight namespace', function() it('set/get highlight namespace', function() - eq(0, meths.nvim_get_hl_ns({})) - local ns = meths.nvim_create_namespace('') - meths.nvim_set_hl_ns(ns) - eq(ns, meths.nvim_get_hl_ns({})) + eq(0, api.nvim_get_hl_ns({})) + local ns = api.nvim_create_namespace('') + api.nvim_set_hl_ns(ns) + eq(ns, api.nvim_get_hl_ns({})) end) it('set/get window highlight namespace', function() - eq(-1, meths.nvim_get_hl_ns({ winid = 0 })) - local ns = meths.nvim_create_namespace('') - meths.nvim_win_set_hl_ns(0, ns) - eq(ns, meths.nvim_get_hl_ns({ winid = 0 })) + eq(-1, api.nvim_get_hl_ns({ winid = 0 })) + local ns = api.nvim_create_namespace('') + api.nvim_win_set_hl_ns(0, ns) + eq(ns, api.nvim_get_hl_ns({ winid = 0 })) end) end) -- cgit