aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ex_cmds/highlight_spec.lua
blob: 3cb6cc2579c333fce1ce3acf437d757a41e1e0e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')

local eq, command = t.eq, n.command
local clear = n.clear
local eval, exc_exec = n.eval, n.exc_exec
local exec = n.exec
local fn = n.fn
local api = n.api

describe(':highlight', function()
  local screen

  before_each(function()
    clear()
    screen = Screen.new()
    screen:attach()
  end)

  it('invalid color name', function()
    eq(
      'Vim(highlight):E421: Color name or number not recognized: ctermfg=#181818',
      exc_exec('highlight normal ctermfg=#181818')
    )
    eq(
      'Vim(highlight):E421: Color name or number not recognized: ctermbg=#181818',
      exc_exec('highlight normal ctermbg=#181818')
    )
  end)

  it('invalid group name', function()
    eq('Vim(highlight):E411: Highlight group not found: foo', exc_exec('highlight foo'))
  end)

  it('"Normal" foreground with red', function()
    eq('', eval('synIDattr(hlID("Normal"), "fg", "cterm")'))
    command('highlight normal ctermfg=red')
    eq('9', eval('synIDattr(hlID("Normal"), "fg", "cterm")'))
  end)

  it('"Normal" background with red', function()
    eq('', eval('synIDattr(hlID("Normal"), "bg", "cterm")'))
    command('highlight normal ctermbg=red')
    eq('9', eval('synIDattr(hlID("Normal"), "bg", "cterm")'))
  end)

  it('only the last underline style takes effect #22371', function()
    command('highlight NonText gui=underline,undercurl')
    eq('', eval('synIDattr(hlID("NonText"), "underline", "gui")'))
    eq('1', eval('synIDattr(hlID("NonText"), "undercurl", "gui")'))
    command('highlight NonText gui=undercurl,underline')
    eq('', eval('synIDattr(hlID("NonText"), "undercurl", "gui")'))
    eq('1', eval('synIDattr(hlID("NonText"), "underline", "gui")'))
  end)

  it('clear', function()
    api.nvim_set_var('colors_name', 'foo')
    eq(1, fn.exists('g:colors_name'))
    command('hi clear')
    eq(0, fn.exists('g:colors_name'))
    api.nvim_set_var('colors_name', 'foo')
    eq(1, fn.exists('g:colors_name'))
    exec([[
      func HiClear()
        hi clear
      endfunc
    ]])
    fn.HiClear()
    eq(0, fn.exists('g:colors_name'))
  end)
end)