Toggle menu
15
236
70
27.5K
Kenshi Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 17:36, 8 March 2025 by Prd (talk | contribs) (Created page with "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:22: foo}}')...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Refer to
Module:Protect



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:22: 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',
		protect(mw.clone)('Foo'),
		'Foo'
	)
	
	self:equals(
		'Default error',
		protect(error)('foo'),
		self.frame:preprocess('{{Error|Error: foo}}')
	)
	
	self:equals(
		'No caught message',
		protect(error)(),
		self.frame:preprocess('{{Error|Error: (no message)}}')
	)
	
	self:equals(
		'Custom errFormat',
		protect(error, 'Failure (%s)')('foo'),
		self.frame:preprocess('{{Error|Failure (foo)}}')
	)
	
	self:equals(
		'Raw errFormat',
		protect(error, {raw = true})('foo'),
		'Error: foo'
	)

	self:equals(
		'Custom raw errFormat',
		protect(error, 'Failure (%s)', {raw = true})('foo'),
		'Failure (foo)'
	)
	
	self:equals(
		'Remove location',
		protect(error)('foo', 3),
		self.frame:preprocess('{{Error|Error: foo}}')
	)
end

return p