Jump to content

Module:Error/testcases: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Not an example
cleanup tests
Line 3: Line 3:


function p:test_error()
function p:test_error()
self:preprocess_equals_sandbox_many('{{#invoke:Error', 'error', {
-- Minimal parameter input
-- Minimal parameter input
{'', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error}}', '{{Error}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error}}', '{{Error}}', {nowiki = 'yes'})
{'', '<strong class="error"></strong>', {nowiki = 'yes'}},
{' ', '<strong class="error"> </strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|}}', '{{Error|}}')
{'&#x20', '<strong class="error">&#x20</strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error| }}', '{{Error| }}') -- space &#x20;
{'{{!}}', '<strong class="error">|</strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|{{!}}}}', '{{Error|{{!}}}}')
{'|tag=p', '<p class="error"></p>', {nowiki = 'yes'}},
self:preprocess_equals_preprocess('{{#invoke:Error|error|{{!}}tag=p}}', '{{Error|{{!}}tag=p}}')
{'|message=', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|message=}}', '{{Error|message=}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|message=}}', '{{Error|message=}}', {nowiki = 'yes'})
{'|message=', '<strong class="error"></strong>', {nowiki = 'yes'}},
{'|message=|tag=p', '<p class="error"></p>', {nowiki = 'yes'}},
self:preprocess_equals_preprocess('{{#invoke:Error|error|message=|tag=p}}', '{{Error|message=|tag=p}}')
{'|1', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|1=}}', '{{Error|1=}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|1=}}', '{{Error|1=}}', {nowiki = 'yes'})
{'|1=', '<strong class="error"></strong>', {nowiki = 'yes'}},
{'|1=|tag=p', '<p class="error"></p>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|1=|tag=p}}', '{{Error|1=|tag=p}}')


-- Plain message
-- Plain message
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message}}', '{{Error|Example error message}}')
{'|Example error message', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error| Example error message }}', '{{Error| Example error message }}')
{'| Example error message ', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|message=Example error message}}', '{{Error|message=Example error message}}')
{'|message=Example error message', '<strong class="error">Example error message</strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|message = Example error message }}', '{{Error|message = Example error message }}')
{'|message = Example error message ', '<strong class="error">Example error message</strong>'},

-- tag
-- tag
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=p}}', '{{Error|Example error message|tag=p}}')
{'|Example error message|tag=p', '<p class="error"></p>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|tag=p}}', '{{Error|tag=p}}') -- no message
{'|tag=p', '<p class="error"></p>'}, -- no message
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message| tag = p}}', '{{Error|Example error message| tag = p}}', {nowiki = 'yes'})
{'|Example error message| tag = p', '<p class="error"></p>', {nowiki = 'yes'}},
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=div}}', '{{Error|Example error message|tag=div}}')
{'|Example error message|tag=div', '<div class="error"></div>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=div}}', '{{Error|Example error message|tag=div}}')
{'|Example error message|tag=div', '<div class="error"></div>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=span}}', '{{Error|Example error message|tag=span}}')
{'|Example error message|tag=span', '<span class="error"></span>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=adsf}}', '{{Error|Example error message|tag=asdf}}')
{'|Example error message|tag=adsf', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=strong}}', '{{Error|Example error message|tag=strong}}')
{'|Example error message|tag=strong', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=&#x0000;}}', '{{Error|Example error message|tag=&#x0000;}}') -- ASCII nul
{'|Example error message|tag=&#x0000;', '<strong class="error"></strong>'}, -- ASCII nul
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag= }}', '{{Error|Example error message|tag= }}') -- nbsp
{'|Example error message|tag= ', '<strong class="error"></strong>'}, -- nbsp
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag={{!}}}}', '{{Error|Example error message|tag={{!}}}}')
{'|Example error message|tag={{!}}', '<strong class="error"></strong>'},

-- Use numbered parameter
-- Use numbered parameter
self:preprocess_equals_preprocess('{{#invoke:Error|error|1=Example error message}}', '{{Error|1=Example error message}}')
{'|1=Example error message', '<strong class="error">Example error message</strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|1= Example error message }}', '{{Error|1= Example error message }}')
{'|1= Example error message ', '<strong class="error">Example error message</strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example = message}}', '{{Error|Example = message}}')
{'|Example = message', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|1= Example = message }}', '{{Error|1= Example = message }}')
{'|1= Example = message ', '<strong class="error">Example = message</strong>'},
-- More extreme input options
self:preprocess_equals_preprocess('{{#invoke:Error|error| }}', '{{Error| }}') -- nbsp
self:preprocess_equals_preprocess('{{#invoke:Error|error|<br/>}}', '{{Error|<br/>}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|\n}}', '{{Error|\n}}', {nowiki = 'yes'})
self:preprocess_equals_preprocess('{{#invoke:Error|error|&#x0000;}}', '{{Error|&#x0000;}}') -- ASCII nul


-- Tricky input options
self:preprocess_equals_preprocess('{{#invoke:Error|error|0}}', '{{Error|0}}') -- nbsp
self:preprocess_equals_preprocess('{{#invoke:Error|error|false}}', '{{Error|false}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|tag=tag}}', '{{Error|tag=tag}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|1}}', '{{Error|1}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|true}}', '{{Error|true}}')
end

function p:test_error_sandbox()
-- Minimal parameter input
self:preprocess_equals_preprocess('{{#invoke:Error|error}}', '{{Error/sandbox}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error}}', '{{Error/sandbox}}', {nowiki = 'yes'})
self:preprocess_equals_preprocess('{{#invoke:Error|error|}}', '{{Error/sandbox|}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error| }}', '{{Error/sandbox| }}') -- space &#x20;
self:preprocess_equals_preprocess('{{#invoke:Error|error|{{!}}}}', '{{Error/sandbox|{{!}}}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|{{!}}tag=p}}', '{{Error/sandbox|{{!}}tag=p}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|message=}}', '{{Error/sandbox|message=}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|message=}}', '{{Error/sandbox|message=}}', {nowiki = 'yes'})
self:preprocess_equals_preprocess('{{#invoke:Error|error|message=|tag=p}}', '{{Error/sandbox|message=|tag=p}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|1=}}', '{{Error/sandbox|1=}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|1=}}', '{{Error/sandbox|1=}}', {nowiki = 'yes'})
self:preprocess_equals_preprocess('{{#invoke:Error|error|1=|tag=p}}', '{{Error/sandbox|1=|tag=p}}')

-- Plain message
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message}}', '{{Error/sandbox|Example error message}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error| Example error message }}', '{{Error/sandbox| Example error message }}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|message=Example error message}}', '{{Error/sandbox|message=Example error message}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|message = Example error message }}', '{{Error/sandbox|message = Example error message }}')
-- tag
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=p}}', '{{Error/sandbox|Example error message|tag=p}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|tag=p}}', '{{Error/sandbox|tag=p}}') -- no message
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message| tag = p}}', '{{Error/sandbox|Example error message| tag = p}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=div}}', '{{Error/sandbox|Example error message|tag=div}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=div}}', '{{Error/sandbox|Example error message|tag=div}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=span}}', '{{Error/sandbox|Example error message|tag=span}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=adsf}}', '{{Error/sandbox|Example error message|tag=asdf}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=strong}}', '{{Error/sandbox|Example error message|tag=strong}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag=&#x0000;}}', '{{Error/sandbox|Example error message|tag=&#x0000;}}') -- ASCII nul
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag= }}', '{{Error/sandbox|Example error message|tag= }}') -- nbsp
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example error message|tag={{!}}}}', '{{Error/sandbox|Example error message|tag={{!}}}}')
-- Use numbered parameter
self:preprocess_equals_preprocess('{{#invoke:Error|error|1=Example error message}}', '{{Error/sandbox|1=Example error message}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|1= Example error message }}', '{{Error/sandbox|1= Example error message }}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|Example = message}}', '{{Error/sandbox|Example = message}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|1= Example = message }}', '{{Error/sandbox|1= Example = message }}')
-- More extreme input options
-- More extreme input options
{'| ', '<strong class="error"></strong>'}, -- nbsp
self:preprocess_equals_preprocess('{{#invoke:Error|error| }}', '{{Error/sandbox| }}') -- nbsp
{'|<br/>', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|<br/>}}', '{{Error/sandbox|<br/>}}')
self:preprocess_equals_preprocess('{{#invoke:Error|error|\n}}', '{{Error/sandbox|\n}}', {nowiki = 'yes'})
{'|\n', '<strong class="error"></strong>', {nowiki = 'yes'}},
self:preprocess_equals_preprocess('{{#invoke:Error|error|&#x0000;}}', '{{Error/sandbox|&#x0000;}}') -- ASCII nul
{'|&#x0000;', '<strong class="error"></strong>'}, -- ASCII nul


-- Tricky input options
-- Tricky input options
{'|0', '<strong class="error"></strong>'}, -- nbsp
self:preprocess_equals_preprocess('{{#invoke:Error|error|0}}', '{{Error/sandbox|0}}')
{'|false', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|false}}', '{{Error/sandbox|false}}')
{'|tag=tag', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|tag=tag}}', '{{Error/sandbox|tag=tag}}', {nowiki = 'yes'})
{'|1', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|1}}', '{{Error/sandbox|1}}')
{'|true', '<strong class="error"></strong>'},
self:preprocess_equals_preprocess('{{#invoke:Error|error|true}}', '{{Error/sandbox|true}}')
}, {nowiki=1})
end
end



Revision as of 17:41, 23 March 2022

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

function p:test_error()
	self:preprocess_equals_sandbox_many('{{#invoke:Error', 'error', {
    -- Minimal parameter input
		{'', '<strong class="error"></strong>'},
		{'', '<strong class="error"></strong>', {nowiki = 'yes'}},
		{' ', '<strong class="error"> </strong>'},
		{'&#x20', '<strong class="error">&#x20</strong>'},
		{'{{!}}', '<strong class="error">|</strong>'},
		{'|tag=p', '<p class="error"></p>', {nowiki = 'yes'}},
		{'|message=', '<strong class="error"></strong>'},
		{'|message=', '<strong class="error"></strong>', {nowiki = 'yes'}},
		{'|message=|tag=p', '<p class="error"></p>', {nowiki = 'yes'}},
		{'|1', '<strong class="error"></strong>'},
		{'|1=', '<strong class="error"></strong>', {nowiki = 'yes'}},
		{'|1=|tag=p', '<p class="error"></p>'},

    -- Plain message
		{'|Example error message', '<strong class="error"></strong>'},
		{'|  Example error message  ', '<strong class="error"></strong>'},
		{'|message=Example error message', '<strong class="error">Example error message</strong>'},
		{'|message =  Example error message  ', '<strong class="error">Example error message</strong>'},

    -- tag
		{'|Example error message|tag=p', '<p class="error"></p>'},
		{'|tag=p', '<p class="error"></p>'}, -- no message
		{'|Example error message| tag = p', '<p class="error"></p>', {nowiki = 'yes'}},
		{'|Example error message|tag=div', '<div class="error"></div>'},
		{'|Example error message|tag=div', '<div class="error"></div>'},
		{'|Example error message|tag=span', '<span class="error"></span>'},
		{'|Example error message|tag=adsf', '<strong class="error"></strong>'},
		{'|Example error message|tag=strong', '<strong class="error"></strong>'},
		{'|Example error message|tag=&#x0000;', '<strong class="error"></strong>'}, -- ASCII nul
		{'|Example error message|tag= ', '<strong class="error"></strong>'}, -- nbsp
		{'|Example error message|tag={{!}}', '<strong class="error"></strong>'},

    -- Use numbered parameter
		{'|1=Example error message', '<strong class="error">Example error message</strong>'},
		{'|1=  Example error message  ', '<strong class="error">Example error message</strong>'},
		{'|Example = message', '<strong class="error"></strong>'},
		{'|1=  Example = message  ', '<strong class="error">Example = message</strong>'},

    -- More extreme input options
		{'| ', '<strong class="error"></strong>'}, -- nbsp
		{'|<br/>', '<strong class="error"></strong>'},
		{'|\n', '<strong class="error"></strong>', {nowiki = 'yes'}},
		{'|&#x0000;', '<strong class="error"></strong>'}, -- ASCII nul

    -- Tricky input options
		{'|0', '<strong class="error"></strong>'}, -- nbsp
		{'|false', '<strong class="error"></strong>'},
		{'|tag=tag', '<strong class="error"></strong>'},
		{'|1', '<strong class="error"></strong>'},
		{'|true', '<strong class="error"></strong>'},
	}, {nowiki=1})
end

return p