Modul:StringUtils/testcases

De la Wikipedia, enciclopedia liberă

Documentația acestui modul poate fi creată la Modul:StringUtils/testcases/doc

local p = require('Modul:UnitTests')

function p:test_prependIfMissing()
	self:preprocess_equals("{{#invoke:StringUtils|prependIfMissing|Q123|Q}}", "Q123");
	self:preprocess_equals("{{#invoke:StringUtils|prependIfMissing|123|Q}}", "Q123");
end

function p:test_appendIfMissing()
	self:preprocess_equals("{{#invoke:StringUtils|appendIfMissing|aliale|le}}", "aliale");
	self:preprocess_equals("{{#invoke:StringUtils|appendIfMissing|nio|le}}", "niole");
end
function p:test_capitalize()
	self:preprocess_equals("{{#invoke:StringUtils|capitalize|aliale}}", "Aliale");
	self:preprocess_equals("{{#invoke:StringUtils|capitalize|Alio}}", "Alio");
	self:preprocess_equals("{{#invoke:StringUtils|capitalize|ALIO}}", "ALIO");
end
function p:test_removeStart()
	self:preprocess_equals_many("{{#invoke:StringUtils|removeStart|", "}}", {{'noc|cu', 'noc'}, {'minc|mi', 'nc'}, {'min|min', ''}, {'min|mino', 'min'}, {'|gig', ''}, {'noc|cu|n', 'oc'}})
end
function p:test_removeEnd()
	self:preprocess_equals_many("{{#invoke:StringUtils|removeEnd|", "}}", {{'noc|cu', 'noc'}, {'minc|nc', 'mi'}, {'min|min', ''}, {'min|omin', 'min'}, {'noc|cu|oc', 'n'}})
end
function p:test_startsWith()
	self:preprocess_equals_many("{{#invoke:StringUtils|startsWith|", "}}", {{'noc|no', tostring(true)}, {'noc|noc', tostring(true)}, {'noc|nocu', tostring(false)}, {'noc|mi', tostring(false)}, {'noc|',  tostring(false)}})
end
function p:test_endsWith()
	self:preprocess_equals_many("{{#invoke:StringUtils|endsWith|", "}}", {{'noc|oc', tostring(true)}, {'noc|noc', tostring(true)}, {'noc|unoc', tostring(false)}, {'noc|mi', tostring(false)}, {'noc|',  tostring(false)}})
end
function p:test_substringBefore()
	self:preprocess_equals("{{#invoke:StringUtils|substringBefore|[[Fișier:Groundzero.jpg]]|]]}}", "[[Fișier:Groundzero.jpg")
	self:preprocess_equals("{{#invoke:StringUtils|substringBefore|moromete|e}}", "morom")
end
function p:test_substringAfter()
	self:preprocess_equals("{{#invoke:StringUtils|substringAfter|moromete|m}}", "oromete")
	self:preprocess_equals("{{#invoke:StringUtils|substringAfter|Fișier:Groundzero.jpg|:}}", "Groundzero.jpg")
end
function p:test_defaultString()
	self:preprocess_equals("{{#invoke:StringUtils|defaultString|George|Coșbuc}}", "George")
	self:preprocess_equals("{{#invoke:StringUtils|defaultString||Coșbuc}}", "Coșbuc")
end

function p:test_appendToString()
	self:preprocess_equals("{{#invoke:StringUtils|appendToString|George|Coșbuc}}", "GeorgeCoșbuc")
	self:preprocess_equals("{{#invoke:StringUtils|appendToString||Coșbuc}}", "")
end

function p:test_prependToString()
	self:preprocess_equals("{{#invoke:StringUtils|prependToString|Coșbuc|George}}", "GeorgeCoșbuc")
	self:preprocess_equals("{{#invoke:StringUtils|prependToString||George}}", "")
end

function p:test_encloseString()
	self:preprocess_equals("{{#invoke:StringUtils|encloseString|Gigi|(}}", "(Gigi")
	self:preprocess_equals("{{#invoke:StringUtils|encloseString||(|)}}", "")
	self:preprocess_equals("{{#invoke:StringUtils|encloseString|Gigi|(|)}}", "(Gigi)")
	self:preprocess_equals("{{#invoke:StringUtils|encloseString|Gigi||)}}", "Gigi)")
end

function p:test_stripNamespace()
	self:preprocess_equals("{{#invoke:StringUtils|stripNamespace|Fișier:Groundzero.jpg}}", "Groundzero.jpg")
	self:preprocess_equals("{{#invoke:StringUtils|stripNamespace|Groundzero.jpg}}", "Groundzero.jpg")
end

function p:test_firstValue()
	self:preprocess_equals("{{#invoke:StringUtils|firstValue|Gigi|Bobo}}", "Gigi")
	self:preprocess_equals("{{#invoke:StringUtils|firstValue|||Gigi|Bobo}}", "Gigi")
	self:preprocess_equals("{{#invoke:StringUtils|firstValue}}", "")
	self:preprocess_equals("{{#invoke:StringUtils|firstValue|||}}", "")
end
return p