From e0bdc9b89c336a15e77639eef1c9087808292f36 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 21 May 2021 22:15:31 +0100 Subject: fix(eval): cherry-pick emsg changes from v8.1.0736 v8.1.0736 made some changes for making some emsgs more specific. Includes the change for Test_lambda_fails() in test_lambda.vim. Adjust relevant functionaltests to expect the new emsgs. This patch has been fully ported in my Blob port PR, but it hasn't been merged yet, so just use what we need from it for now. Required for v8.1.1821. --- test/functional/core/startup_spec.lua | 2 +- test/functional/eval/null_spec.lua | 6 +++--- test/functional/provider/clipboard_spec.lua | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) (limited to 'test/functional') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 997e600671..f3ab420603 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -247,9 +247,9 @@ describe('startup', function() [[" -u NONE -i NONE --cmd "set noruler" --cmd "let g:foo = g:bar"')]]) screen:expect([[ ^ | + | Error detected while processing pre-vimrc command line: | E121: Undefined variable: g:bar | - E15: Invalid expression: g:bar | Press ENTER or type command to continue | | ]]) diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index b1ceff9115..f866aca3ed 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -53,7 +53,7 @@ describe('NULL', function() -- Correct behaviour null_expr_test('can be indexed with error message for empty list', 'L[0]', - 'E684: list index out of range: 0\nE15: Invalid expression: L[0]', nil) + 'E684: list index out of range: 0', nil) null_expr_test('can be splice-indexed', 'L[:]', 0, {}) null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) @@ -68,7 +68,7 @@ describe('NULL', function() null_expr_test('can be copied', 'copy(L)', 0, {}) null_expr_test('can be deepcopied', 'deepcopy(L)', 0, {}) null_expr_test('does not crash when indexed', 'L[1]', - 'E684: list index out of range: 1\nE15: Invalid expression: L[1]', nil) + 'E684: list index out of range: 1', nil) null_expr_test('does not crash call()', 'call("arglistid", L)', 0, 0) null_expr_test('does not crash col()', 'col(L)', 0, 0) null_expr_test('does not crash virtcol()', 'virtcol(L)', 0, 0) @@ -135,7 +135,7 @@ describe('NULL', function() end) describe('dict', function() it('does not crash when indexing NULL dict', function() - eq('\nE716: Key not present in Dictionary: "test"\nE15: Invalid expression: v:_null_dict.test', + eq('\nE716: Key not present in Dictionary: "test"', redir_exec('echo v:_null_dict.test')) end) null_expr_test('makes extend error out', 'extend(D, {})', 'E742: Cannot change value of extend() argument', 0) diff --git a/test/functional/provider/clipboard_spec.lua b/test/functional/provider/clipboard_spec.lua index e5e21f11a6..986db96a18 100644 --- a/test/functional/provider/clipboard_spec.lua +++ b/test/functional/provider/clipboard_spec.lua @@ -653,14 +653,12 @@ describe('clipboard (with fake clipboard.vim)', function() '', '', 'E121: Undefined variable: doesnotexist', - 'E15: Invalid expression: doesnotexist', }, 'v'}, eval("g:test_clip['*']")) feed_command(':echo "Howdy!"') eq({{ '', '', 'E121: Undefined variable: doesnotexist', - 'E15: Invalid expression: doesnotexist', '', 'Howdy!', }, 'v'}, eval("g:test_clip['*']")) -- cgit From 287a77ef51a7a12813d3fa6e1c49c595e5951ba5 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 7 Aug 2021 01:28:52 +0100 Subject: vim-patch:8.1.1861: only some assert functions can be used as a method Problem: Only some assert functions can be used as a method. Solution: Allow using most assert functions as a method. https://github.com/vim/vim/commit/24278d2407dfbc8d93eb36593cdd006ff5d86f94 Port tests to assert_spec.lua. --- test/functional/legacy/assert_spec.lua | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'test/functional') diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua index 515d6d91b8..40050f6ce8 100644 --- a/test/functional/legacy/assert_spec.lua +++ b/test/functional/legacy/assert_spec.lua @@ -26,6 +26,14 @@ describe('assert function:', function() call('assert_beeps', 'normal 0') expected_errors({'command did not beep: normal 0'}) end) + + it('can be used as a method', function() + local tmpname = source [[ + call assert_equal(0, 'normal h'->assert_beeps()) + call assert_equal(1, 'normal 0'->assert_beeps()) + ]] + expected_errors({tmpname .. ' line 2: command did not beep: normal 0'}) + end) end) -- assert_equal({expected}, {actual}, [, {msg}]) @@ -133,6 +141,14 @@ describe('assert function:', function() call('assert_false', {}) expected_errors({'Expected False but got []'}) end) + + it('can be used as a method', function() + local tmpname = source [[ + call assert_equal(0, v:false->assert_false()) + call assert_equal(1, 123->assert_false()) + ]] + expected_errors({tmpname .. ' line 2: Expected False but got 123'}) + end) end) -- assert_true({actual}, [, {msg}]) @@ -148,6 +164,14 @@ describe('assert function:', function() eq(1, call('assert_true', 1.5)) expected_errors({'Expected True but got 1.5'}) end) + + it('can be used as a method', function() + local tmpname = source [[ + call assert_equal(0, v:true->assert_true()) + call assert_equal(1, 0->assert_true()) + ]] + expected_errors({tmpname .. ' line 2: Expected True but got 0'}) + end) end) describe('v:errors', function() @@ -223,6 +247,15 @@ describe('assert function:', function() call('assert_match', 'bar.*foo', 'foobar', 'wrong') expected_errors({"wrong: Pattern 'bar.*foo' does not match 'foobar'"}) end) + + it('can be used as a method', function() + local tmpname = source [[ + call assert_equal(1, 'foobar'->assert_match('bar.*foo', 'wrong')) + ]] + expected_errors({ + tmpname .. " line 1: wrong: Pattern 'bar.*foo' does not match 'foobar'" + }) + end) end) -- assert_notmatch({pat}, {text}[, {msg}]) @@ -237,6 +270,13 @@ describe('assert function:', function() call('assert_notmatch', 'foo', 'foobar') expected_errors({"Pattern 'foo' does match 'foobar'"}) end) + + it('can be used as a method', function() + local tmpname = source [[ + call assert_equal(1, 'foobar'->assert_notmatch('foo')) + ]] + expected_errors({tmpname .. " line 1: Pattern 'foo' does match 'foobar'"}) + end) end) -- assert_fails({cmd}, [, {error}]) @@ -267,6 +307,15 @@ describe('assert function:', function() eq(1, eval([[assert_fails('echo', '', 'echo command')]])) expected_errors({'command did not fail: echo command'}) end) + + it('can be used as a method', function() + local tmpname = source [[ + call assert_equal(1, 'echo'->assert_fails('', 'echo command')) + ]] + expected_errors({ + tmpname .. ' line 1: command did not fail: echo command' + }) + end) end) -- assert_inrange({lower}, {upper}, {actual}[, {msg}]) @@ -292,6 +341,15 @@ describe('assert function:', function() eq('Vim(call):E119: Not enough arguments for function: assert_inrange', exc_exec("call assert_inrange(1, 1)")) end) + + it('can be used as a method', function() + local tmpname = source [[ + call assert_equal(0, 5->assert_inrange(5, 7)) + call assert_equal(0, 7->assert_inrange(5, 7)) + call assert_equal(1, 8->assert_inrange(5, 7)) + ]] + expected_errors({tmpname .. ' line 3: Expected range 5 - 7, but got 8'}) + end) end) -- assert_report({msg}) -- cgit From 7925f0b6330c18c9391d02f844cd17b41fbb3d2e Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 7 Aug 2021 17:53:43 +0100 Subject: vim-patch:8.1.1909: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make a few more functions usable as a method. https://github.com/vim/vim/commit/e49fbff384e45dd17fed72321c26937edf6de16b --- test/functional/legacy/assert_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional') diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua index 40050f6ce8..c2b22472bf 100644 --- a/test/functional/legacy/assert_spec.lua +++ b/test/functional/legacy/assert_spec.lua @@ -360,6 +360,13 @@ describe('assert function:', function() command('call remove(v:errors, 0)') expected_empty() end) + + it('can be used as a method', function() + local tmpname = source [[ + call assert_equal(1, 'also wrong'->assert_report()) + ]] + expected_errors({tmpname .. ' line 1: also wrong'}) + end) end) -- assert_exception({cmd}, [, {error}]) -- cgit From da9005af792f7a7eaae98ee9f6499af9a97fd095 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 12 Aug 2021 17:19:05 +0100 Subject: fix(v:lua): fix emsg when calling v:lua directly v:lua expressions are represented using vvlua_partial. As v:lua isn't intended to be called directly, it's given an empty pt_name. Because of this, calling v:lua directly like "v:lua()" will cause "E117: Unknown function: ", with an empty name. Instead, have call_func() show the name "v:lua" in the emsg. --- test/functional/lua/luaeval_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional') diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index 2ec48777fd..263408ad33 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -518,6 +518,7 @@ describe('v:lua', function() eq("Vim:E15: Invalid expression: v:['lua'].foo()", pcall_err(eval, "v:['lua'].foo()")) eq("Vim(call):E461: Illegal variable name: v:['lua']", pcall_err(command, "call v:['lua'].baar()")) + eq("Vim:E117: Unknown function: v:lua", pcall_err(eval, "v:lua()")) eq("Vim(let):E46: Cannot change read-only variable \"v:['lua']\"", pcall_err(command, "let v:['lua'] = 'xx'")) eq("Vim(let):E46: Cannot change read-only variable \"v:lua\"", pcall_err(command, "let v:lua = 'xx'")) -- cgit From b2994e35c9357a8144beaf27e1a8ea4dd133f5d4 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Wed, 11 Aug 2021 13:47:33 +0100 Subject: feat(v:lua): support calling v:lua as a method --- test/functional/lua/luaeval_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/functional') diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index 263408ad33..8ef77faa0f 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -481,6 +481,21 @@ describe('v:lua', function() pcall_err(eval, 'v:lua.mymod.crashy()')) end) + it('works when called as a method', function() + eq(123, eval('110->v:lua.foo(13)')) + eq(true, exec_lua([[return _G.val == nil]])) + + eq(321, eval('300->v:lua.foo(21, "boop")')) + eq("boop", exec_lua([[return _G.val]])) + + eq(NIL, eval('"there"->v:lua.mymod.noisy()')) + eq("hey there", meths.get_current_line()) + eq({5, 10, 15, 20}, eval('[[1], [2, 3], [4]]->v:lua.vim.tbl_flatten()->map({_, v -> v * 5})')) + + eq("Vim:E5108: Error executing lua [string \"\"]:0: attempt to call global 'nonexistent' (a nil value)", + pcall_err(eval, '"huh?"->v:lua.mymod.crashy()')) + end) + it('works in :call', function() command(":call v:lua.mymod.noisy('command')") eq("hey command", meths.get_current_line()) @@ -522,5 +537,11 @@ describe('v:lua', function() eq("Vim(let):E46: Cannot change read-only variable \"v:['lua']\"", pcall_err(command, "let v:['lua'] = 'xx'")) eq("Vim(let):E46: Cannot change read-only variable \"v:lua\"", pcall_err(command, "let v:lua = 'xx'")) + + eq("Vim:E107: Missing parentheses: v:lua.func", pcall_err(eval, "'bad'->v:lua.func")) + eq("Vim:E274: No white space allowed before parenthesis", pcall_err(eval, "'bad'->v:lua.func ()")) + eq("Vim:E107: Missing parentheses: v:lua", pcall_err(eval, "'bad'->v:lua")) + eq("Vim:E117: Unknown function: v:lua", pcall_err(eval, "'bad'->v:lua()")) + eq("Vim:E15: Invalid expression: v:lua.()", pcall_err(eval, "'bad'->v:lua.()")) end) end) -- cgit