Module:Protect/testcases: Difference between revisions

Content deleted Content added
No edit summary
.
 
(15 intermediate revisions by the same user not shown)
Line 1:
local p = require('Module:UnitTests')
local protect = require('Module:Protect')
 
local o = {}
function o.f1(a)
if not a then
error('missing argument')
end
return a
end
 
function o:f2(a)
if not a then
error('missing argument')
end
return a
end
 
function p:test_protect()
self:equals(
'Keep ___location',
protect(error, {removeLocation = false})('foo', 3),
self.frame:preprocess('{{Error|Error: Module:Protect/testcases:4922: foo}}')
)
 
self:equals(
'.',
protect(o.f1)('Foo'),
'Foo'
)
self:equals(
'.',
protect(o.f1)(o, 'Foo'),
o
)
self:equals(
':',
protect(o.f2)('Foo'),
self.frame:preprocess('{{Error|Error: missing argument}}')
)
self:equals(
':',
protect(o.f2)(o, 'Foo'),
'Foo'
)
protect(o.f2)
protect(o.f2)
local a = o.f2
local b = o.f2
 
self:equals(
'Success',
Line 43 ⟶ 93:
protect(error)('foo', 3),
self.frame:preprocess('{{Error|Error: foo}}')
)
 
self:equals(
'Keep ___location',
protect(error, {removeLocation = false})('foo', 3),
self.frame:preprocess('{{Error|Error: Module:Protect/testcases:49: foo}}')
)
end