Module:WikitextParser/testcases

local W = require( 'Module:WikitextParser' ) local testpage = mw.title.new( 'Module:WikitextParser/testpage' ):getContent local ScribuntoUnit = require( 'Module:ScribuntoUnit' ) local Suite = ScribuntoUnit:new

function Suite:testLead self:assertEquals( , W.getLead(  ) ) self:assertEquals( '', W.getLead( '==b==' ) ) self:assertEquals( 'a', W.getLead( 'a' ) ) self:assertEquals( 'a', W.getLead( 'a', 'a\n==b==' ) ) self:assertEquals( 'This test page interacts with Module:WikitextParser/testcases.', W.getLead( testpage ) ) end

function Suite:testSection self:assertEquals( nil, W.getSection( 'a', 'a' ) ) self:assertEquals( '', W.getSection( '==a==', 'a' ) ) self:assertEquals( 'b', W.getSection( '==a==\nb', 'a' ) ) self:assertEquals( 'b', W.getSection( '==a==\nb\n==c==\nd', 'a' ) ) self:assertEquals( 'b', W.getSection( '==a==\nb\n==a==\nd', 'a' ) ) self:assertEquals( 'b\n===c===\nd', W.getSection( '==a==\nb\n===c===\nd', 'a' ) ) self:assertEquals( 'd', W.getSection( '==a==\nb\n===c===\nd', 'c' ) ) self:assertEquals( 'a\n===Subsection===\nb', W.getSection( testpage, 'Section' ) ) self:assertEquals( 'b', W.getSection( testpage, 'Subsection' ) ) end

function Suite:testSectionTag self:assertEquals( nil, W.getSectionTag( 'a', 'a' ) ) self:assertEquals( nil, W.getSectionTag( 'a c', 'a' ) ) self:assertEquals( '', W.getSectionTag( 'a c', 'b' ) ) self:assertEquals( 'c', W.getSectionTag( 'a c d', 'b' ) ) self:assertEquals( '', W.getSectionTag( testpage, 'a' ) ) self:assertEquals( 'b', W.getSectionTag( testpage, 'b' ) ) self:assertEquals( '{|\n!c\n|}', W.getSectionTag( testpage, 'c' ) ) self:assertEquals( nil, W.getSectionTag( testpage, 'd' ) ) end

function Suite:testSections self:assertDeepEquals( {}, W.getSections( '' ) ) self:assertDeepEquals( {}, W.getSections( 'a' ) ) self:assertDeepEquals( { ['a']='' }, W.getSections( '==a==' ) ) self:assertDeepEquals( { ['b']='' }, W.getSections( 'a\n==b==' ) ) self:assertDeepEquals( { ['a']=, ['b']= }, W.getSections( '==a==\n==b==' ) ) self:assertDeepEquals( { ['a']='b' }, W.getSections( '==a==\nb' ) ) self:assertDeepEquals( { ['b']='c' }, W.getSections( 'a\n==b==\nc' ) ) self:assertDeepEquals( { ['b']='c', ['d']='e' }, W.getSections( 'a\n==b==\nc\n===d===\ne' ) ) end

function Suite:testLists self:assertDeepEquals( {}, W.getLists( '' ) ) self:assertDeepEquals( {}, W.getLists( 'a' ) ) self:assertDeepEquals( { '*a' }, W.getLists( '*a' ) ) self:assertDeepEquals( { '*a\n*b' }, W.getLists( '*a\n*b' ) ) self:assertDeepEquals( { '*b\n*c' }, W.getLists( 'a\n*b\n*c\nd' ) ) self:assertDeepEquals( { '*b\n*c', '#e\n#f' }, W.getLists( 'a\n*b\n*c\nd\n#e\n#f\ng' ) ) self:assertDeepEquals( {		'*b\n*c',		'#e\n#f',		'*c\n*d',		'#h\n#i',		'*c\n*d',		'#h\n#i',	}, W.getLists( testpage ) ) end

function Suite:testParagraphs self:assertDeepEquals( {}, W.getParagraphs( '' ) ) self:assertDeepEquals( {}, W.getParagraphs( '' ) ) self:assertDeepEquals( {}, W.getParagraphs( '' ) ) self:assertDeepEquals( {}, W.getParagraphs( '\n\n' ) ) self:assertDeepEquals( {}, W.getParagraphs( '\n\n\n\n' ) ) self:assertDeepEquals( { 'a' }, W.getParagraphs( 'a' ) ) self:assertDeepEquals( { 'a' }, W.getParagraphs( 'a' ) ) self:assertDeepEquals( { 'b' }, W.getParagraphs( 'b' ) ) self:assertDeepEquals( { 'a' }, W.getParagraphs( 'a\n\n' ) ) self:assertDeepEquals( { 'b' }, W.getParagraphs( '\n\nb' ) ) self:assertDeepEquals( { 'b' }, W.getParagraphs( 'b' ) ) self:assertDeepEquals( { 'a', 'b', 'c' }, W.getParagraphs( 'a\n\nb\n\nc' ) ) self:assertDeepEquals( { 'a', 'c' }, W.getParagraphs( 'a\n\n\n\nc' ) ) self:assertDeepEquals( {		'X1',		' X3 ',	}, W.getParagraphs( W.getSection( testpage, 'Paragraphs' ) ) ) end

function Suite:testTemplates self:assertDeepEquals( {}, W.getTemplates( 'a' ) ) self:assertDeepEquals( {  }, W.getTemplates(  ) ) self:assertDeepEquals( { '' }, W.getTemplates( 'ac' ) ) self:assertDeepEquals( {  }, W.getTemplates(  ) ) self:assertDeepEquals( {  }, W.getTemplates(  ) ) self:assertDeepEquals( { ,  }, W.getTemplates( 'ace' ) ) self:assertDeepEquals( { ,  }, W.getTemplates( 'ace' ) ) self:assertDeepEquals( {  }, W.getTemplates(  ) ) self:assertDeepEquals( {		,		,		,		,		,		,		,		,		,		,		''	}, W.getTemplates( testpage ) ) end

function Suite:testTemplate self:assertEquals( , W.getTemplate( , 'a' ) ) self:assertEquals( , W.getTemplate( , 'a' ) ) self:assertEquals( , W.getTemplate( , 'A' ) ) self:assertEquals( '', W.getTemplate( testpage, 'Infobox' ) ) end

function Suite:testParameters self:assertDeepEquals( { [1]='b' }, W.getParameters( '' ) ) --self:assertDeepEquals( { [1]='b' }, W.getParameters( '' ) ) self:assertDeepEquals( { [1]='b',['c']='1' }, W.getParameters( '' ) ) self:assertDeepEquals( { [1]='b',['c']='d' }, W.getParameters( '' ) ) self:assertDeepEquals( { ['b']='c' }, W.getParameters( '' ) ) self:assertDeepEquals( { ['b']='c', ['d']='e' }, W.getParameters( '' ) ) end

function Suite:testTags self:assertDeepEquals( {}, W.getTags( 'a' ) ) self:assertDeepEquals( { ' a' }, W.getTags( ' a' ) ) self:assertDeepEquals( { ' ' }, W.getTags( '  ' ) ) self:assertDeepEquals( { ' ' }, W.getTags( 'a  b' ) ) self:assertDeepEquals( { ' a ' }, W.getTags( ' a ' ) ) self:assertDeepEquals( { ' b ' }, W.getTags( 'a b c' ) ) self:assertDeepEquals( { ' a' }, W.getTags( ' a' ) ) self:assertDeepEquals( { ' b ' }, W.getTags( ' b ' ) ) self:assertDeepEquals( { '   ', '  ' }, W.getTags( '    ' ) ) self:assertDeepEquals( { ' b c d ', ' c ' }, W.getTags( 'a b c d e' ) ) self:assertDeepEquals( { '  a   ', '  a  ', ' a ' }, W.getTags( '   a   ' ) ) self:assertDeepEquals( {		'', 	}, W.getGalleries( testpage ) ) end

function Suite:testReferences self:assertDeepEquals( {}, W.getReferences( 'a' ) ) self:assertDeepEquals( { ' ' }, W.getReferences( ' ' ) ) self:assertDeepEquals( { ' ' }, W.getReferences( 'a c' ) ) self:assertDeepEquals( { ' ', ' ' }, W.getReferences( 'a c ' ) ) self:assertDeepEquals( { ' ', ' ' }, W.getReferences( 'a d ' ) ) self:assertDeepEquals( {		' ', 		' ', 		' ', 		' ', 		' ', 		' ', 		' ', 	}, W.getReferences( testpage ) ) end

function Suite:testTables self:assertDeepEquals( {}, W.getTables( 'a' ) ) self:assertDeepEquals( { '{|\n!b\n|}' }, W.getTables( 'a\n{|\n!b\n|}\nc' ) ) self:assertDeepEquals( { '{|\n!b\n|}', '{|\n|d\n|}', '{|id="e"\n|e\n|}' }, W.getTables( 'a\n{|\n!b\n|}\nc\n{|\n|d\n|}\n{|id="e"\n|e\n|}f' ) ) self:assertDeepEquals( {		'{|\n!b\n|}', 		'{|\n|d\n|}', 		'{|id="e"\n|e\n|}', 		'{|\n!c\n|}', 		'{|\n|X2\n|}', 		'{|\n|e\n|}', 		'{|\n|k\n|}', 		'{|\n|e\n|}', 		'{|\n|k\n|}', 	}, W.getTables( testpage ) ) end

function Suite:testLinks self:assertDeepEquals( {}, W.getLinks( 'a' ) ) self:assertDeepEquals( { 'a' }, W.getLinks( 'a' ) ) self:assertDeepEquals( { 'a|b' }, W.getLinks( 'a|b' ) ) self:assertDeepEquals( { 'b' }, W.getLinks( 'abc' ) ) self:assertDeepEquals( { 'b', 'd' }, W.getLinks( 'abcde' ) ) self:assertDeepEquals( {		'Module:WikitextParser/testcases', 		'link', 		, 		, 		, 		'b', 		'd', 		'Module talk:Transcluder/testcases', 		'module talk:Transcluder/testcases', 		'a', 		'a', 		, 		, 		, 		, 		, 		, 		, 	}, W.getLinks( testpage ) ) end

function Suite:testCategories self:assertDeepEquals( {}, W.getCategories( 'a' ) ) self:assertDeepEquals( {}, W.getCategories( 'a' ) ) self:assertDeepEquals( { '' ) )	self:assertDeepEquals( { ' category : a ' }, W.getCategories( ' category : a ' ) )	self:assertDeepEquals( { 'c' ) ) self:assertDeepEquals( { '' }, W.getCategories( 'ad' ) ) self:assertDeepEquals( {		, 		, 		'', 	}, W.getCategories( testpage ) ) end

function Suite:testFiles self:assertDeepEquals( {}, W.getFiles( 'a' ) ) self:assertDeepEquals( {}, W.getFiles( 'a' ) ) self:assertDeepEquals( {  }, W.getFiles(  ) ) self:assertDeepEquals( { ' file : a ' }, W.getFiles( ' file : a ' ) ) self:assertDeepEquals( { '' }, W.getFiles( 'ac' ) ) self:assertDeepEquals( { ,  }, W.getFiles( 'ad' ) ) self:assertDeepEquals( {		, 		, 		, 		, 		, 		, 		'', 	}, W.getFiles( testpage ) ) end

function Suite:testExternalLinks self:assertDeepEquals( {}, W.getExternalLinks( '' ) ) self:assertDeepEquals( {}, W.getExternalLinks( 'a' ) ) self:assertDeepEquals( {}, W.getExternalLinks( 'a' ) ) self:assertDeepEquals( { '[//www.example.com]' }, W.getExternalLinks( '[//www.example.com]' ) ) self:assertDeepEquals( {  }, W.getExternalLinks(  ) ) self:assertDeepEquals( {  }, W.getExternalLinks(  ) ) self:assertDeepEquals( { '[//www.example.com example]' }, W.getExternalLinks( '[//www.example.com example]' ) ) self:assertDeepEquals( { 'example' }, W.getExternalLinks( 'example' ) ) self:assertDeepEquals( { 'example' }, W.getExternalLinks( 'example' ) ) end

return Suite