mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
Adds nvim_get_hl_by_name/by_id
...in order to retrieve highlights. Added test/functional/api/highlight_spec.lua HL_NORMAL is not really a good name, since it's more like an empty attribute than the normal's one. If one pays attention, syn_cterm_attr2entry is never called with attr=0 because it's always special cased before. I suggest in subsequent PRs we remove the ATTR_OFF and just insert an EMPTY ATTR/RESET_ATTR/UNINITIALIZED for id 0.
This commit is contained in:
54
test/functional/api/highlight_spec.lua
Normal file
54
test/functional/api/highlight_spec.lua
Normal file
@@ -0,0 +1,54 @@
|
||||
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local clear, nvim = helpers.clear, helpers.nvim
|
||||
local Screen = require('test.functional.ui.screen')
|
||||
local eq, eval = helpers.eq, helpers.eval
|
||||
local command = helpers.command
|
||||
local ok = helpers.ok
|
||||
local meths = helpers.meths
|
||||
|
||||
|
||||
describe('highlight api', function()
|
||||
|
||||
before_each(function()
|
||||
clear('--cmd', 'set termguicolors')
|
||||
end)
|
||||
|
||||
it("nvim_get_hl_by_id", function()
|
||||
local expected_hl = { background = Screen.colors.Yellow,
|
||||
foreground = Screen.colors.Red,
|
||||
special = Screen.colors.Blue
|
||||
}
|
||||
|
||||
command('hi NewHighlight guifg=red guibg=yellow guisp=blue')
|
||||
|
||||
local hl_id = eval("hlID('NewHighlight')")
|
||||
eq(expected_hl, nvim("get_hl_by_id", hl_id))
|
||||
|
||||
-- assume there is no hl with 30000
|
||||
local err, emsg = pcall(meths.get_hl_by_id, 30000)
|
||||
eq(false, err)
|
||||
ok(string.find(emsg, 'Invalid highlight id') ~= nil)
|
||||
end)
|
||||
|
||||
it("nvim_get_hl_by_name", function()
|
||||
local expected_hl = { background = Screen.colors.Yellow,
|
||||
foreground = Screen.colors.Red }
|
||||
|
||||
-- test "Normal" hl defaults
|
||||
eq({}, nvim("get_hl_by_name", 'Normal'))
|
||||
|
||||
command('hi NewHighlight guifg=red guibg=yellow')
|
||||
eq(expected_hl, nvim("get_hl_by_name", 'NewHighlight'))
|
||||
|
||||
command('hi Normal guifg=red guibg=yellow')
|
||||
eq(expected_hl, nvim("get_hl_by_name", 'Normal'))
|
||||
local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight')
|
||||
eq(false, err)
|
||||
ok(string.find(emsg, 'Invalid highlight name') ~= nil)
|
||||
end)
|
||||
|
||||
|
||||
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user