vim.opt.rtp:prepend(".")
local t = require("test.runner")
local lsp = require("test.lsp")
local b = require("test.buf")
local buf = lsp.open_and_attach("test_files/plugin_mojo_demo.pl")
local function names_contain(names, needle)
for _, n in ipairs(names) do
if n:find(needle, 1, true) then return true end
end
return false
end
local function assert_outline_has(test_name, needle)
local names = lsp.symbol_names(buf)
if not t.ok(test_name, names_contain(names, needle),
"outline missing '" .. needle .. "', got: [" .. table.concat(names, ", ") .. "]")
then return false end
return true
end
t.test("mojo-helpers: outline includes synthesized helpers", function()
local N = "mojo-helpers: outline includes synthesized helpers"
local ok = assert_outline_has(N, "<helper> current_user")
ok = assert_outline_has(N, "<helper> users.create") and ok
ok = assert_outline_has(N, "<helper> users.delete") and ok
ok = assert_outline_has(N, "<helper> admin.users.purge") and ok
if ok then t.pass(N) end
end)
t.test("mojo-helpers: helper sig shows params in outline name", function()
local N = "mojo-helpers: helper sig shows params in outline name"
if assert_outline_has(N, "users.create ($name, $email)") then
t.pass(N)
end
end)
t.test("mojo-routes: ->to('Ctrl#action') becomes a <action> outline entry", function()
local N = "mojo-routes: ->to('Ctrl#action') becomes a <action> outline entry"
local ok = assert_outline_has(N, "<action> Users#list")
ok = assert_outline_has(N, "<action> Users#create") and ok
ok = assert_outline_has(N, "<action> Admin::Dashboard#index") and ok
if ok then t.pass(N) end
end)
t.test("mojo-lite: top-level verbs register routes keyed by path", function()
local N = "mojo-lite: top-level verbs register routes keyed by path"
local ok = assert_outline_has(N, "<route> GET /users/profile")
ok = assert_outline_has(N, "<route> POST /users/profile") and ok
ok = assert_outline_has(N, "<route> ANY /fallback") and ok
if ok then t.pass(N) end
end)
t.test("minion: add_task registers tasks with the callback's signature", function()
local N = "minion: add_task registers tasks with the callback's signature"
local ok = assert_outline_has(N, "<task> send_email ($to, $subject, $body)")
ok = assert_outline_has(N, "<task> resize_image ($path, $width, $height)") and ok
if ok then t.pass(N) end
end)
t.test("minion: enqueue sig help surfaces the registered task's params", function()
local N = "minion: enqueue sig help surfaces the registered task's params"
local line, col = b.find_pos(buf, "enqueue(send_email => ['alice")
if not t.ok(N, line, "couldn't find enqueue site") then return end
local search_col = col + #"enqueue(send_email => ['"
local sig = lsp.signature_label(buf, line, search_col)
if not t.ok(N, sig, "no sig help at enqueue first arg") then return end
if t.ok(N, sig:find("$to", 1, true) ~= nil,
"sig help should mention '$to', got: " .. sig)
then t.pass(N) end
end)
lsp.assert_no_diagnostics(t, buf, {
"'render' is not defined",
"'session' is not defined",
"'redirect_to' is not defined",
"'enqueue_p' is not defined",
"'perform_jobs' is not defined",
"'on' is not defined",
"'emit' is not defined",
}, 5)
t.finish()