summaryrefslogtreecommitdiff
path: root/lib/lua-repl/t/plugin-repl-tests.lua
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-12-13 16:10:08 +1100
committerjacqueline <me@jacqueline.id.au>2023-12-13 16:10:08 +1100
commit64b106c13e18c33be0f2b0de532054e0ed3f731d (patch)
treeb54b1c90d941bc456b4d51e864970720bdf2d648 /lib/lua-repl/t/plugin-repl-tests.lua
parent5a2f0b08e0e3f20cda977b510b680d5843ae7283 (diff)
downloadtangara-fw-64b106c13e18c33be0f2b0de532054e0ed3f731d.tar.gz
add a cool lua repl
Diffstat (limited to 'lib/lua-repl/t/plugin-repl-tests.lua')
-rw-r--r--lib/lua-repl/t/plugin-repl-tests.lua75
1 files changed, 75 insertions, 0 deletions
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 -- }}}