Jump to content

Module:LuaCall/testcases

From Wikipedia, the free encyclopedia

local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

function suite:testmain()
	self:assertResultEquals(
		[=[_test test test test test test test ]=],
		[=[{{#invoke:LuaCall|main|a=test |b=7|string.rep(a,b)}}]=],
		"<code>"..mw.text.nowiki([=[{{#invoke:LuaCall|main|a=test&nbsp;|b=7|string.rep(a,b)}}]=].."</code>"))
	self:assertResultEquals(
		[=[_I. c.a.n.'t. g.e.t. n.o. s.a.t.i.s.f.a.c.t.i.o.n.]=],
		[=[{{#invoke:LuaCall|main|pattern=(%a)|replace=%1.|string=I can't get no satisfaction|mw.ustring.gsub(string,pattern,replace)|reserved_return=1}}]=],
		[=[<code><nowiki>{{#invoke:LuaCall|main|pattern=(%a)|replace=%1.|string=I can't get no satisfaction|mw.ustring.gsub(string,pattern,replace)|reserved_return=1}}</nowiki></code>]=])
	self:assertResultEquals(
		[=[_22]=],
		[=[{{#invoke:LuaCall|main|pattern=(%a)|replace=%1.|string=I can't get no satisfaction|mw.ustring.gsub(string,pattern,replace)|reserved_return=2}}]=],
		[=[<code><nowiki>{{#invoke:LuaCall|main|pattern=(%a)|replace=%1.|string=I can't get no satisfaction|mw.ustring.gsub(string,pattern,replace)|reserved_return=2}}</nowiki></code>]=])
	self:assertResultEquals(
		[=[_2]=],
		[=[{{#invoke:LuaCall|main|value=1.4512|math.ceil(value)}}]=],
		[=[<code><nowiki>{{#invoke:LuaCall|main|value=1.4512|math.ceil(value)}}</nowiki></code>]=])
	self:assertResultEquals(
		[=[_1]=],
		[=[{{#invoke:LuaCall|main|value=1.4512|math.modf(value)}}]=],
		[=[<code><nowiki>{{#invoke:LuaCall|main|value=1.4512|math.modf(value)}}</nowiki></code>]=])
	self:assertResultEquals(
		[=[_0.4512]=],
		[=[{{#invoke:LuaCall|main|value=1.4512|math.modf(value)|reserved_return=2}}]=],
		[=[<code><nowiki>{{#invoke:LuaCall|main|value=1.4512|math.modf(value)|reserved_return=2}}</nowiki></code>]=])
	self:assertResultEquals(
		[=[_181]=],
		[=[{{#invoke:LuaCall|main|value=... that the '''[[Privacy and Civil Liberties Oversight Board report on mass surveillance]]''' recommended against imposing a [[data retention]] requirement on U.S. phone companies?|string.len(value)}}]=],
		[=[<code><nowiki>{{#invoke:LuaCall|main|value=... that the '''[[Privacy and Civil Liberties Oversight Board report on mass surveillance]]''' recommended against imposing a [[data retention]] requirement on U.S. phone companies?|string.len(value)}}</nowiki></code>]=])
	self:assertResultEquals(
		[=[_bc]=],
		[=[{{#invoke:LuaCall|main|value=abcd|start=2|end=3|string.sub(value,start,end)}}]=],
		[=[For comparison with [[n:Template:Evalx]]: <code><nowiki>{{#invoke:LuaCall|main|value=abcd|start=2|end=3|string.sub(value,start,end)}}</nowiki></code>]=])
end

return suite