diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-10-08 19:09:14 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-10-08 19:09:14 +0200 |
commit | 04187a1c74e79abfb46c0b9c1e522b61f1cedcae (patch) | |
tree | ae13c45333d1fb47e1734f59d3625139d69a8161 /test/functional/api/highlight_spec.lua | |
parent | 032b088c848585e60e8dc1a210f240bad6bb3387 (diff) | |
parent | 481e40cc8ca061f5c3a68f56f30ee96e9086da4d (diff) | |
download | rneovim-04187a1c74e79abfb46c0b9c1e522b61f1cedcae.tar.gz rneovim-04187a1c74e79abfb46c0b9c1e522b61f1cedcae.tar.bz2 rneovim-04187a1c74e79abfb46c0b9c1e522b61f1cedcae.zip |
Merge #7082 'api: nvim_get_hl_by_name/by_id'
Diffstat (limited to 'test/functional/api/highlight_spec.lua')
-rw-r--r-- | test/functional/api/highlight_spec.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua new file mode 100644 index 0000000000..c482128a31 --- /dev/null +++ b/test/functional/api/highlight_spec.lua @@ -0,0 +1,56 @@ +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 meths = helpers.meths + +describe('highlight api',function() + local expected_rgb = { background = Screen.colors.Yellow, + foreground = Screen.colors.Red, + special = Screen.colors.Blue, + bold = true, + } + + local expected_cterm = { background = 10, + underline = true, + } + + before_each(function() + clear() + command("hi NewHighlight cterm=underline ctermbg=green guifg=red guibg=yellow guisp=blue gui=bold") + end) + + it("nvim_get_hl_by_id", function() + local hl_id = eval("hlID('NewHighlight')") + eq(expected_cterm, nvim("get_hl_by_id", hl_id, false)) + + hl_id = eval("hlID('NewHighlight')") + eq(expected_rgb, nvim("get_hl_by_id", hl_id, true)) + + local expected_error = 'Invalid highlight id' + -- Assume there is no hl id 30000. + local err, emsg = pcall(meths.get_hl_by_id, 30000, false) + eq(false, err) + eq(expected_error, string.match(emsg, expected_error)) + end) + + it("nvim_get_hl_by_name", function() + local expected_normal = { background = Screen.colors.Yellow, + foreground = Screen.colors.Red } + + -- Test "Normal" hl defaults. + 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)) + + command('hi Normal guifg=red guibg=yellow') + eq(expected_normal, nvim("get_hl_by_name", 'Normal', true)) + + local expected_error = 'Invalid highlight name' + local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight', false) + eq(false, err) + eq(expected_error, string.match(emsg, expected_error)) + end) +end) |