123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- local t = require('test.testutil')
- local n = require('test.functional.testnvim')()
- local Screen = require('test.functional.ui.screen')
- local eq = t.eq
- local clear = n.clear
- local fn = n.fn
- local command = n.command
- local exc_exec = n.exc_exec
- 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')
- eq(0, fn.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4 } }))
- eq({
- {
- group = '1',
- pattern = '2',
- id = 3,
- priority = 4,
- },
- }, fn.getmatches())
- eq(0, fn.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4, conceal = 5 } }))
- eq({
- {
- group = '1',
- pattern = '2',
- id = 3,
- priority = 4,
- conceal = '5',
- },
- }, fn.getmatches())
- eq(
- 0,
- fn.setmatches({
- { group = 1, pos1 = { 2 }, pos2 = { 6 }, id = 3, priority = 4, conceal = 5 },
- })
- )
- eq({
- {
- group = '1',
- pos1 = { 2 },
- pos2 = { 6 },
- id = 3,
- priority = 4,
- conceal = '5',
- },
- }, fn.getmatches())
- end)
- it('does not fail if highlight group is not defined', function()
- eq(0, fn.setmatches { { group = 1, pattern = 2, id = 3, priority = 4 } })
- eq({ { group = '1', pattern = '2', id = 3, priority = 4 } }, fn.getmatches())
- eq(
- 0,
- fn.setmatches {
- { group = 1, pos1 = { 2 }, pos2 = { 6 }, id = 3, priority = 4, conceal = 5 },
- }
- )
- eq(
- { { group = '1', pos1 = { 2 }, pos2 = { 6 }, id = 3, priority = 4, conceal = '5' } },
- fn.getmatches()
- )
- end)
- end)
- describe('matchadd()', function()
- it('correctly works when first two arguments and conceal are numbers at once', function()
- command('hi def link 1 PreProc')
- eq(4, fn.matchadd(1, 2, 3, 4, { conceal = 5 }))
- eq({
- {
- group = '1',
- pattern = '2',
- priority = 3,
- id = 4,
- conceal = '5',
- },
- }, fn.getmatches())
- end)
- end)
- 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", [[]])')
- )
- eq(
- 'Vim(let):E5030: Empty list at position 1',
- exc_exec('let val = matchaddpos("PreProc", [1, v:_null_list])')
- )
- eq(
- 'Vim(let):E5031: List or number required at position 1',
- exc_exec('let val = matchaddpos("PreProc", [1, v:_null_dict])')
- )
- end)
- it('works with 0 lnum', function()
- command('hi clear PreProc')
- eq(4, fn.matchaddpos('PreProc', { 1 }, 3, 4))
- eq({
- {
- group = 'PreProc',
- pos1 = { 1 },
- priority = 3,
- id = 4,
- },
- }, fn.getmatches())
- fn.matchdelete(4)
- eq(4, fn.matchaddpos('PreProc', { { 0 }, 1 }, 3, 4))
- eq({
- {
- group = 'PreProc',
- pos1 = { 1 },
- priority = 3,
- id = 4,
- },
- }, fn.getmatches())
- fn.matchdelete(4)
- eq(4, fn.matchaddpos('PreProc', { 0, 1 }, 3, 4))
- eq({
- {
- group = 'PreProc',
- pos1 = { 1 },
- priority = 3,
- id = 4,
- },
- }, fn.getmatches())
- end)
- it('works with negative numbers', function()
- command('hi clear PreProc')
- eq(4, fn.matchaddpos('PreProc', { -10, 1 }, 3, 4))
- eq({
- {
- group = 'PreProc',
- pos1 = { 1 },
- priority = 3,
- id = 4,
- },
- }, fn.getmatches())
- fn.matchdelete(4)
- eq(4, fn.matchaddpos('PreProc', { { -10 }, 1 }, 3, 4))
- eq({
- {
- group = 'PreProc',
- pos1 = { 1 },
- priority = 3,
- id = 4,
- },
- }, fn.getmatches())
- fn.matchdelete(4)
- eq(4, fn.matchaddpos('PreProc', { { 2, -1 }, 1 }, 3, 4))
- eq({
- {
- group = 'PreProc',
- pos1 = { 1 },
- priority = 3,
- id = 4,
- },
- }, fn.getmatches())
- fn.matchdelete(4)
- eq(4, fn.matchaddpos('PreProc', { { 2, 0, -1 }, 1 }, 3, 4))
- eq({
- {
- group = 'PreProc',
- pos1 = { 1 },
- priority = 3,
- id = 4,
- },
- }, fn.getmatches())
- end)
- it('works with zero length', function()
- local screen = Screen.new(40, 5)
- fn.setline(1, 'abcdef')
- command('hi PreProc guifg=Red')
- eq(4, fn.matchaddpos('PreProc', { { 1, 2, 0 } }, 3, 4))
- eq({
- {
- group = 'PreProc',
- pos1 = { 1, 2, 0 },
- priority = 3,
- id = 4,
- },
- }, fn.getmatches())
- screen:expect(
- [[
- ^a{1:b}cdef |
- {2:~ }|*3
- |
- ]],
- {
- [1] = { foreground = Screen.colors.Red },
- [2] = { bold = true, foreground = Screen.colors.Blue1 },
- }
- )
- end)
- end)
|