mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Increased test coverage for RGB and cterm
This commit is contained in:
parent
ba7277cfb4
commit
e3a2cca387
@ -78,7 +78,7 @@ Dictionary nvim_get_hl_by_name(String name, Error *err)
|
|||||||
|
|
||||||
/// Retrieves highlight description from its id
|
/// Retrieves highlight description from its id
|
||||||
///
|
///
|
||||||
/// @param hl_id highlight id as returned by hlID()
|
/// @param hl_id highlight id as returned by |hlID()|
|
||||||
/// @see nvim_get_hl_by_name
|
/// @see nvim_get_hl_by_name
|
||||||
Dictionary nvim_get_hl_by_id(Integer hl_id, Error *err)
|
Dictionary nvim_get_hl_by_id(Integer hl_id, Error *err)
|
||||||
FUNC_API_SINCE(3)
|
FUNC_API_SINCE(3)
|
||||||
@ -89,7 +89,7 @@ Dictionary nvim_get_hl_by_id(Integer hl_id, Error *err)
|
|||||||
return dic;
|
return dic;
|
||||||
}
|
}
|
||||||
int attrcode = syn_id2attr((int)hl_id);
|
int attrcode = syn_id2attr((int)hl_id);
|
||||||
return get_attr_by_id(attrcode, err);
|
return hl_get_attr_by_id(attrcode, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Passes input keys to Nvim.
|
/// Passes input keys to Nvim.
|
||||||
|
@ -8221,6 +8221,32 @@ RgbValue name_to_color(const uint8_t *name)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieves attribute description from its id
|
||||||
|
///
|
||||||
|
/// @param attr_id attribute id
|
||||||
|
Dictionary hl_get_attr_by_id(Integer attr_id, Error *err)
|
||||||
|
{
|
||||||
|
HlAttrs attrs = HLATTRS_INIT;
|
||||||
|
Dictionary dic = ARRAY_DICT_INIT;
|
||||||
|
|
||||||
|
if (attr_id == 0) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
attrentry_T *aep = syn_cterm_attr2entry((int)attr_id);
|
||||||
|
if (!aep) {
|
||||||
|
api_set_error(err, kErrorTypeException,
|
||||||
|
"Invalid attribute id %d", attr_id);
|
||||||
|
return dic;
|
||||||
|
}
|
||||||
|
|
||||||
|
attrs = attrentry2hlattrs(aep, p_tgc);
|
||||||
|
|
||||||
|
end:
|
||||||
|
return hlattrs2dict(attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************
|
/**************************************
|
||||||
* End of Highlighting stuff *
|
* End of Highlighting stuff *
|
||||||
**************************************/
|
**************************************/
|
||||||
|
@ -166,31 +166,6 @@ void ui_event(char *name, Array args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves attribute description from its id
|
|
||||||
///
|
|
||||||
/// @param attr_id attribute id
|
|
||||||
Dictionary get_attr_by_id(Integer attr_id, Error *err)
|
|
||||||
{
|
|
||||||
HlAttrs attrs = HLATTRS_INIT;
|
|
||||||
Dictionary dic = ARRAY_DICT_INIT;
|
|
||||||
|
|
||||||
if (attr_id == 0) {
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
attrentry_T *aep = syn_cterm_attr2entry((int)attr_id);
|
|
||||||
if (!aep) {
|
|
||||||
api_set_error(err, kErrorTypeException,
|
|
||||||
"Invalid attribute id %d", attr_id);
|
|
||||||
return dic;
|
|
||||||
}
|
|
||||||
|
|
||||||
attrs = attrentry2hlattrs(aep, p_tgc);
|
|
||||||
|
|
||||||
end:
|
|
||||||
return hlattrs2dict(attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Converts an attrentry_T into an HlAttrs
|
/// Converts an attrentry_T into an HlAttrs
|
||||||
///
|
///
|
||||||
|
@ -8,47 +8,53 @@ local ok = helpers.ok
|
|||||||
local meths = helpers.meths
|
local meths = helpers.meths
|
||||||
|
|
||||||
|
|
||||||
describe('highlight api', function()
|
describe('highlight api',function()
|
||||||
|
local expected_rgb = { background = Screen.colors.Yellow,
|
||||||
|
foreground = Screen.colors.Red,
|
||||||
|
special = Screen.colors.Blue,
|
||||||
|
bold = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
local expected_cterm = { background = 10,
|
||||||
|
underline = true,
|
||||||
|
}
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
clear('--cmd', 'set termguicolors')
|
clear()
|
||||||
|
command("hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("nvim_get_hl_by_id", function()
|
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')")
|
local hl_id = eval("hlID('NewHighlight')")
|
||||||
eq(expected_hl, nvim("get_hl_by_id", hl_id))
|
|
||||||
|
|
||||||
-- assume there is no hl with 30000
|
eq(expected_cterm, nvim("get_hl_by_id", hl_id))
|
||||||
|
|
||||||
|
command('set termguicolors')
|
||||||
|
hl_id = eval("hlID('NewHighlight')")
|
||||||
|
eq(expected_rgb, nvim("get_hl_by_id", hl_id))
|
||||||
|
|
||||||
|
-- assume there is no hl with id 30000
|
||||||
local err, emsg = pcall(meths.get_hl_by_id, 30000)
|
local err, emsg = pcall(meths.get_hl_by_id, 30000)
|
||||||
eq(false, err)
|
eq(false, err)
|
||||||
ok(string.find(emsg, 'Invalid highlight id') ~= nil)
|
ok(string.find(emsg, 'Invalid highlight id') ~= nil)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("nvim_get_hl_by_name", function()
|
it("nvim_get_hl_by_name", function()
|
||||||
local expected_hl = { background = Screen.colors.Yellow,
|
local expected_normal = { background = Screen.colors.Yellow,
|
||||||
foreground = Screen.colors.Red }
|
foreground = Screen.colors.Red }
|
||||||
|
|
||||||
-- test "Normal" hl defaults
|
-- test "Normal" hl defaults
|
||||||
eq({}, nvim("get_hl_by_name", 'Normal'))
|
eq({}, nvim("get_hl_by_name", 'Normal'))
|
||||||
|
|
||||||
command('hi NewHighlight guifg=red guibg=yellow')
|
eq(expected_cterm, nvim("get_hl_by_name", 'NewHighlight'))
|
||||||
eq(expected_hl, nvim("get_hl_by_name", 'NewHighlight'))
|
command('set termguicolors')
|
||||||
|
eq(expected_rgb, nvim("get_hl_by_name", 'NewHighlight'))
|
||||||
|
|
||||||
command('hi Normal guifg=red guibg=yellow')
|
command('hi Normal guifg=red guibg=yellow')
|
||||||
eq(expected_hl, nvim("get_hl_by_name", 'Normal'))
|
eq(expected_normal, nvim("get_hl_by_name", 'Normal'))
|
||||||
|
|
||||||
local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight')
|
local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight')
|
||||||
eq(false, err)
|
eq(false, err)
|
||||||
ok(string.find(emsg, 'Invalid highlight name') ~= nil)
|
ok(string.find(emsg, 'Invalid highlight name') ~= nil)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user