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/input_spec.lua | 96 ++++++++------------------------ 1 file changed, 24 insertions(+), 72 deletions(-) (limited to 'test/functional/vimscript/input_spec.lua') diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index e1179d29cc..b8ac99437d 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -89,9 +89,7 @@ describe('input()', function() command('redraw!') screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:Foo}^ | ]]) end) @@ -100,17 +98,13 @@ describe('input()', function() feed([[:call input(1, 2)]]) screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:1}2^ | ]]) feed('') screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:1}^ | ]]) end) @@ -120,25 +114,19 @@ describe('input()', function() feed([[:echo input(opts)]]) screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:1}2^ | ]]) feed('') screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:1}^ | ]]) feed('') screen:expect([[ ^ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:3} | ]]) end) @@ -148,33 +136,25 @@ describe('input()', function() feed([[:echo inputdialog(opts)]]) screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:Foo>}Bar^ | ]]) command('mode') screen:expect{grid=[[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:Foo>}Bar^ | ]], reset=true} feed('') screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:Foo>}Ba^ | ]]) command('mode') screen:expect{grid=[[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:Foo>}Ba^ | ]], reset=true} end) @@ -183,9 +163,7 @@ describe('input()', function() feed([[:call input({})]]) screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 ^ | ]]) end) @@ -245,9 +223,7 @@ describe('input()', function() feed('(())') screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {RBP1:(}{RBP2:()}{RBP1:)}^ | ]]) end) @@ -294,9 +270,7 @@ describe('inputdialog()', function() command('redraw!') screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:Foo}^ | ]]) end) @@ -305,17 +279,13 @@ describe('inputdialog()', function() feed([[:call inputdialog(1, 2)]]) screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:1}2^ | ]]) feed('') screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:1}^ | ]]) end) @@ -325,25 +295,19 @@ describe('inputdialog()', function() feed([[:echo input(opts)]]) screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:1}2^ | ]]) feed('') screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:1}^ | ]]) feed('') screen:expect([[ ^ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:3} | ]]) end) @@ -353,33 +317,25 @@ describe('inputdialog()', function() feed([[:echo input(opts)]]) screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:Foo>}Bar^ | ]]) command('mode') screen:expect{grid=[[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:Foo>}Bar^ | ]], reset=true} feed('') screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:Foo>}Ba^ | ]]) command('mode') screen:expect{grid=[[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {T:Foo>}Ba^ | ]], reset=true} end) @@ -388,9 +344,7 @@ describe('inputdialog()', function() feed(':echo inputdialog({})') screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 ^ | ]]) end) @@ -441,9 +395,7 @@ describe('inputdialog()', function() feed('(())') screen:expect([[ | - {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {EOB:~ }|*3 {RBP1:(}{RBP2:()}{RBP1:)}^ | ]]) 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/input_spec.lua | 172 ++++++++++++++++--------------- 1 file changed, 91 insertions(+), 81 deletions(-) (limited to 'test/functional/vimscript/input_spec.lua') diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index b8ac99437d..8a634a6700 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -55,14 +55,14 @@ before_each(function() endfunction ]]) screen:set_default_attr_ids({ - EOB={bold = true, foreground = Screen.colors.Blue1}, - T={foreground=Screen.colors.Red}, - RBP1={background=Screen.colors.Red}, - RBP2={background=Screen.colors.Yellow}, - RBP3={background=Screen.colors.Green}, - RBP4={background=Screen.colors.Blue}, - SEP={bold = true, reverse = true}, - CONFIRM={bold = true, foreground = Screen.colors.SeaGreen4}, + EOB = { bold = true, foreground = Screen.colors.Blue1 }, + T = { foreground = Screen.colors.Red }, + RBP1 = { background = Screen.colors.Red }, + RBP2 = { background = Screen.colors.Yellow }, + RBP3 = { background = Screen.colors.Green }, + RBP4 = { background = Screen.colors.Blue }, + SEP = { bold = true, reverse = true }, + CONFIRM = { bold = true, foreground = Screen.colors.SeaGreen4 }, }) end) @@ -110,7 +110,7 @@ describe('input()', function() end) it('allows unequal numeric values when using {opts} dictionary', function() command('echohl Test') - meths.set_var('opts', {prompt=1, default=2, cancelreturn=3}) + meths.set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) feed([[:echo input(opts)]]) screen:expect([[ | @@ -132,7 +132,7 @@ describe('input()', function() end) it('works with redraw', function() command('echohl Test') - meths.set_var('opts', {prompt='Foo>', default='Bar'}) + meths.set_var('opts', { prompt = 'Foo>', default = 'Bar' }) feed([[:echo inputdialog(opts)]]) screen:expect([[ | @@ -140,11 +140,14 @@ describe('input()', function() {T:Foo>}Bar^ | ]]) command('mode') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {EOB:~ }|*3 {T:Foo>}Bar^ | - ]], reset=true} + ]], + reset = true, + } feed('') screen:expect([[ | @@ -152,11 +155,14 @@ describe('input()', function() {T:Foo>}Ba^ | ]]) command('mode') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {EOB:~ }|*3 {T:Foo>}Ba^ | - ]], reset=true} + ]], + reset = true, + } end) it('allows omitting everything with dictionary argument', function() command('echohl Test') @@ -200,22 +206,17 @@ describe('input()', function() eq('DEF2', meths.get_var('var')) end) it('errors out on invalid inputs', function() - eq('Vim(call):E730: Using a List as a String', - exc_exec('call input([])')) - eq('Vim(call):E730: Using a List as a String', - exc_exec('call input("", [])')) - eq('Vim(call):E730: Using a List as a String', - exc_exec('call input("", "", [])')) - eq('Vim(call):E730: Using a List as a String', - exc_exec('call input({"prompt": []})')) - eq('Vim(call):E730: Using a List as a String', - exc_exec('call input({"default": []})')) - eq('Vim(call):E730: Using a List as a String', - exc_exec('call input({"completion": []})')) - eq('Vim(call):E5050: {opts} must be the only argument', - exc_exec('call input({}, "default")')) - eq('Vim(call):E118: Too many arguments for function: input', - exc_exec('call input("prompt> ", "default", "file", "extra")')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call input([])')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call input("", [])')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call input("", "", [])')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"prompt": []})')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"default": []})')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call input({"completion": []})')) + eq('Vim(call):E5050: {opts} must be the only argument', exc_exec('call input({}, "default")')) + eq( + 'Vim(call):E118: Too many arguments for function: input', + exc_exec('call input("prompt> ", "default", "file", "extra")') + ) end) it('supports highlighting', function() command('nnoremap X input({"highlight": "RainBowParens"})[-1]') @@ -291,7 +292,7 @@ describe('inputdialog()', function() end) it('allows unequal numeric values when using {opts} dictionary', function() command('echohl Test') - meths.set_var('opts', {prompt=1, default=2, cancelreturn=3}) + meths.set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) feed([[:echo input(opts)]]) screen:expect([[ | @@ -313,7 +314,7 @@ describe('inputdialog()', function() end) it('works with redraw', function() command('echohl Test') - meths.set_var('opts', {prompt='Foo>', default='Bar'}) + meths.set_var('opts', { prompt = 'Foo>', default = 'Bar' }) feed([[:echo input(opts)]]) screen:expect([[ | @@ -321,11 +322,14 @@ describe('inputdialog()', function() {T:Foo>}Bar^ | ]]) command('mode') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {EOB:~ }|*3 {T:Foo>}Bar^ | - ]], reset=true} + ]], + reset = true, + } feed('') screen:expect([[ | @@ -333,11 +337,14 @@ describe('inputdialog()', function() {T:Foo>}Ba^ | ]]) command('mode') - screen:expect{grid=[[ + screen:expect { + grid = [[ | {EOB:~ }|*3 {T:Foo>}Ba^ | - ]], reset=true} + ]], + reset = true, + } end) it('allows omitting everything with dictionary argument', function() command('echohl Test') @@ -372,22 +379,20 @@ describe('inputdialog()', function() eq('DEF2', meths.get_var('var')) end) it('errors out on invalid inputs', function() - eq('Vim(call):E730: Using a List as a String', - exc_exec('call inputdialog([])')) - eq('Vim(call):E730: Using a List as a String', - exc_exec('call inputdialog("", [])')) - eq('Vim(call):E730: Using a List as a String', - exc_exec('call inputdialog("", "", [])')) - eq('Vim(call):E730: Using a List as a String', - exc_exec('call inputdialog({"prompt": []})')) - eq('Vim(call):E730: Using a List as a String', - exc_exec('call inputdialog({"default": []})')) - eq('Vim(call):E730: Using a List as a String', - exc_exec('call inputdialog({"completion": []})')) - eq('Vim(call):E5050: {opts} must be the only argument', - exc_exec('call inputdialog({}, "default")')) - eq('Vim(call):E118: Too many arguments for function: inputdialog', - exc_exec('call inputdialog("prompt> ", "default", "file", "extra")')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog([])')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog("", [])')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog("", "", [])')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"prompt": []})')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"default": []})')) + eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog({"completion": []})')) + eq( + 'Vim(call):E5050: {opts} must be the only argument', + exc_exec('call inputdialog({}, "default")') + ) + eq( + 'Vim(call):E118: Too many arguments for function: inputdialog', + exc_exec('call inputdialog("prompt> ", "default", "file", "extra")') + ) end) it('supports highlighting', function() command('nnoremap X inputdialog({"highlight": "RainBowParens"})[-1]') @@ -404,84 +409,89 @@ end) describe('confirm()', function() -- oldtest: Test_confirm() it('works', function() - meths.set_option_value('more', false, {}) -- Avoid hit-enter prompt + meths.set_option_value('more', false, {}) -- Avoid hit-enter prompt meths.set_option_value('laststatus', 2, {}) -- screen:expect() calls are needed to avoid feeding input too early - screen:expect({any = '%[No Name%]'}) + screen:expect({ any = '%[No Name%]' }) async_meths.command([[let a = confirm('Press O to proceed')]]) - screen:expect({any = '{CONFIRM:.+: }'}) + screen:expect({ any = '{CONFIRM:.+: }' }) feed('o') - screen:expect({any = '%[No Name%]'}) + screen:expect({ any = '%[No Name%]' }) eq(1, meths.get_var('a')) async_meths.command([[let a = 'Are you sure?'->confirm("&Yes\n&No")]]) - screen:expect({any = '{CONFIRM:.+: }'}) + screen:expect({ any = '{CONFIRM:.+: }' }) feed('y') - screen:expect({any = '%[No Name%]'}) + screen:expect({ any = '%[No Name%]' }) eq(1, meths.get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) - screen:expect({any = '{CONFIRM:.+: }'}) + screen:expect({ any = '{CONFIRM:.+: }' }) feed('n') - screen:expect({any = '%[No Name%]'}) + screen:expect({ any = '%[No Name%]' }) eq(2, meths.get_var('a')) -- Not possible to match Vim's CTRL-C test here as CTRL-C always sets got_int in Nvim. -- confirm() should return 0 when pressing ESC. async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) - screen:expect({any = '{CONFIRM:.+: }'}) + screen:expect({ any = '{CONFIRM:.+: }' }) feed('') - screen:expect({any = '%[No Name%]'}) + screen:expect({ any = '%[No Name%]' }) eq(0, meths.get_var('a')) -- Default choice is returned when pressing . async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) - screen:expect({any = '{CONFIRM:.+: }'}) + screen:expect({ any = '{CONFIRM:.+: }' }) feed('') - screen:expect({any = '%[No Name%]'}) + screen:expect({ any = '%[No Name%]' }) eq(1, meths.get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]]) - screen:expect({any = '{CONFIRM:.+: }'}) + screen:expect({ any = '{CONFIRM:.+: }' }) feed('') - screen:expect({any = '%[No Name%]'}) + screen:expect({ any = '%[No Name%]' }) eq(2, meths.get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]]) - screen:expect({any = '{CONFIRM:.+: }'}) + screen:expect({ any = '{CONFIRM:.+: }' }) feed('') - screen:expect({any = '%[No Name%]'}) + screen:expect({ any = '%[No Name%]' }) eq(0, meths.get_var('a')) -- Test with the {type} 4th argument - for _, type in ipairs({'Error', 'Question', 'Info', 'Warning', 'Generic'}) do + for _, type in ipairs({ 'Error', 'Question', 'Info', 'Warning', 'Generic' }) do async_meths.command(([[let a = confirm('Are you sure?', "&Yes\n&No", 1, '%s')]]):format(type)) - screen:expect({any = '{CONFIRM:.+: }'}) + screen:expect({ any = '{CONFIRM:.+: }' }) feed('y') - screen:expect({any = '%[No Name%]'}) + screen:expect({ any = '%[No Name%]' }) eq(1, meths.get_var('a')) end - eq('Vim(call):E730: Using a List as a String', - pcall_err(command, 'call confirm([])')) - eq('Vim(call):E730: Using a List as a String', - pcall_err(command, 'call confirm("Are you sure?", [])')) - eq('Vim(call):E745: Using a List as a Number', - pcall_err(command, 'call confirm("Are you sure?", "&Yes\n&No\n", [])')) - eq('Vim(call):E730: Using a List as a String', - pcall_err(command, 'call confirm("Are you sure?", "&Yes\n&No\n", 0, [])')) + eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call confirm([])')) + eq( + 'Vim(call):E730: Using a List as a String', + pcall_err(command, 'call confirm("Are you sure?", [])') + ) + eq( + 'Vim(call):E745: Using a List as a Number', + pcall_err(command, 'call confirm("Are you sure?", "&Yes\n&No\n", [])') + ) + eq( + 'Vim(call):E730: Using a List as a String', + pcall_err(command, 'call confirm("Are you sure?", "&Yes\n&No\n", 0, [])') + ) end) - it("shows dialog even if :silent #8788", function() + it('shows dialog even if :silent #8788', function() command("autocmd BufNewFile * call confirm('test')") local function check_and_clear(edit_line) screen:expect([[ | {SEP: }| - ]]..edit_line..[[ + ]] .. edit_line .. [[ {CONFIRM:test} | {CONFIRM:[O]k: }^ | ]]) -- cgit From d33e1da9b7f7e886219cfdd20b9bbfaccdc43be9 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 11:28:20 +0000 Subject: test: do not inject vim module into global helpers --- test/functional/vimscript/input_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/vimscript/input_spec.lua') diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index 8a634a6700..52c28869ff 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -10,7 +10,7 @@ local command = helpers.command local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err local async_meths = helpers.async_meths -local NIL = helpers.NIL +local NIL = vim.NIL local screen -- cgit From c30f2e3182e3b50e7c03932027ac55edfc8ada4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:44:54 +0000 Subject: test: typing for helpers.meths --- test/functional/vimscript/input_spec.lua | 54 ++++++++++++++++---------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'test/functional/vimscript/input_spec.lua') diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index 52c28869ff..2e1d0501cf 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -110,7 +110,7 @@ describe('input()', function() end) it('allows unequal numeric values when using {opts} dictionary', function() command('echohl Test') - meths.set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) + meths.nvim_set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) feed([[:echo input(opts)]]) screen:expect([[ | @@ -132,7 +132,7 @@ describe('input()', function() end) it('works with redraw', function() command('echohl Test') - meths.set_var('opts', { prompt = 'Foo>', default = 'Bar' }) + meths.nvim_set_var('opts', { prompt = 'Foo>', default = 'Bar' }) feed([[:echo inputdialog(opts)]]) screen:expect([[ | @@ -176,34 +176,34 @@ describe('input()', function() it('supports completion', function() feed(':let var = input("", "", "custom,CustomCompl")') feed('') - eq('TEST', meths.get_var('var')) + eq('TEST', meths.nvim_get_var('var')) feed(':let var = input({"completion": "customlist,CustomListCompl"})') feed('') - eq('FOO', meths.get_var('var')) + eq('FOO', meths.nvim_get_var('var')) end) it('supports cancelreturn', function() feed(':let var = input({"cancelreturn": "BAR"})') feed('') - eq('BAR', meths.get_var('var')) + eq('BAR', meths.nvim_get_var('var')) feed(':let var = input({"cancelreturn": []})') feed('') - eq({}, meths.get_var('var')) + eq({}, meths.nvim_get_var('var')) feed(':let var = input({"cancelreturn": v:false})') feed('') - eq(false, meths.get_var('var')) + eq(false, meths.nvim_get_var('var')) feed(':let var = input({"cancelreturn": v:null})') feed('') - eq(NIL, meths.get_var('var')) + eq(NIL, meths.nvim_get_var('var')) end) it('supports default string', function() feed(':let var = input("", "DEF1")') feed('') - eq('DEF1', meths.get_var('var')) + eq('DEF1', meths.nvim_get_var('var')) feed(':let var = input({"default": "DEF2"})') feed('') - eq('DEF2', meths.get_var('var')) + eq('DEF2', meths.nvim_get_var('var')) end) it('errors out on invalid inputs', function() eq('Vim(call):E730: Using a List as a String', exc_exec('call input([])')) @@ -292,7 +292,7 @@ describe('inputdialog()', function() end) it('allows unequal numeric values when using {opts} dictionary', function() command('echohl Test') - meths.set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) + meths.nvim_set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) feed([[:echo input(opts)]]) screen:expect([[ | @@ -314,7 +314,7 @@ describe('inputdialog()', function() end) it('works with redraw', function() command('echohl Test') - meths.set_var('opts', { prompt = 'Foo>', default = 'Bar' }) + meths.nvim_set_var('opts', { prompt = 'Foo>', default = 'Bar' }) feed([[:echo input(opts)]]) screen:expect([[ | @@ -358,25 +358,25 @@ describe('inputdialog()', function() it('supports completion', function() feed(':let var = inputdialog({"completion": "customlist,CustomListCompl"})') feed('') - eq('FOO', meths.get_var('var')) + eq('FOO', meths.nvim_get_var('var')) end) it('supports cancelreturn', function() feed(':let var = inputdialog("", "", "CR1")') feed('') - eq('CR1', meths.get_var('var')) + eq('CR1', meths.nvim_get_var('var')) feed(':let var = inputdialog({"cancelreturn": "BAR"})') feed('') - eq('BAR', meths.get_var('var')) + eq('BAR', meths.nvim_get_var('var')) end) it('supports default string', function() feed(':let var = inputdialog("", "DEF1")') feed('') - eq('DEF1', meths.get_var('var')) + eq('DEF1', meths.nvim_get_var('var')) feed(':let var = inputdialog({"default": "DEF2"})') feed('') - eq('DEF2', meths.get_var('var')) + eq('DEF2', meths.nvim_get_var('var')) end) it('errors out on invalid inputs', function() eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog([])')) @@ -409,8 +409,8 @@ end) describe('confirm()', function() -- oldtest: Test_confirm() it('works', function() - meths.set_option_value('more', false, {}) -- Avoid hit-enter prompt - meths.set_option_value('laststatus', 2, {}) + meths.nvim_set_option_value('more', false, {}) -- Avoid hit-enter prompt + meths.nvim_set_option_value('laststatus', 2, {}) -- screen:expect() calls are needed to avoid feeding input too early screen:expect({ any = '%[No Name%]' }) @@ -418,19 +418,19 @@ describe('confirm()', function() screen:expect({ any = '{CONFIRM:.+: }' }) feed('o') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.get_var('a')) + eq(1, meths.nvim_get_var('a')) async_meths.command([[let a = 'Are you sure?'->confirm("&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('y') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.get_var('a')) + eq(1, meths.nvim_get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('n') screen:expect({ any = '%[No Name%]' }) - eq(2, meths.get_var('a')) + eq(2, meths.nvim_get_var('a')) -- Not possible to match Vim's CTRL-C test here as CTRL-C always sets got_int in Nvim. @@ -439,26 +439,26 @@ describe('confirm()', function() screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) - eq(0, meths.get_var('a')) + eq(0, meths.nvim_get_var('a')) -- Default choice is returned when pressing . async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.get_var('a')) + eq(1, meths.nvim_get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) - eq(2, meths.get_var('a')) + eq(2, meths.nvim_get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) - eq(0, meths.get_var('a')) + eq(0, meths.nvim_get_var('a')) -- Test with the {type} 4th argument for _, type in ipairs({ 'Error', 'Question', 'Info', 'Warning', 'Generic' }) do @@ -466,7 +466,7 @@ describe('confirm()', function() screen:expect({ any = '{CONFIRM:.+: }' }) feed('y') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.get_var('a')) + eq(1, meths.nvim_get_var('a')) end eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call confirm([])')) -- 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/input_spec.lua | 56 ++++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'test/functional/vimscript/input_spec.lua') diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index 2e1d0501cf..6dd22078d6 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen') local eq = helpers.eq local feed = helpers.feed -local meths = helpers.meths +local api = helpers.api local clear = helpers.clear local source = helpers.source local command = helpers.command @@ -110,7 +110,7 @@ describe('input()', function() end) it('allows unequal numeric values when using {opts} dictionary', function() command('echohl Test') - meths.nvim_set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) + api.nvim_set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) feed([[:echo input(opts)]]) screen:expect([[ | @@ -132,7 +132,7 @@ describe('input()', function() end) it('works with redraw', function() command('echohl Test') - meths.nvim_set_var('opts', { prompt = 'Foo>', default = 'Bar' }) + api.nvim_set_var('opts', { prompt = 'Foo>', default = 'Bar' }) feed([[:echo inputdialog(opts)]]) screen:expect([[ | @@ -176,34 +176,34 @@ describe('input()', function() it('supports completion', function() feed(':let var = input("", "", "custom,CustomCompl")') feed('') - eq('TEST', meths.nvim_get_var('var')) + eq('TEST', api.nvim_get_var('var')) feed(':let var = input({"completion": "customlist,CustomListCompl"})') feed('') - eq('FOO', meths.nvim_get_var('var')) + eq('FOO', api.nvim_get_var('var')) end) it('supports cancelreturn', function() feed(':let var = input({"cancelreturn": "BAR"})') feed('') - eq('BAR', meths.nvim_get_var('var')) + eq('BAR', api.nvim_get_var('var')) feed(':let var = input({"cancelreturn": []})') feed('') - eq({}, meths.nvim_get_var('var')) + eq({}, api.nvim_get_var('var')) feed(':let var = input({"cancelreturn": v:false})') feed('') - eq(false, meths.nvim_get_var('var')) + eq(false, api.nvim_get_var('var')) feed(':let var = input({"cancelreturn": v:null})') feed('') - eq(NIL, meths.nvim_get_var('var')) + eq(NIL, api.nvim_get_var('var')) end) it('supports default string', function() feed(':let var = input("", "DEF1")') feed('') - eq('DEF1', meths.nvim_get_var('var')) + eq('DEF1', api.nvim_get_var('var')) feed(':let var = input({"default": "DEF2"})') feed('') - eq('DEF2', meths.nvim_get_var('var')) + eq('DEF2', api.nvim_get_var('var')) end) it('errors out on invalid inputs', function() eq('Vim(call):E730: Using a List as a String', exc_exec('call input([])')) @@ -292,7 +292,7 @@ describe('inputdialog()', function() end) it('allows unequal numeric values when using {opts} dictionary', function() command('echohl Test') - meths.nvim_set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) + api.nvim_set_var('opts', { prompt = 1, default = 2, cancelreturn = 3 }) feed([[:echo input(opts)]]) screen:expect([[ | @@ -314,7 +314,7 @@ describe('inputdialog()', function() end) it('works with redraw', function() command('echohl Test') - meths.nvim_set_var('opts', { prompt = 'Foo>', default = 'Bar' }) + api.nvim_set_var('opts', { prompt = 'Foo>', default = 'Bar' }) feed([[:echo input(opts)]]) screen:expect([[ | @@ -358,25 +358,25 @@ describe('inputdialog()', function() it('supports completion', function() feed(':let var = inputdialog({"completion": "customlist,CustomListCompl"})') feed('') - eq('FOO', meths.nvim_get_var('var')) + eq('FOO', api.nvim_get_var('var')) end) it('supports cancelreturn', function() feed(':let var = inputdialog("", "", "CR1")') feed('') - eq('CR1', meths.nvim_get_var('var')) + eq('CR1', api.nvim_get_var('var')) feed(':let var = inputdialog({"cancelreturn": "BAR"})') feed('') - eq('BAR', meths.nvim_get_var('var')) + eq('BAR', api.nvim_get_var('var')) end) it('supports default string', function() feed(':let var = inputdialog("", "DEF1")') feed('') - eq('DEF1', meths.nvim_get_var('var')) + eq('DEF1', api.nvim_get_var('var')) feed(':let var = inputdialog({"default": "DEF2"})') feed('') - eq('DEF2', meths.nvim_get_var('var')) + eq('DEF2', api.nvim_get_var('var')) end) it('errors out on invalid inputs', function() eq('Vim(call):E730: Using a List as a String', exc_exec('call inputdialog([])')) @@ -409,8 +409,8 @@ end) describe('confirm()', function() -- oldtest: Test_confirm() it('works', function() - meths.nvim_set_option_value('more', false, {}) -- Avoid hit-enter prompt - meths.nvim_set_option_value('laststatus', 2, {}) + api.nvim_set_option_value('more', false, {}) -- Avoid hit-enter prompt + api.nvim_set_option_value('laststatus', 2, {}) -- screen:expect() calls are needed to avoid feeding input too early screen:expect({ any = '%[No Name%]' }) @@ -418,19 +418,19 @@ describe('confirm()', function() screen:expect({ any = '{CONFIRM:.+: }' }) feed('o') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.nvim_get_var('a')) + eq(1, api.nvim_get_var('a')) async_meths.command([[let a = 'Are you sure?'->confirm("&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('y') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.nvim_get_var('a')) + eq(1, api.nvim_get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('n') screen:expect({ any = '%[No Name%]' }) - eq(2, meths.nvim_get_var('a')) + eq(2, api.nvim_get_var('a')) -- Not possible to match Vim's CTRL-C test here as CTRL-C always sets got_int in Nvim. @@ -439,26 +439,26 @@ describe('confirm()', function() screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) - eq(0, meths.nvim_get_var('a')) + eq(0, api.nvim_get_var('a')) -- Default choice is returned when pressing . async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.nvim_get_var('a')) + eq(1, api.nvim_get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) - eq(2, meths.nvim_get_var('a')) + eq(2, api.nvim_get_var('a')) async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) - eq(0, meths.nvim_get_var('a')) + eq(0, api.nvim_get_var('a')) -- Test with the {type} 4th argument for _, type in ipairs({ 'Error', 'Question', 'Info', 'Warning', 'Generic' }) do @@ -466,7 +466,7 @@ describe('confirm()', function() screen:expect({ any = '{CONFIRM:.+: }' }) feed('y') screen:expect({ any = '%[No Name%]' }) - eq(1, meths.nvim_get_var('a')) + eq(1, api.nvim_get_var('a')) end eq('Vim(call):E730: Using a List as a String', pcall_err(command, 'call confirm([])')) -- cgit From b536e0ba37addaea5507b054120e4c1e122c4405 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 15 Jan 2024 16:10:51 +0000 Subject: test: big cleanup followup Followup to 07a7c0ec --- test/functional/vimscript/input_spec.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'test/functional/vimscript/input_spec.lua') diff --git a/test/functional/vimscript/input_spec.lua b/test/functional/vimscript/input_spec.lua index 6dd22078d6..b749d5a7f0 100644 --- a/test/functional/vimscript/input_spec.lua +++ b/test/functional/vimscript/input_spec.lua @@ -414,19 +414,19 @@ describe('confirm()', function() -- screen:expect() calls are needed to avoid feeding input too early screen:expect({ any = '%[No Name%]' }) - async_meths.command([[let a = confirm('Press O to proceed')]]) + async_meths.nvim_command([[let a = confirm('Press O to proceed')]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('o') screen:expect({ any = '%[No Name%]' }) eq(1, api.nvim_get_var('a')) - async_meths.command([[let a = 'Are you sure?'->confirm("&Yes\n&No")]]) + async_meths.nvim_command([[let a = 'Are you sure?'->confirm("&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('y') screen:expect({ any = '%[No Name%]' }) eq(1, api.nvim_get_var('a')) - async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) + async_meths.nvim_command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('n') screen:expect({ any = '%[No Name%]' }) @@ -435,26 +435,26 @@ describe('confirm()', function() -- Not possible to match Vim's CTRL-C test here as CTRL-C always sets got_int in Nvim. -- confirm() should return 0 when pressing ESC. - async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) + async_meths.nvim_command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) eq(0, api.nvim_get_var('a')) -- Default choice is returned when pressing . - async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) + async_meths.nvim_command([[let a = confirm('Are you sure?', "&Yes\n&No")]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) eq(1, api.nvim_get_var('a')) - async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]]) + async_meths.nvim_command([[let a = confirm('Are you sure?', "&Yes\n&No", 2)]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) eq(2, api.nvim_get_var('a')) - async_meths.command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]]) + async_meths.nvim_command([[let a = confirm('Are you sure?', "&Yes\n&No", 0)]]) screen:expect({ any = '{CONFIRM:.+: }' }) feed('') screen:expect({ any = '%[No Name%]' }) @@ -462,7 +462,9 @@ describe('confirm()', function() -- Test with the {type} 4th argument for _, type in ipairs({ 'Error', 'Question', 'Info', 'Warning', 'Generic' }) do - async_meths.command(([[let a = confirm('Are you sure?', "&Yes\n&No", 1, '%s')]]):format(type)) + async_meths.nvim_command( + ([[let a = confirm('Are you sure?', "&Yes\n&No", 1, '%s')]]):format(type) + ) screen:expect({ any = '{CONFIRM:.+: }' }) feed('y') screen:expect({ any = '%[No Name%]' }) @@ -518,7 +520,7 @@ describe('confirm()', function() feed(':call nvim_command("edit x")') check_and_clear(':call nvim_command("edit |\n') - async_meths.command('edit x') + async_meths.nvim_command('edit x') check_and_clear(' |\n') end) end) -- cgit