2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2017-12-15 01:38:34 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2016-08-20 12:24:34 -07:00
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local clear = n.clear
|
|
|
|
local fn = n.fn
|
|
|
|
local command = n.command
|
|
|
|
local exc_exec = n.exc_exec
|
2016-08-20 12:24:34 -07:00
|
|
|
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
describe('setmatches()', function()
|
|
|
|
it('correctly handles case when both group and pattern entries are numbers', function()
|
|
|
|
command('hi def link 1 PreProc')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, fn.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4 } }))
|
2016-08-20 12:24:34 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2016-08-20 12:24:34 -07:00
|
|
|
group = '1',
|
|
|
|
pattern = '2',
|
|
|
|
id = 3,
|
|
|
|
priority = 4,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
|
|
|
eq(0, fn.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4, conceal = 5 } }))
|
2016-08-20 12:24:34 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2016-08-20 12:24:34 -07:00
|
|
|
group = '1',
|
|
|
|
pattern = '2',
|
|
|
|
id = 3,
|
|
|
|
priority = 4,
|
|
|
|
conceal = '5',
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
2016-08-20 12:24:34 -07:00
|
|
|
eq(
|
|
|
|
0,
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setmatches({
|
2016-08-20 12:24:34 -07:00
|
|
|
{ group = 1, pos1 = { 2 }, pos2 = { 6 }, id = 3, priority = 4, conceal = 5 },
|
|
|
|
})
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2016-08-20 12:24:34 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2016-08-20 12:24:34 -07:00
|
|
|
group = '1',
|
|
|
|
pos1 = { 2 },
|
|
|
|
pos2 = { 6 },
|
|
|
|
id = 3,
|
|
|
|
priority = 4,
|
|
|
|
conceal = '5',
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
2016-08-20 12:24:34 -07:00
|
|
|
end)
|
2016-08-20 12:25:57 -07:00
|
|
|
|
2021-08-18 05:29:42 -07:00
|
|
|
it('does not fail if highlight group is not defined', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, fn.setmatches { { group = 1, pattern = 2, id = 3, priority = 4 } })
|
|
|
|
eq({ { group = '1', pattern = '2', id = 3, priority = 4 } }, fn.getmatches())
|
2021-08-18 05:29:42 -07:00
|
|
|
eq(
|
|
|
|
0,
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setmatches {
|
2021-08-18 05:29:42 -07:00
|
|
|
{ group = 1, pos1 = { 2 }, pos2 = { 6 }, id = 3, priority = 4, conceal = 5 },
|
2024-01-02 18:09:18 -07:00
|
|
|
}
|
2021-08-18 05:29:42 -07:00
|
|
|
)
|
|
|
|
eq(
|
|
|
|
{ { group = '1', pos1 = { 2 }, pos2 = { 6 }, id = 3, priority = 4, conceal = '5' } },
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.getmatches()
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2016-08-20 12:25:57 -07:00
|
|
|
end)
|
2016-08-20 12:24:34 -07:00
|
|
|
end)
|
2016-09-03 16:25:24 -07:00
|
|
|
|
|
|
|
describe('matchadd()', function()
|
|
|
|
it('correctly works when first two arguments and conceal are numbers at once', function()
|
|
|
|
command('hi def link 1 PreProc')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(4, fn.matchadd(1, 2, 3, 4, { conceal = 5 }))
|
2016-09-03 16:25:24 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2016-09-03 16:25:24 -07:00
|
|
|
group = '1',
|
|
|
|
pattern = '2',
|
|
|
|
priority = 3,
|
|
|
|
id = 4,
|
|
|
|
conceal = '5',
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
2016-09-03 16:25:24 -07:00
|
|
|
end)
|
|
|
|
end)
|
2017-12-15 01:38:34 -07:00
|
|
|
|
|
|
|
describe('matchaddpos()', function()
|
|
|
|
it('errors out on invalid input', function()
|
|
|
|
command('hi clear PreProc')
|
|
|
|
eq(
|
|
|
|
'Vim(let):E5030: Empty list at position 0',
|
|
|
|
exc_exec('let val = matchaddpos("PreProc", [[]])')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2017-12-15 01:38:34 -07:00
|
|
|
eq(
|
|
|
|
'Vim(let):E5030: Empty list at position 1',
|
|
|
|
exc_exec('let val = matchaddpos("PreProc", [1, v:_null_list])')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2017-12-15 01:38:34 -07:00
|
|
|
eq(
|
|
|
|
'Vim(let):E5031: List or number required at position 1',
|
|
|
|
exc_exec('let val = matchaddpos("PreProc", [1, v:_null_dict])')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2017-12-15 01:38:34 -07:00
|
|
|
end)
|
|
|
|
it('works with 0 lnum', function()
|
|
|
|
command('hi clear PreProc')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(4, fn.matchaddpos('PreProc', { 1 }, 3, 4))
|
2017-12-15 01:38:34 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2017-12-15 01:38:34 -07:00
|
|
|
group = 'PreProc',
|
|
|
|
pos1 = { 1 },
|
|
|
|
priority = 3,
|
|
|
|
id = 4,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
|
|
|
fn.matchdelete(4)
|
|
|
|
eq(4, fn.matchaddpos('PreProc', { { 0 }, 1 }, 3, 4))
|
2017-12-15 01:38:34 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2017-12-15 01:38:34 -07:00
|
|
|
group = 'PreProc',
|
|
|
|
pos1 = { 1 },
|
|
|
|
priority = 3,
|
|
|
|
id = 4,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
|
|
|
fn.matchdelete(4)
|
|
|
|
eq(4, fn.matchaddpos('PreProc', { 0, 1 }, 3, 4))
|
2017-12-15 01:38:34 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2017-12-15 01:38:34 -07:00
|
|
|
group = 'PreProc',
|
|
|
|
pos1 = { 1 },
|
|
|
|
priority = 3,
|
|
|
|
id = 4,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
2017-12-15 01:38:34 -07:00
|
|
|
end)
|
|
|
|
it('works with negative numbers', function()
|
|
|
|
command('hi clear PreProc')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(4, fn.matchaddpos('PreProc', { -10, 1 }, 3, 4))
|
2017-12-15 01:38:34 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2017-12-15 01:38:34 -07:00
|
|
|
group = 'PreProc',
|
|
|
|
pos1 = { 1 },
|
|
|
|
priority = 3,
|
|
|
|
id = 4,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
|
|
|
fn.matchdelete(4)
|
|
|
|
eq(4, fn.matchaddpos('PreProc', { { -10 }, 1 }, 3, 4))
|
2017-12-15 01:38:34 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2017-12-15 01:38:34 -07:00
|
|
|
group = 'PreProc',
|
|
|
|
pos1 = { 1 },
|
|
|
|
priority = 3,
|
|
|
|
id = 4,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
|
|
|
fn.matchdelete(4)
|
|
|
|
eq(4, fn.matchaddpos('PreProc', { { 2, -1 }, 1 }, 3, 4))
|
2017-12-15 01:38:34 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2017-12-15 01:38:34 -07:00
|
|
|
group = 'PreProc',
|
|
|
|
pos1 = { 1 },
|
|
|
|
priority = 3,
|
|
|
|
id = 4,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
|
|
|
fn.matchdelete(4)
|
|
|
|
eq(4, fn.matchaddpos('PreProc', { { 2, 0, -1 }, 1 }, 3, 4))
|
2017-12-15 01:38:34 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2017-12-15 01:38:34 -07:00
|
|
|
group = 'PreProc',
|
|
|
|
pos1 = { 1 },
|
|
|
|
priority = 3,
|
|
|
|
id = 4,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
2017-12-15 01:38:34 -07:00
|
|
|
end)
|
|
|
|
it('works with zero length', function()
|
|
|
|
local screen = Screen.new(40, 5)
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.setline(1, 'abcdef')
|
2017-12-15 01:38:34 -07:00
|
|
|
command('hi PreProc guifg=Red')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(4, fn.matchaddpos('PreProc', { { 1, 2, 0 } }, 3, 4))
|
2017-12-15 01:38:34 -07:00
|
|
|
eq({
|
2024-01-02 18:09:18 -07:00
|
|
|
{
|
2017-12-15 01:38:34 -07:00
|
|
|
group = 'PreProc',
|
|
|
|
pos1 = { 1, 2, 0 },
|
|
|
|
priority = 3,
|
|
|
|
id = 4,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2024-01-12 10:59:57 -07:00
|
|
|
}, fn.getmatches())
|
2017-12-15 01:38:34 -07:00
|
|
|
screen:expect(
|
|
|
|
[[
|
|
|
|
^a{1:b}cdef |
|
2023-12-09 05:42:00 -07:00
|
|
|
{2:~ }|*3
|
2017-12-15 01:38:34 -07:00
|
|
|
|
|
|
|
|
]],
|
|
|
|
{
|
|
|
|
[1] = { foreground = Screen.colors.Red },
|
|
|
|
[2] = { bold = true, foreground = Screen.colors.Blue1 },
|
2024-01-02 18:09:18 -07:00
|
|
|
}
|
2017-12-15 01:38:34 -07:00
|
|
|
)
|
|
|
|
end)
|
|
|
|
end)
|