From 1037ce2e461034a20e35ad59969fd05d5ad68b91 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 9 Dec 2023 20:42:00 +0800 Subject: test: avoid repeated screen lines in expected states This is the command invoked repeatedly to make the changes: :%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g --- test/functional/vimscript/match_functions_spec.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'test/functional/vimscript/match_functions_spec.lua') diff --git a/test/functional/vimscript/match_functions_spec.lua b/test/functional/vimscript/match_functions_spec.lua index 9f168c913a..3f3205ba81 100644 --- a/test/functional/vimscript/match_functions_spec.lua +++ b/test/functional/vimscript/match_functions_spec.lua @@ -148,9 +148,7 @@ describe('matchaddpos()', function() }}, funcs.getmatches()) screen:expect([[ ^a{1:b}cdef | - {2:~ }| - {2:~ }| - {2:~ }| + {2:~ }|*3 | ]], {[1] = {foreground = Screen.colors.Red}, [2] = {bold = true, foreground = Screen.colors.Blue1}}) end) -- cgit From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/vimscript/match_functions_spec.lua | 257 ++++++++++++--------- 1 file changed, 151 insertions(+), 106 deletions(-) (limited to 'test/functional/vimscript/match_functions_spec.lua') diff --git a/test/functional/vimscript/match_functions_spec.lua b/test/functional/vimscript/match_functions_spec.lua index 3f3205ba81..8092d140c8 100644 --- a/test/functional/vimscript/match_functions_spec.lua +++ b/test/functional/vimscript/match_functions_spec.lua @@ -10,146 +10,191 @@ local exc_exec = helpers.exc_exec before_each(clear) describe('setmatches()', function() - it('correctly handles case when both group and pattern entries are numbers', - function() + it('correctly handles case when both group and pattern entries are numbers', function() command('hi def link 1 PreProc') - eq(0, funcs.setmatches({{group=1, pattern=2, id=3, priority=4}})) - eq({{ - group='1', - pattern='2', - id=3, - priority=4, - }}, funcs.getmatches()) - eq(0, funcs.setmatches({{group=1, pattern=2, id=3, priority=4, conceal=5}})) - eq({{ - group='1', - pattern='2', - id=3, - priority=4, - conceal='5', - }}, funcs.getmatches()) - eq(0, funcs.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', - }}, funcs.getmatches()) + eq(0, funcs.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4 } })) + eq({ + { + group = '1', + pattern = '2', + id = 3, + priority = 4, + }, + }, funcs.getmatches()) + eq(0, funcs.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4, conceal = 5 } })) + eq({ + { + group = '1', + pattern = '2', + id = 3, + priority = 4, + conceal = '5', + }, + }, funcs.getmatches()) + eq( + 0, + funcs.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', + }, + }, funcs.getmatches()) end) it('does not fail if highlight group is not defined', function() - eq(0, funcs.setmatches{{group=1, pattern=2, id=3, priority=4}}) - eq({{group='1', pattern='2', id=3, priority=4}}, - funcs.getmatches()) - eq(0, funcs.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'}}, - funcs.getmatches()) + eq(0, funcs.setmatches { { group = 1, pattern = 2, id = 3, priority = 4 } }) + eq({ { group = '1', pattern = '2', id = 3, priority = 4 } }, funcs.getmatches()) + eq( + 0, + funcs.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' } }, + funcs.getmatches() + ) end) end) describe('matchadd()', function() - it('correctly works when first two arguments and conceal are numbers at once', - function() + it('correctly works when first two arguments and conceal are numbers at once', function() command('hi def link 1 PreProc') - eq(4, funcs.matchadd(1, 2, 3, 4, {conceal=5})) - eq({{ - group='1', - pattern='2', - priority=3, - id=4, - conceal='5', - }}, funcs.getmatches()) + eq(4, funcs.matchadd(1, 2, 3, 4, { conceal = 5 })) + eq({ + { + group = '1', + pattern = '2', + priority = 3, + id = 4, + conceal = '5', + }, + }, funcs.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])')) + 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, funcs.matchaddpos('PreProc', {1}, 3, 4)) - eq({{ - group='PreProc', - pos1 = {1}, - priority=3, - id=4, - }}, funcs.getmatches()) + eq(4, funcs.matchaddpos('PreProc', { 1 }, 3, 4)) + eq({ + { + group = 'PreProc', + pos1 = { 1 }, + priority = 3, + id = 4, + }, + }, funcs.getmatches()) funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', {{0}, 1}, 3, 4)) - eq({{ - group='PreProc', - pos1 = {1}, - priority=3, - id=4, - }}, funcs.getmatches()) + eq(4, funcs.matchaddpos('PreProc', { { 0 }, 1 }, 3, 4)) + eq({ + { + group = 'PreProc', + pos1 = { 1 }, + priority = 3, + id = 4, + }, + }, funcs.getmatches()) funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', {0, 1}, 3, 4)) - eq({{ - group='PreProc', - pos1 = {1}, - priority=3, - id=4, - }}, funcs.getmatches()) + eq(4, funcs.matchaddpos('PreProc', { 0, 1 }, 3, 4)) + eq({ + { + group = 'PreProc', + pos1 = { 1 }, + priority = 3, + id = 4, + }, + }, funcs.getmatches()) end) it('works with negative numbers', function() command('hi clear PreProc') - eq(4, funcs.matchaddpos('PreProc', {-10, 1}, 3, 4)) - eq({{ - group='PreProc', - pos1 = {1}, - priority=3, - id=4, - }}, funcs.getmatches()) + eq(4, funcs.matchaddpos('PreProc', { -10, 1 }, 3, 4)) + eq({ + { + group = 'PreProc', + pos1 = { 1 }, + priority = 3, + id = 4, + }, + }, funcs.getmatches()) funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', {{-10}, 1}, 3, 4)) - eq({{ - group='PreProc', - pos1 = {1}, - priority=3, - id=4, - }}, funcs.getmatches()) + eq(4, funcs.matchaddpos('PreProc', { { -10 }, 1 }, 3, 4)) + eq({ + { + group = 'PreProc', + pos1 = { 1 }, + priority = 3, + id = 4, + }, + }, funcs.getmatches()) funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', {{2, -1}, 1}, 3, 4)) - eq({{ - group='PreProc', - pos1 = {1}, - priority=3, - id=4, - }}, funcs.getmatches()) + eq(4, funcs.matchaddpos('PreProc', { { 2, -1 }, 1 }, 3, 4)) + eq({ + { + group = 'PreProc', + pos1 = { 1 }, + priority = 3, + id = 4, + }, + }, funcs.getmatches()) funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', {{2, 0, -1}, 1}, 3, 4)) - eq({{ - group='PreProc', - pos1 = {1}, - priority=3, - id=4, - }}, funcs.getmatches()) + eq(4, funcs.matchaddpos('PreProc', { { 2, 0, -1 }, 1 }, 3, 4)) + eq({ + { + group = 'PreProc', + pos1 = { 1 }, + priority = 3, + id = 4, + }, + }, funcs.getmatches()) end) it('works with zero length', function() local screen = Screen.new(40, 5) screen:attach() funcs.setline(1, 'abcdef') command('hi PreProc guifg=Red') - eq(4, funcs.matchaddpos('PreProc', {{1, 2, 0}}, 3, 4)) - eq({{ - group='PreProc', - pos1 = {1, 2, 0}, - priority=3, - id=4, - }}, funcs.getmatches()) - screen:expect([[ + eq(4, funcs.matchaddpos('PreProc', { { 1, 2, 0 } }, 3, 4)) + eq({ + { + group = 'PreProc', + pos1 = { 1, 2, 0 }, + priority = 3, + id = 4, + }, + }, funcs.getmatches()) + screen:expect( + [[ ^a{1:b}cdef | {2:~ }|*3 | - ]], {[1] = {foreground = Screen.colors.Red}, [2] = {bold = true, foreground = Screen.colors.Blue1}}) + ]], + { + [1] = { foreground = Screen.colors.Red }, + [2] = { bold = true, foreground = Screen.colors.Blue1 }, + } + ) end) end) -- cgit From 795f896a5772d5e0795f86642bdf90c82efac45c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 17:59:57 +0000 Subject: test: rename (meths, funcs) -> (api, fn) --- test/functional/vimscript/match_functions_spec.lua | 70 +++++++++++----------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'test/functional/vimscript/match_functions_spec.lua') diff --git a/test/functional/vimscript/match_functions_spec.lua b/test/functional/vimscript/match_functions_spec.lua index 8092d140c8..3db612e472 100644 --- a/test/functional/vimscript/match_functions_spec.lua +++ b/test/functional/vimscript/match_functions_spec.lua @@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen') local eq = helpers.eq local clear = helpers.clear -local funcs = helpers.funcs +local fn = helpers.fn local command = helpers.command local exc_exec = helpers.exc_exec @@ -12,7 +12,7 @@ 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, funcs.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4 } })) + eq(0, fn.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4 } })) eq({ { group = '1', @@ -20,8 +20,8 @@ describe('setmatches()', function() id = 3, priority = 4, }, - }, funcs.getmatches()) - eq(0, funcs.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4, conceal = 5 } })) + }, fn.getmatches()) + eq(0, fn.setmatches({ { group = 1, pattern = 2, id = 3, priority = 4, conceal = 5 } })) eq({ { group = '1', @@ -30,10 +30,10 @@ describe('setmatches()', function() priority = 4, conceal = '5', }, - }, funcs.getmatches()) + }, fn.getmatches()) eq( 0, - funcs.setmatches({ + fn.setmatches({ { group = 1, pos1 = { 2 }, pos2 = { 6 }, id = 3, priority = 4, conceal = 5 }, }) ) @@ -46,21 +46,21 @@ describe('setmatches()', function() priority = 4, conceal = '5', }, - }, funcs.getmatches()) + }, fn.getmatches()) end) it('does not fail if highlight group is not defined', function() - eq(0, funcs.setmatches { { group = 1, pattern = 2, id = 3, priority = 4 } }) - eq({ { group = '1', pattern = '2', id = 3, priority = 4 } }, funcs.getmatches()) + 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, - funcs.setmatches { + 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' } }, - funcs.getmatches() + fn.getmatches() ) end) end) @@ -68,7 +68,7 @@ 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, funcs.matchadd(1, 2, 3, 4, { conceal = 5 })) + eq(4, fn.matchadd(1, 2, 3, 4, { conceal = 5 })) eq({ { group = '1', @@ -77,7 +77,7 @@ describe('matchadd()', function() id = 4, conceal = '5', }, - }, funcs.getmatches()) + }, fn.getmatches()) end) end) @@ -99,7 +99,7 @@ describe('matchaddpos()', function() end) it('works with 0 lnum', function() command('hi clear PreProc') - eq(4, funcs.matchaddpos('PreProc', { 1 }, 3, 4)) + eq(4, fn.matchaddpos('PreProc', { 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -107,9 +107,9 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) - funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', { { 0 }, 1 }, 3, 4)) + }, fn.getmatches()) + fn.matchdelete(4) + eq(4, fn.matchaddpos('PreProc', { { 0 }, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -117,9 +117,9 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) - funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', { 0, 1 }, 3, 4)) + }, fn.getmatches()) + fn.matchdelete(4) + eq(4, fn.matchaddpos('PreProc', { 0, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -127,11 +127,11 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) + }, fn.getmatches()) end) it('works with negative numbers', function() command('hi clear PreProc') - eq(4, funcs.matchaddpos('PreProc', { -10, 1 }, 3, 4)) + eq(4, fn.matchaddpos('PreProc', { -10, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -139,9 +139,9 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) - funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', { { -10 }, 1 }, 3, 4)) + }, fn.getmatches()) + fn.matchdelete(4) + eq(4, fn.matchaddpos('PreProc', { { -10 }, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -149,9 +149,9 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) - funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', { { 2, -1 }, 1 }, 3, 4)) + }, fn.getmatches()) + fn.matchdelete(4) + eq(4, fn.matchaddpos('PreProc', { { 2, -1 }, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -159,9 +159,9 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) - funcs.matchdelete(4) - eq(4, funcs.matchaddpos('PreProc', { { 2, 0, -1 }, 1 }, 3, 4)) + }, fn.getmatches()) + fn.matchdelete(4) + eq(4, fn.matchaddpos('PreProc', { { 2, 0, -1 }, 1 }, 3, 4)) eq({ { group = 'PreProc', @@ -169,14 +169,14 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) + }, fn.getmatches()) end) it('works with zero length', function() local screen = Screen.new(40, 5) screen:attach() - funcs.setline(1, 'abcdef') + fn.setline(1, 'abcdef') command('hi PreProc guifg=Red') - eq(4, funcs.matchaddpos('PreProc', { { 1, 2, 0 } }, 3, 4)) + eq(4, fn.matchaddpos('PreProc', { { 1, 2, 0 } }, 3, 4)) eq({ { group = 'PreProc', @@ -184,7 +184,7 @@ describe('matchaddpos()', function() priority = 3, id = 4, }, - }, funcs.getmatches()) + }, fn.getmatches()) screen:expect( [[ ^a{1:b}cdef | -- cgit