From 7a6228d581d4ba49ac26b316362278e180791959 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Sat, 3 Apr 2021 09:18:53 +0600 Subject: Add tests for nvim_set_hl() --- test/functional/api/highlight_spec.lua | 92 ++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 058706718a..04ed22efba 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -158,3 +158,95 @@ describe('API: highlight',function() assert_alive() end) end) + +describe("API: set highlight", function() + local highlight_color = { + fg = tonumber('0xff0000'), + bg = tonumber('0x0032aa'), + ctermfg = 8, + ctermbg = 15, + } + local highlight1 = { + background = highlight_color.bg, + foreground = highlight_color.fg, + bold = true, + italic = true, + } + local highlight2_config = { + ctermbg = highlight_color.ctermbg, + ctermfg = highlight_color.ctermfg, + underline = true, + reverse = true, + } + local highlight2_result = { + background = highlight_color.ctermbg, + foreground = highlight_color.ctermfg, + underline = true, + reverse = true, + } + local highlight3_config = { + background = highlight_color.bg, + foreground = highlight_color.fg, + ctermbg = highlight_color.ctermbg, + ctermfg = highlight_color.ctermfg, + bold = true, + italic = true, + reverse = true, + undercurl = true, + underline = true, + cterm = { + italic = true, + reverse = true, + undercurl = true, + } + } + local highlight3_result_gui = { + background = highlight_color.bg, + foreground = highlight_color.fg, + bold = true, + italic = true, + reverse = true, + undercurl = true, + underline = true, + } + local highlight3_result_cterm = { + background = highlight_color.ctermbg, + foreground = highlight_color.ctermfg, + italic = true, + reverse = true, + undercurl = true, + } + + before_each(function() + _G.ns = meths.get_namespaces().Test_set_hl + if not ns then ns = meths.create_namespace('Test_set_hl') end + meths._set_hl_ns(ns) + end) + + after_each(function() + _G.ns = nil + end) + + it ("can set gui highlight", function() + meths.set_hl(ns, 'Test_hl', highlight1) + eq(highlight1, meths.get_hl_by_name('Test_hl', true)) + end) + + it ("can set cterm highlight", function() + meths.set_hl(ns, 'Test_hl', highlight2_config) + eq(highlight2_result, meths.get_hl_by_name('Test_hl', false)) + end) + + it ("cterm attr defaults to gui attr", function() + meths.set_hl(ns, 'Test_hl', highlight1) + eq({ + bold = true, + italic = true, + }, meths.get_hl_by_name('Test_hl', false)) + end) + it ("can overwrite attr for cterm", function() + 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) +end) -- cgit From f4224a12c039f09e237ac7e5e7db4431747a9b54 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Sat, 3 Apr 2021 10:18:40 +0600 Subject: Fix lualint warnings --- test/functional/api/highlight_spec.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 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 04ed22efba..6f9188d880 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -217,34 +217,36 @@ describe("API: set highlight", function() undercurl = true, } - before_each(function() - _G.ns = meths.get_namespaces().Test_set_hl + local function get_ns() + local ns = meths.get_namespaces().Test_set_hl if not ns then ns = meths.create_namespace('Test_set_hl') end meths._set_hl_ns(ns) - end) - - after_each(function() - _G.ns = nil - end) + return ns + end it ("can set gui highlight", function() + local ns = get_ns() meths.set_hl(ns, 'Test_hl', highlight1) eq(highlight1, meths.get_hl_by_name('Test_hl', true)) end) it ("can set cterm highlight", function() + 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 ("cterm attr defaults to gui attr", function() + local ns = get_ns() meths.set_hl(ns, 'Test_hl', highlight1) eq({ bold = true, italic = true, }, meths.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)) -- cgit From 0559d3f9c6bbcf6110e04a6f831b077e832be879 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Sat, 3 Apr 2021 15:54:34 +0600 Subject: Improvements to tests --- test/functional/api/highlight_spec.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/functional/api/highlight_spec.lua') diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 6f9188d880..21e3094f8e 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -218,12 +218,13 @@ describe("API: set highlight", function() } local function get_ns() - local ns = meths.get_namespaces().Test_set_hl - if not ns then ns = meths.create_namespace('Test_set_hl') end + local ns = meths.create_namespace('Test_set_hl') meths._set_hl_ns(ns) return ns end + before_each(clear) + it ("can set gui highlight", function() local ns = get_ns() meths.set_hl(ns, 'Test_hl', highlight1) -- cgit