Module:LuaCall/testcases

Diyila Dagbani Wikipedia

Miscellaneous testing moved to Module talk:LuaCall/testcases.

I sincerely hope that no one ever actually uses this[mali mi di yibu sheena n-niŋ]

We don't provide loadstring() because we don't want people trying to embed Lua in pages or templates because that leads to unreadable messes. So this is fun (and impressive) like IOCCC entries, but there's no reason to use this any more than there is to use the old padleft hacks for string functions now that we have Scribunto. BJorsch (WMF) (talk) 18:14, 11 March 2014 (UTC)

I think the point of this is to avoid having to make a bunch of one-line modules (though I would yell about this appearing in an article). Jackmcbarn (talk) 15:48, 14 March 2014 (UTC)

Category:Pages using duplicate arguments in template calls[mali mi di yibu sheena n-niŋ]

I have removed the testcases from Category:Pages using duplicate arguments in template calls. I see no need to permanently test how LUA handles duplicate unnamed/named parameters. Frietjes (talk) 14:24, 24 March 2019 (UTC)


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