diff options
| author | ZyX <kp-pav@yandex.ru> | 2017-12-03 16:49:30 +0300 | 
|---|---|---|
| committer | ZyX <kp-pav@yandex.ru> | 2017-12-03 16:49:30 +0300 | 
| commit | c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57 (patch) | |
| tree | b7e59c416d1435725c65f8952b6e55c70544d97e /test/functional/api/highlight_spec.lua | |
| parent | 62108c3b0be46936c83f6d4c98b44ceb5e6f77fd (diff) | |
| parent | 27a577586eace687c47e7398845178208cae524a (diff) | |
| download | rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.gz rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.bz2 rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.zip  | |
Merge branch 'master' into s-dash-stdin
Diffstat (limited to 'test/functional/api/highlight_spec.lua')
| -rw-r--r-- | test/functional/api/highlight_spec.lua | 103 | 
1 files changed, 103 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..2297a0760f --- /dev/null +++ b/test/functional/api/highlight_spec.lua @@ -0,0 +1,103 @@ +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, +  } +  local expected_rgb2 = { +    background = Screen.colors.Yellow, +    foreground = Screen.colors.Red, +    special = Screen.colors.Blue, +    bold = true, +    italic = true, +    reverse = true, +    undercurl = true, +    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')") +    -- Test valid id. +    eq(expected_rgb, nvim("get_hl_by_id", hl_id, true)) + +    -- Test invalid id. +    local err, emsg = pcall(meths.get_hl_by_id, 30000, false) +    eq(false, err) +    eq('Invalid highlight id: 30000', string.match(emsg, 'Invalid.*')) + +    -- Test all highlight properties. +    command('hi NewHighlight gui=underline,bold,undercurl,italic,reverse') +    eq(expected_rgb2, nvim("get_hl_by_id", hl_id, true)) + +    -- Test nil argument. +    err, emsg = pcall(meths.get_hl_by_id, { nil }, false) +    eq(false, err) +    eq('Wrong type for argument 1, expecting Integer', +       string.match(emsg, 'Wrong.*')) + +    -- Test 0 argument. +    err, emsg = pcall(meths.get_hl_by_id, 0, false) +    eq(false, err) +    eq('Invalid highlight id: 0', +       string.match(emsg, 'Invalid.*')) + +    -- Test -1 argument. +    err, emsg = pcall(meths.get_hl_by_id, -1, false) +    eq(false, err) +    eq('Invalid highlight id: -1', +       string.match(emsg, 'Invalid.*')) +  end) + +  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(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)) + +    -- Test invalid name. +    local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight', false) +    eq(false, err) +    eq('Invalid highlight name: unknown_highlight', +       string.match(emsg, 'Invalid.*')) + +    -- Test nil argument. +    err, emsg = pcall(meths.get_hl_by_name , { nil }, false) +    eq(false, err) +    eq('Wrong type for argument 1, expecting String', +       string.match(emsg, 'Wrong.*')) + +    -- Test empty string argument. +    err, emsg = pcall(meths.get_hl_by_name , '', false) +    eq(false, err) +    eq('Invalid highlight name: ', +       string.match(emsg, 'Invalid.*')) +  end) +end)  | 
