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/changedtick_spec.lua | 122 ++++++++++++++++--------- 1 file changed, 79 insertions(+), 43 deletions(-) (limited to 'test/functional/vimscript/changedtick_spec.lua') diff --git a/test/functional/vimscript/changedtick_spec.lua b/test/functional/vimscript/changedtick_spec.lua index 8533fac9ec..1ff580e570 100644 --- a/test/functional/vimscript/changedtick_spec.lua +++ b/test/functional/vimscript/changedtick_spec.lua @@ -29,7 +29,7 @@ end describe('b:changedtick', function() -- Ported tests from Vim-8.0.333 - it('increments', function() -- Test_changedtick_increments + it('increments', function() -- Test_changedtick_increments -- New buffer has an empty line, tick starts at 2 eq(2, changedtick()) funcs.setline(1, 'hello') @@ -56,35 +56,55 @@ describe('b:changedtick', function() local ct = changedtick() local ctn = ct + 100500 eq(0, exc_exec('let d = b:')) - eq('Vim(let):E46: Cannot change read-only variable "b:changedtick"', - pcall_err(command, 'let b:changedtick = ' .. ctn)) - eq('Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"', - pcall_err(command, 'let b:["changedtick"] = ' .. ctn)) - eq('Vim(let):E46: Cannot change read-only variable "b:.changedtick"', - pcall_err(command, 'let b:.changedtick = ' .. ctn)) - eq('Vim(let):E46: Cannot change read-only variable "d.changedtick"', - pcall_err(command, 'let d.changedtick = ' .. ctn)) - eq('Key is read-only: changedtick', - pcall_err(curbufmeths.set_var, 'changedtick', ctn)) + eq( + 'Vim(let):E46: Cannot change read-only variable "b:changedtick"', + pcall_err(command, 'let b:changedtick = ' .. ctn) + ) + eq( + 'Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"', + pcall_err(command, 'let b:["changedtick"] = ' .. ctn) + ) + eq( + 'Vim(let):E46: Cannot change read-only variable "b:.changedtick"', + pcall_err(command, 'let b:.changedtick = ' .. ctn) + ) + eq( + 'Vim(let):E46: Cannot change read-only variable "d.changedtick"', + pcall_err(command, 'let d.changedtick = ' .. ctn) + ) + eq('Key is read-only: changedtick', pcall_err(curbufmeths.set_var, 'changedtick', ctn)) - eq('Vim(unlet):E795: Cannot delete variable b:changedtick', - pcall_err(command, 'unlet b:changedtick')) - eq('Vim(unlet):E46: Cannot change read-only variable "b:.changedtick"', - pcall_err(command, 'unlet b:.changedtick')) - eq('Vim(unlet):E46: Cannot change read-only variable "b:["changedtick"]"', - pcall_err(command, 'unlet b:["changedtick"]')) - eq('Vim(unlet):E46: Cannot change read-only variable "d.changedtick"', - pcall_err(command, 'unlet d.changedtick')) - eq('Key is read-only: changedtick', - pcall_err(curbufmeths.del_var, 'changedtick')) + eq( + 'Vim(unlet):E795: Cannot delete variable b:changedtick', + pcall_err(command, 'unlet b:changedtick') + ) + eq( + 'Vim(unlet):E46: Cannot change read-only variable "b:.changedtick"', + pcall_err(command, 'unlet b:.changedtick') + ) + eq( + 'Vim(unlet):E46: Cannot change read-only variable "b:["changedtick"]"', + pcall_err(command, 'unlet b:["changedtick"]') + ) + eq( + 'Vim(unlet):E46: Cannot change read-only variable "d.changedtick"', + pcall_err(command, 'unlet d.changedtick') + ) + eq('Key is read-only: changedtick', pcall_err(curbufmeths.del_var, 'changedtick')) eq(ct, changedtick()) - eq('Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"', - pcall_err(command, 'let b:["changedtick"] += ' .. ctn)) - eq('Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"', - pcall_err(command, 'let b:["changedtick"] -= ' .. ctn)) - eq('Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"', - pcall_err(command, 'let b:["changedtick"] .= ' .. ctn)) + eq( + 'Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"', + pcall_err(command, 'let b:["changedtick"] += ' .. ctn) + ) + eq( + 'Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"', + pcall_err(command, 'let b:["changedtick"] -= ' .. ctn) + ) + eq( + 'Vim(let):E46: Cannot change read-only variable "b:["changedtick"]"', + pcall_err(command, 'let b:["changedtick"] .= ' .. ctn) + ) eq(ct, changedtick()) @@ -99,16 +119,24 @@ describe('b:changedtick', function() eq(0, exc_exec('let d = b:')) eq(0, funcs.islocked('b:changedtick')) eq(0, funcs.islocked('d.changedtick')) - eq('Vim(unlockvar):E940: Cannot lock or unlock variable b:changedtick', - pcall_err(command, 'unlockvar b:changedtick')) - eq('Vim(unlockvar):E46: Cannot change read-only variable "d.changedtick"', - pcall_err(command, 'unlockvar d.changedtick')) + eq( + 'Vim(unlockvar):E940: Cannot lock or unlock variable b:changedtick', + pcall_err(command, 'unlockvar b:changedtick') + ) + eq( + 'Vim(unlockvar):E46: Cannot change read-only variable "d.changedtick"', + pcall_err(command, 'unlockvar d.changedtick') + ) eq(0, funcs.islocked('b:changedtick')) eq(0, funcs.islocked('d.changedtick')) - eq('Vim(lockvar):E940: Cannot lock or unlock variable b:changedtick', - pcall_err(command, 'lockvar b:changedtick')) - eq('Vim(lockvar):E46: Cannot change read-only variable "d.changedtick"', - pcall_err(command, 'lockvar d.changedtick')) + eq( + 'Vim(lockvar):E940: Cannot lock or unlock variable b:changedtick', + pcall_err(command, 'lockvar b:changedtick') + ) + eq( + 'Vim(lockvar):E46: Cannot change read-only variable "d.changedtick"', + pcall_err(command, 'lockvar d.changedtick') + ) eq(0, funcs.islocked('b:changedtick')) eq(0, funcs.islocked('d.changedtick')) end) @@ -118,18 +146,26 @@ describe('b:changedtick', function() end) it('cannot be changed by filter() or map()', function() eq(2, changedtick()) - eq('Vim(call):E795: Cannot delete variable filter() argument', - pcall_err(command, 'call filter(b:, 0)')) - eq('Vim(call):E742: Cannot change value of map() argument', - pcall_err(command, 'call map(b:, 0)')) - eq('Vim(call):E742: Cannot change value of map() argument', - pcall_err(command, 'call map(b:, "v:val")')) + eq( + 'Vim(call):E795: Cannot delete variable filter() argument', + pcall_err(command, 'call filter(b:, 0)') + ) + eq( + 'Vim(call):E742: Cannot change value of map() argument', + pcall_err(command, 'call map(b:, 0)') + ) + eq( + 'Vim(call):E742: Cannot change value of map() argument', + pcall_err(command, 'call map(b:, "v:val")') + ) eq(2, changedtick()) end) it('cannot be remove()d', function() eq(2, changedtick()) - eq('Vim(call):E795: Cannot delete variable remove() argument', - pcall_err(command, 'call remove(b:, "changedtick")')) + eq( + 'Vim(call):E795: Cannot delete variable remove() argument', + pcall_err(command, 'call remove(b:, "changedtick")') + ) eq(2, changedtick()) end) it('does not inherit VAR_FIXED when copying dictionary over', function() -- 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/changedtick_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/vimscript/changedtick_spec.lua') diff --git a/test/functional/vimscript/changedtick_spec.lua b/test/functional/vimscript/changedtick_spec.lua index 1ff580e570..04ebc9cdc9 100644 --- a/test/functional/vimscript/changedtick_spec.lua +++ b/test/functional/vimscript/changedtick_spec.lua @@ -41,7 +41,7 @@ describe('b:changedtick', function() it('is present in b: dictionary', function() eq(2, changedtick()) command('let d = b:') - eq(2, meths.get_var('d').changedtick) + eq(2, meths.nvim_get_var('d').changedtick) end) it('increments at bdel', function() command('new') @@ -142,7 +142,7 @@ describe('b:changedtick', function() end) it('is being completed', function() feed(':echo b:let cmdline=""') - eq('echo b:changedtick', meths.get_var('cmdline')) + eq('echo b:changedtick', meths.nvim_get_var('cmdline')) end) it('cannot be changed by filter() or map()', function() eq(2, changedtick()) -- cgit From 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 13:11:28 +0000 Subject: test: normalise nvim bridge functions - remove helpers.cur*meths - remove helpers.nvim --- test/functional/vimscript/changedtick_spec.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'test/functional/vimscript/changedtick_spec.lua') diff --git a/test/functional/vimscript/changedtick_spec.lua b/test/functional/vimscript/changedtick_spec.lua index 04ebc9cdc9..203c9a22e5 100644 --- a/test/functional/vimscript/changedtick_spec.lua +++ b/test/functional/vimscript/changedtick_spec.lua @@ -10,14 +10,13 @@ local command = helpers.command local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err local exec_capture = helpers.exec_capture -local curbufmeths = helpers.curbufmeths before_each(clear) local function changedtick() - local ct = curbufmeths.get_changedtick() - eq(ct, curbufmeths.get_var('changedtick')) - eq(ct, curbufmeths.get_var('changedtick')) + local ct = meths.nvim_buf_get_changedtick(0) + eq(ct, meths.nvim_buf_get_var(0, 'changedtick')) + eq(ct, meths.nvim_buf_get_var(0, 'changedtick')) eq(ct, eval('b:changedtick')) eq(ct, eval('b:["changedtick"]')) eq(ct, eval('b:.changedtick')) @@ -46,11 +45,11 @@ describe('b:changedtick', function() it('increments at bdel', function() command('new') eq(2, changedtick()) - local bnr = curbufmeths.get_number() + local bnr = meths.nvim_buf_get_number(0) eq(2, bnr) command('bdel') eq(3, funcs.getbufvar(bnr, 'changedtick')) - eq(1, curbufmeths.get_number()) + eq(1, meths.nvim_buf_get_number(0)) end) it('fails to be changed by user', function() local ct = changedtick() @@ -72,7 +71,7 @@ describe('b:changedtick', function() 'Vim(let):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'let d.changedtick = ' .. ctn) ) - eq('Key is read-only: changedtick', pcall_err(curbufmeths.set_var, 'changedtick', ctn)) + eq('Key is read-only: changedtick', pcall_err(meths.nvim_buf_set_var, 0, 'changedtick', ctn)) eq( 'Vim(unlet):E795: Cannot delete variable b:changedtick', @@ -90,7 +89,7 @@ describe('b:changedtick', function() 'Vim(unlet):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'unlet d.changedtick') ) - eq('Key is read-only: changedtick', pcall_err(curbufmeths.del_var, 'changedtick')) + eq('Key is read-only: changedtick', pcall_err(meths.nvim_buf_del_var, 0, 'changedtick')) eq(ct, changedtick()) eq( -- 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/changedtick_spec.lua | 44 +++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'test/functional/vimscript/changedtick_spec.lua') diff --git a/test/functional/vimscript/changedtick_spec.lua b/test/functional/vimscript/changedtick_spec.lua index 203c9a22e5..85928921c5 100644 --- a/test/functional/vimscript/changedtick_spec.lua +++ b/test/functional/vimscript/changedtick_spec.lua @@ -4,8 +4,8 @@ local eq = helpers.eq local eval = helpers.eval local feed = helpers.feed local clear = helpers.clear -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local command = helpers.command local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err @@ -14,14 +14,14 @@ local exec_capture = helpers.exec_capture before_each(clear) local function changedtick() - local ct = meths.nvim_buf_get_changedtick(0) - eq(ct, meths.nvim_buf_get_var(0, 'changedtick')) - eq(ct, meths.nvim_buf_get_var(0, 'changedtick')) + local ct = api.nvim_buf_get_changedtick(0) + eq(ct, api.nvim_buf_get_var(0, 'changedtick')) + eq(ct, api.nvim_buf_get_var(0, 'changedtick')) eq(ct, eval('b:changedtick')) eq(ct, eval('b:["changedtick"]')) eq(ct, eval('b:.changedtick')) - eq(ct, funcs.getbufvar('%', 'changedtick')) - eq(ct, funcs.getbufvar('%', '').changedtick) + eq(ct, fn.getbufvar('%', 'changedtick')) + eq(ct, fn.getbufvar('%', '').changedtick) eq(ct, eval('b:').changedtick) return ct end @@ -31,7 +31,7 @@ describe('b:changedtick', function() it('increments', function() -- Test_changedtick_increments -- New buffer has an empty line, tick starts at 2 eq(2, changedtick()) - funcs.setline(1, 'hello') + fn.setline(1, 'hello') eq(3, changedtick()) eq(0, exc_exec('undo')) -- Somehow undo counts as two changes @@ -40,16 +40,16 @@ describe('b:changedtick', function() it('is present in b: dictionary', function() eq(2, changedtick()) command('let d = b:') - eq(2, meths.nvim_get_var('d').changedtick) + eq(2, api.nvim_get_var('d').changedtick) end) it('increments at bdel', function() command('new') eq(2, changedtick()) - local bnr = meths.nvim_buf_get_number(0) + local bnr = api.nvim_buf_get_number(0) eq(2, bnr) command('bdel') - eq(3, funcs.getbufvar(bnr, 'changedtick')) - eq(1, meths.nvim_buf_get_number(0)) + eq(3, fn.getbufvar(bnr, 'changedtick')) + eq(1, api.nvim_buf_get_number(0)) end) it('fails to be changed by user', function() local ct = changedtick() @@ -71,7 +71,7 @@ describe('b:changedtick', function() 'Vim(let):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'let d.changedtick = ' .. ctn) ) - eq('Key is read-only: changedtick', pcall_err(meths.nvim_buf_set_var, 0, 'changedtick', ctn)) + eq('Key is read-only: changedtick', pcall_err(api.nvim_buf_set_var, 0, 'changedtick', ctn)) eq( 'Vim(unlet):E795: Cannot delete variable b:changedtick', @@ -89,7 +89,7 @@ describe('b:changedtick', function() 'Vim(unlet):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'unlet d.changedtick') ) - eq('Key is read-only: changedtick', pcall_err(meths.nvim_buf_del_var, 0, 'changedtick')) + eq('Key is read-only: changedtick', pcall_err(api.nvim_buf_del_var, 0, 'changedtick')) eq(ct, changedtick()) eq( @@ -107,7 +107,7 @@ describe('b:changedtick', function() eq(ct, changedtick()) - funcs.setline(1, 'hello') + fn.setline(1, 'hello') eq(ct + 1, changedtick()) end) @@ -116,8 +116,8 @@ describe('b:changedtick', function() end) it('fails to unlock b:changedtick', function() eq(0, exc_exec('let d = b:')) - eq(0, funcs.islocked('b:changedtick')) - eq(0, funcs.islocked('d.changedtick')) + eq(0, fn.islocked('b:changedtick')) + eq(0, fn.islocked('d.changedtick')) eq( 'Vim(unlockvar):E940: Cannot lock or unlock variable b:changedtick', pcall_err(command, 'unlockvar b:changedtick') @@ -126,8 +126,8 @@ describe('b:changedtick', function() 'Vim(unlockvar):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'unlockvar d.changedtick') ) - eq(0, funcs.islocked('b:changedtick')) - eq(0, funcs.islocked('d.changedtick')) + eq(0, fn.islocked('b:changedtick')) + eq(0, fn.islocked('d.changedtick')) eq( 'Vim(lockvar):E940: Cannot lock or unlock variable b:changedtick', pcall_err(command, 'lockvar b:changedtick') @@ -136,12 +136,12 @@ describe('b:changedtick', function() 'Vim(lockvar):E46: Cannot change read-only variable "d.changedtick"', pcall_err(command, 'lockvar d.changedtick') ) - eq(0, funcs.islocked('b:changedtick')) - eq(0, funcs.islocked('d.changedtick')) + eq(0, fn.islocked('b:changedtick')) + eq(0, fn.islocked('d.changedtick')) end) it('is being completed', function() feed(':echo b:let cmdline=""') - eq('echo b:changedtick', meths.nvim_get_var('cmdline')) + eq('echo b:changedtick', api.nvim_get_var('cmdline')) end) it('cannot be changed by filter() or map()', function() eq(2, changedtick()) -- cgit