Jump to content

Module:String2/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Tholme (talk | contribs) at 15:08, 12 May 2022. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Unit tests for [[Module:{{ROOTPAGENAME}}]]. Click talk page to run tests.
local p = require('Module:UnitTests')

function p:test_matchAny()
	self:preprocess_equals_sandbox_many('{{#invoke:String2', 'ucfirst', {
        {'[[test]]', '[[Test]]'},
        {'*test', '*Test'},
        {'32nd', '32nd'},
        {'3 ×', '3 ×'},
        {'<li>test</li>', '<li>Test</li>'},
    },{nowiki=1})
    self:preprocess_equals_sandbox_many('{{#invoke:String2','matchAny', {
    	{'123|abc|source=adc 123', '1'},
    	{'123|abc|source=adc 123', '1'},
     },{nowiki=1})
	self:preprocess_equals('{{#invoke:String2|matchAny|123|abc|source=adc 123}}', '1')
	self:preprocess_equals('{{#invoke:String2|matchAny|123|abc|source=adc 124}}', '')
	self:preprocess_equals('{{#invoke:String2|matchAny|123|abc|source=abc 124}}', '2')
	self:preprocess_equals('{{#invoke:String2|ucfirst|test}}', 'Test')
	self:preprocess_equals('{{#invoke:String2|ucfirst|[[test]]}}', '[[Test]]')
	self:preprocess_equals('{{#invoke:String2|ucfirst|32nd infantry}}', '32nd infantry')
	self:preprocess_equals('{{#invoke:String2|ucfirst|3 &times; infantry}}', '3 &times; infantry')
	self:preprocess_equals('{{#invoke:String2/sandbox|ucfirst|test}}', 'Test')
	self:preprocess_equals('{{#invoke:String2/sandbox|ucfirst|[[test]]}}', '[[Test]]')
	self:preprocess_equals('{{#invoke:String2/sandbox|ucfirst|32nd infantry}}', '32nd infantry')
	self:preprocess_equals('{{#invoke:String2/sandbox|ucfirst|3 &times; infantry}}', '3 &times; infantry')
	self:preprocess_equals('{{#invoke:String2|ucfirst|*test}}', '*Test')
	self:preprocess_equals('{{#invoke:String2/sandbox|ucfirst|*test}}', '*Test')
	self:preprocess_equals_sandbox_many('{{#invoke:String2', 'ucfirst', {
        {'[[test]]', '[[Test]]'},
        {'*test', '*Test'},
        {'32nd', '32nd'},
        {'3 &times;', '3 &times;'},
        {'<li>test</li>', '<li>Test</li>'},
    },{nowiki=1})
end

function p:test_sentence()
	self:preprocess_equals_preprocess('{{#invoke:String2|sentence|ThE RaIN In Spain falls <nowiki>mainly</nowiki> on THE PLANE.}}',
		'The rain in spain falls <nowiki>mainly</nowiki> on the plane.',
		{ stripmarker = true })
	self:preprocess_equals_preprocess('{{#invoke:String2|sentence|ThE RaIN In Spain <ref>falls</ref> mainly on THE PLANE.}}',
		'The rain in spain <ref>falls</ref> mainly on the plane.', { stripmarker = true })
end

return p