Module:Text/testcases

local p = require('Module:UnitTests') local Text = require('Module:Text').Text

-- Tests re-written in Lua from https://de.wikipedia.org/wiki/Wikipedia:Lua/Modul/Text/Test version 198988523

function p:testChar self:equals('nil',Text.char,'') self:equals('3 chars',Text.char({65,104,97}),'Aha') self:equals('rep',Text.char({98,108,97},2),'blabla') self:equals('lenient',Text.char('something',1,true),'') end

function p:testConcatParams self:equals('nil',Text.concatParams,'') self:equals('empty',Text.concatParams({}),'') self:equals('1',Text.concatParams({'A'}),'A') self:equals('3',Text.concatParams({'A','B','C'}),'A|B|C') self:equals('inbetween',Text.concatParams({'A','B','C'},'-'),'A-B-C') self:equals('format',Text.concatParams({'1','2','3'},nil,'%.2f'),'1.00|2.00|3.00') end

function p:testContainsCJK self:equals('nil',Text.containsCJK,false) self:equals('Latin',Text.containsCJK('Draco Dormiens Nunquam Titillandus'),false) self:equals('Russian',Text.containsCJK('Никогда не щекочи спящего дракона'),false) self:equals('Hindi',Text.containsCJK('सोए शेर को न जगाओ'),false) self:equals('Chinese',Text.containsCJK('永远不要惊醒卧龙'),true) self:equals('Japanese',Text.containsCJK('眠っているドラゴンをくすぐることはありません'),true) self:equals('Korean',Text.containsCJK('잠자는 용을 간지럽히지 마십시오'),true) end

function p:testGetPlain self:equals('plain',Text.getPlain('a and b'),'a and b') self:equals('comment',Text.getPlain('a&#x3c;!--comment--&#x3e;b'),'ab') self:equals('2 comments',Text.getPlain(' &#x3c;!--comment--&#x3e;hello, world&#x3c;!--comment 2--&#x3e; '),' hello, world ') self:equals('wikimarkup',Text.getPlain('a &#x3c;nowiki&#x3e;b&#x3c;/nowiki&#x3e; c'),'a b c') self:equals('bold',Text.getPlain("a"),"a") self:equals('italic',Text.getPlain("b"),"b") self:equals('bold and italic',Text.getPlain("a and b"),"a and b") self:equals('nbsp',Text.getPlain("a&#x26;nbsp;and&#x26;nbsp;b"),"a and b") self:equals('weird1',Text.getPlain("a and b"),"a and b") self:equals('weird2',Text.getPlain("a&#x3c;!--I am an unclosed comment"),"a") self:equals('weird3',Text.getPlain("'''unclosed bold"),"unclosed bold") self:equals('mix1',Text.getPlain("&#x3c;!-- hello -- --&#x3e;a&#x26;nbsp;&#x3c;!--world--&#x3e;&#x3c;nowiki&#x3e;b&#x3c;/nowiki&#x3e;"),"a b") self:equals('mix2',Text.getPlain("&#x3c;b&#x3e;a&#x3c;/b&#x3e;&#x26;nbsp;b&#x3c;!-- hello -- world --&#x3e;,&#x26;nbsp;&#x3c;div style='font-size:100%;'&#x3e;c&#x3c;/div&#x3e;"),"a b, c") end

function p:testRemoveDelimited self:equals('comment',Text.removeDelimited('a&#x3c;!--comment--&#x3e;b','&#x3c;!--','--&#x3e;'),'ab') self:equals('2 comments',Text.removeDelimited(' &#x3c;!--comment--&#x3e;hello, world&#x3c;!--comment 2--&#x3e; ','&#x3c;!--','--&#x3e;'),' hello, world ') self:equals('ref',Text.removeDelimited('in foo.&#x3c;ref name=foo&#x3e;&#x3c;/ref&#x3e;','&#x3c;ref','&#x3c;/ref&#x3e;'),'in foo.') end

function p:testSentenceTerminated self:preprocess_equals_sandbox_many('{{#invoke:Text', 'sentenceTerminated', {		{"Hello", ""},		{"(Hello)", ""},		{"Hello.", "1"},		{"„Deutsche“", ""},		{"Hello!", "1"},		{"„Deutsche?“", "1"},		{"\"English?\"", "1"},	}) end

return p