From 64b106c13e18c33be0f2b0de532054e0ed3f731d Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 13 Dec 2023 16:10:08 +1100 Subject: add a cool lua repl --- lib/lua-repl/t/plugin-repl-tests.lua | 75 ++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 lib/lua-repl/t/plugin-repl-tests.lua (limited to 'lib/lua-repl/t/plugin-repl-tests.lua') diff --git a/lib/lua-repl/t/plugin-repl-tests.lua b/lib/lua-repl/t/plugin-repl-tests.lua new file mode 100644 index 00000000..b3aa7665 --- /dev/null +++ b/lib/lua-repl/t/plugin-repl-tests.lua @@ -0,0 +1,75 @@ +-- vim:foldmethod=marker +local r = require 'repl' -- we don't call it 'repl' so we don't shadow + -- repl in the plugin environment +pcall(require, 'luarocks.loader') +require 'Test.More' +local utils = require 'test-utils' + +plan(5) + +local clone = r:clone() + +do -- basic tests {{{ + local with_plugin = clone:clone() + + function with_plugin:foo() + end + + local line_no + + local _, err = pcall(function() + with_plugin:loadplugin(function() + line_no = utils.next_line_number() + function repl:foo() + end + end) + end) + + like(err, string.format("%d: The 'foo' method already exists", line_no)) + + with_plugin:loadplugin(function() + function repl:bar() + return 17 + end + end) + + is(with_plugin:bar(), 17) + + with_plugin:loadplugin(function() + repl.baz = 18 + end) + + is(with_plugin.baz, 18) +end -- }}} + +do -- conflict tests {{{ + local clone = r:clone() + local line_no + + clone:loadplugin(function() + function repl:foo() + end + end) + + local _, err = pcall(function() + clone:loadplugin(function() + line_no = utils.next_line_number() + function repl:foo() + end + end) + end) + + like(err, tostring(line_no) .. ": The 'foo' method already exists") +end -- }}} + +do -- proxy tests {{{ + local clone = r:clone() + + clone:loadplugin(function() + features = 'foo' + end) + + clone:loadplugin(function() + ok(repl:hasfeature 'foo') + end) +end -- }}} -- cgit v1.2.3