Jump to content

Module:Text/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Hike395 (talk | contribs) at 04:00, 10 January 2022 (update tests). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = require('Module:UnitTests')
local Text = require('Module:Text').Text()

function p:testremoveDelimited()
	self:equals('comment',Text.removeDelimited('a<!--comment-->b','<!--','-->'),'ab')
	self:equals('2 comments',Text.removeDelimited(' <!--comment-->hello, world<!--comment 2--> ','<!--','-->'),' hello, world ')
	self:equals('ref',Text.removeDelimited('in foo.<ref name=foo>{{cite web|title=Title|url=https://www.example.com}}</ref>','<ref','</ref>'),'in foo.')
end

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

return p