Jump to content

Module:String2/testcases: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
 
Line 4: Line 4:
function p:test_sentence()
function p:test_sentence()
self:preprocess_equals_sandbox_many('{{#invoke:String2', 'sentence', {
self:preprocess_equals_sandbox_many('{{#invoke:String2', 'sentence', {
{'*teSt', '\n*Test'},
{'*teSt', '\n*Test'},
{'[[tEst]]', '[[Test]]'},
{'[[tEst]]', '[[Test]]'},
{'[[test|pipeTest]]', '[[test|Pipetest]]'},
{'[[test|pipeTest]]', '[[test|Pipetest]]'},
{'32ND', '32nd'},
{'32ND', '32nd'},
{'3 ×', '3 ×'},
{'3 ×', '3 ×'},
{'<li>TEST</li>', '<li>Test</li>'},
{'<li>TEST</li>', '<li>Test</li>'},
{'1900 &ndash; 2000', '1900 &ndash; 2000'},
{'1900 &ndash; 2000', '1900 &ndash; 2000'},
{'éclair', 'Éclair'},
{'éclair', 'Éclair'},
{'Äpfel', 'Äpfel'},
{'Äpfel', 'Äpfel'},
-- this requires options.stripmarker to be implemented for preprocess_equals_sandbox_many
-- this requires options.stripmarker to be implemented for preprocess_equals_sandbox_many
{'teXT <nowiki>TeXT</nowiki>', 'Text <nowiki>TeXT</nowiki>'},
{'teXT <nowiki>TeXT</nowiki>', 'Text <nowiki>TeXT</nowiki>'},
})
})
end
end
Line 20: Line 20:
function p:test_ucfirst()
function p:test_ucfirst()
self:preprocess_equals_sandbox_many('{{#invoke:String2', 'ucfirst', {
self:preprocess_equals_sandbox_many('{{#invoke:String2', 'ucfirst', {
{'*test', '\n*Test'},
{'*test', '\n*Test'},
{'[[test]]', '[[Test]]'},
{'[[test]]', '[[Test]]'},
{'[[test|pipetest]]', '[[test|Pipetest]]'},
{'[[test|pipetest]]', '[[test|Pipetest]]'},
{'32nd', '32nd'},
{'32nd', '32nd'},
{'3 &times;', '3 &times;'},
{'3 &times;', '3 &times;'},
{'<li>test</li>', '<li>Test</li>'},
{'<li>test</li>', '<li>Test</li>'},
{'1900 &ndash; 2000', '1900 &ndash; 2000'},
{'1900 &ndash; 2000', '1900 &ndash; 2000'},
{'éclair', 'Éclair'},
{'éclair', 'Éclair'},
{'äpfel', 'Äpfel'},
{'äpfel', 'Äpfel'},
{'[[endocrinology]], [[infectious disease (medical specialty)|infectious disease]]', '[[Endocrinology]], [[infectious disease (medical specialty)|infectious disease]]'},
{'[[endocrinology]], [[infectious disease (medical specialty)|infectious disease]]', '[[Endocrinology]], [[infectious disease (medical specialty)|infectious disease]]'},
{'[//example.com ext link test]', '[//example.com ext link test]'},
{'[//example.com ext link test]', '[//example.com ext link test]'},
})
})
end
end


function p:test_matchAny()
function p:test_matchAny()
self:preprocess_equals_sandbox_many('{{#invoke:String2','matchAny', {
self:preprocess_equals_sandbox_many('{{#invoke:String2','matchAny', {
{'123|abc|source=adc 123', '1'},
{'123|abc|source=adc 123', '1'},
{'123|abc|source=adc 124', ''},
{'123|abc|source=adc 124', ''},
{'123|abc|source=abc 124', '2'},
{'123|abc|source=abc 124', '2'},
},{nowiki=1})
},{nowiki=1})
end
end


function p:test_getError()
function p:test_getError()
self:preprocess_equals_sandbox_many('{{#invoke:String2','getError', {
self:preprocess_equals_sandbox_many('{{#invoke:String2','getError', {
{'123', ''},
{'123', ''},
{'error', ''},
{'error', ''},
{'Expression error', ''},
{'Expression error', ''},
{[[text<strong class="error">Expression error: Unrecognized word &quot;california&quot;.</strong>text]], [[<strong class="error">Expression error: Unrecognized word &quot;california&quot;.</strong>]]},
{[[text<strong class="error">Expression error: Unrecognized word &quot;california&quot;.</strong>text]], [[<strong class="error">Expression error: Unrecognized word &quot;california&quot;.</strong>]]},
},{nowiki=1})
},{nowiki=1})
end
end


function p:test_isInteger()
function p:test_isInteger()
self:preprocess_equals_sandbox_many('{{#invoke:String2','isInteger', {
self:preprocess_equals_sandbox_many('{{#invoke:String2','isInteger', {
{'1993', 'true'},
{'1993', 'true'},
{'1993|02|24|08|30', 'true'},
{'1993|02|24|08|30', 'true'},
{'1993|02||08|30|empty=yes', 'true'},
{'1993|02||08|30|empty=yes', 'true'},
{'', 'false'},
{'1993|02| |08|30|empty=yes', 'true'},
{'1993|02||08|30', 'false'},
{'', 'false'},
{'1993|02||08|30', 'false'},
},{nowiki=1})
},{nowiki=1})
end
end



Latest revision as of 12:20, 19 February 2025

-- Unit tests for [[Module:{{ROOTPAGENAME}}]]. Click talk page to run tests.
local p = require('Module:UnitTests')

function p:test_sentence()
	self:preprocess_equals_sandbox_many('{{#invoke:String2', 'sentence', {
		{'*teSt', '\n*Test'},
		{'[[tEst]]', '[[Test]]'},
		{'[[test|pipeTest]]', '[[test|Pipetest]]'},
		{'32ND', '32nd'},
		{'3 &times;', '3 &times;'},
		{'<li>TEST</li>', '<li>Test</li>'},
		{'1900 &ndash; 2000', '1900 &ndash; 2000'},
		{'éclair', 'Éclair'},
		{'Äpfel', 'Äpfel'},
		-- this requires options.stripmarker to be implemented for preprocess_equals_sandbox_many
		{'teXT <nowiki>TeXT</nowiki>', 'Text <nowiki>TeXT</nowiki>'},
	})
end

function p:test_ucfirst()
	self:preprocess_equals_sandbox_many('{{#invoke:String2', 'ucfirst', {
		{'*test', '\n*Test'},
		{'[[test]]', '[[Test]]'},
		{'[[test|pipetest]]', '[[test|Pipetest]]'},
		{'32nd', '32nd'},
		{'3 &times;', '3 &times;'},
		{'<li>test</li>', '<li>Test</li>'},
		{'1900 &ndash; 2000', '1900 &ndash; 2000'},
		{'éclair', 'Éclair'},
		{'äpfel', 'Äpfel'},
		{'[[endocrinology]], [[infectious disease (medical specialty)|infectious disease]]', '[[Endocrinology]], [[infectious disease (medical specialty)|infectious disease]]'},
		{'[//example.com ext link test]', '[//example.com ext link test]'},
	})
end

function p:test_matchAny()
	self:preprocess_equals_sandbox_many('{{#invoke:String2','matchAny', {
		{'123|abc|source=adc 123', '1'},
		{'123|abc|source=adc 124', ''},
		{'123|abc|source=abc 124', '2'},
	},{nowiki=1})
end

function p:test_getError()
	self:preprocess_equals_sandbox_many('{{#invoke:String2','getError', {
		{'123', ''},
		{'error', ''},
		{'Expression error', ''},
		{[[text<strong class="error">Expression error: Unrecognized word &quot;california&quot;.</strong>text]], [[<strong class="error">Expression error: Unrecognized word &quot;california&quot;.</strong>]]},
	},{nowiki=1})
end

function p:test_isInteger()
	self:preprocess_equals_sandbox_many('{{#invoke:String2','isInteger', {
		{'1993', 'true'},
		{'1993|02|24|08|30', 'true'},
		{'1993|02||08|30|empty=yes', 'true'},
		{'1993|02| |08|30|empty=yes', 'true'},
		{'', 'false'},
		{'1993|02||08|30', 'false'},
	},{nowiki=1})
end

return p