local p = require('Module:UnitTests')local Text = require('Module:Text/sandbox').Text
-- Tests re-written in Lua from https://de.wikipedia.org/wiki/Wikipedia:Lua/Modul/Text/Test version 198988523
function p:testChar self:equals(,Text.char,) self:equals('{65,104,97}
',Text.char,'Aha') self:equals('{"65",104,97}
',Text.char,'Aha') self:equals('{98,108,97},2
',Text.char(2),'blabla') self:equals('{"something"}
',mw.ustring.match(Text.char,"error"),"error") self:equals('"something",1,true
',Text.char('something',1,true),) self:equals('{7,8,9}
',mw.ustring.match(Text.char,"error"),"error") self:preprocess_equals('','Aha') self:preprocess_equals('','blabla') self:preprocess_equals('',)end
function p:testConcatParams self:equals(,Text.concatParams,) self:equals('{}
',Text.concatParams,) self:equals('A
',Text.concatParams('A'),'A') self:equals('{"A"}
',Text.concatParams,'A') self:equals('{"A","B","C"}
',Text.concatParams,'A|B|C',) self:equals('{"A","B","C"},"-"
',Text.concatParams('-'),'A-B-C') self:equals('{"1","2","3"},nil,"%.2f"
',Text.concatParams(nil,'%.2f'),'1.00|2.00|3.00',) self:preprocess_equals('', '1.00:2.00:3.00')end
function p:testListToText self:equals(,Text.listToText,) self:equals('{}
',Text.listToText,) self:equals('A
',Text.listToText('A'),'A') self:equals('{"A"}
',Text.listToText,'A') self:equals('{"A","B","C"}
',Text.listToText,'A, B and C') self:equals('{"1","2","3"},"%.2f"
',Text.listToText('%.2f'),'1.00, 2.00 and 3.00') self:preprocess_equals('', '1.00, 2.00 and 3.00')end
function p:testContainsCJK local function singleTest(arg, expected) self:equals(''..arg..'
',Text.containsCJK(arg),expected) end self:equals(,Text.containsCJK,false) singleTest('Draco Dormiens Nunquam Titillandus',false) singleTest('Никогда не щекочи спящего дракона',false) singleTest('सोए शेर को न जगाओ',false) singleTest('永远不要惊醒卧龙',true) singleTest('眠っているドラゴンをくすぐることはありません',true) singleTest('잠자는 용을 간지럽히지 마십시오',true)end
function p:testGetPlain local function singleTest(arg, expected) self:equals('<nowiki>'..arg..'</nowiki>
', Text.getPlain(arg),expected) end singleTest('a and b','a and b') singleTest('ab','ab') singleTest(' hello, world ',' hello, world ') singleTest('a b c','a b c') singleTest("a","a") singleTest("b","b") singleTest("a and b","a and b") singleTest("a and b","a and b") singleTest("a and b","a and b") singleTest("aa b","a b") singleTest("a b,
c
","a b, c")end
function p:testRemoveDelimited self:equals('comment',Text.removeDelimited('ab',''),'ab') self:equals('2 comments',Text.removeDelimited(' hello, world ',''),' hello, world ') self:equals('ref',Text.removeDelimited('in foo.[1] ','[2]
function p:testIsLatin local function singleTest(arg,expected) self:equals(''..arg..'
',Text.isLatinRange(arg),expected) end self:equals(,Text.isLatinRange,true) singleTest('abcd',true) singleTest('Ça ira',true) singleTest('α – Ω',false) singleTest('a日本d',false)end
function p:testIsQuote local function singleTest(arg,expected) self:equals(''..arg..'
',Text.isQuote(arg),expected) end self:equals(,Text.isQuote,false) singleTest('"',true) singleTest('日',false) singleTest('abc"',false)end
function p:testQuote self:equals(,Text.quote,'“”') self:equals('abcd
',Text.quote('abcd'),'“abcd”') self:equals('"abcd"
',Text.quote('"abcd"'),'“"abcd"”') self:equals('fr',Text.quote('abcd','fr'),'« abcd »') self:equals('fr2',Text.quote('abcd','fr',2),'‹ abcd ›')end
function p:testQuoteUnquoted self:equals(,Text.quoteUnquoted,) self:equals('abcd
',Text.quoteUnquoted('abcd'),'“abcd”') self:equals('"abcd"
',Text.quoteUnquoted('"abcd"'),'"abcd"') self:equals('fr',Text.quoteUnquoted('abcd','fr'),'« abcd »') self:equals('fr2',Text.quoteUnquoted('abcd','fr',2),'‹ abcd ›')end
function p:testRemoveDiacritics local function singleTest(arg,expected) self:equals(''..arg..'
',Text.removeDiacritics(arg),expected) end self:equals(,Text.removeDiacritics,) singleTest('abcd','abcd') singleTest('âbçdé','abcde') singleTest('a日本d','a日本d')end
function p:testSentenceTerminated local function singleTest(arg,expected) self:equals('<nowiki>'..arg..'</nowiki>
', Text.sentenceTerminated(arg),expected) end singleTest('Hello',false) singleTest('(Hello)',false) singleTest('Hello.',true) singleTest('„Deutsche“',false) singleTest('„Deutsche?“',true) singleTest('"English?"',true) singleTest('Hello!',true)end
function p:testUCFirstAll local function singleTest(arg,expected) self:equals(''..tostring(arg)..'
',Text.ucfirstAll(arg),expected) end self:equals(,Text.ucfirstAll,) singleTest(25,'25') singleTest('Help test me','Help Test Me') singleTest('an der Schönen','An Der Schönen') singleTest('an der Schönen &lauen','An Der Schönen &Lauen') self:equals('HTML ndash',Text.ucfirstAll('an der Schönen &lauen donau - X y z'), 'An Der Schönen &Lauen Donau '..mw.text.decode(' - ',true)..' X Y Z') self:equals('HTML nbsp',Text.ucfirstAll('a b'),'A B') self:equals('many HTML',Text.ucfirstAll("&<> "), '&<> '..mw.text.decode(" "))end
function p:testUprightNonLatin local function singleTest(arg,expected) self:equals(''..arg..'
',Text.uprightNonlatin(arg),expected) end singleTest('abc','abc') singleTest('abc ','abc ') singleTest('Mutsṭafah','Mutsṭafah') singleTest('μm','μm') singleTest('1 α-particle','1 α-particle') singleTest('Method 3α','Method 3α') singleTest('ΣΨΩ',"
function p:testExport self:preprocess_equals('',"") self:preprocess_equals('',"1") self:preprocess_equals('',"") self:preprocess_equals('',"1") self:preprocess_equals('',"") self:preprocess_equals('',"1") self:preprocess_equals('',"") self:preprocess_equals('',"1") self:preprocess_equals('',"a") self:preprocess_equals('',"a") self:preprocess_equals('',"A") self:preprocess_equals('',"a")end
return p