Module:Transcluder/testcases

local frame = mw.getCurrentFrame local title = frame and frame.args and frame.args.module or 'Transcluder' local T = require( 'Module:' .. title ) local ScribuntoUnit = require('Module:ScribuntoUnit') local Suite = ScribuntoUnit:new

function Suite:testCategories self:assertThrows( function T.getCategories end ) self:assertThrows( function T.getCategories({}) end ) self:assertThrows( function T.getCategories(false) end )

self:assertDeepEquals( {}, T.getCategories('') ) self:assertDeepEquals( {}, T.getCategories('a') ) self:assertDeepEquals( {) )	self:assertDeepEquals( {}, T.getCategories() )	self:assertDeepEquals( {}, T.getCategories() )	self:assertDeepEquals( {}, T.getCategories() )	self:assertDeepEquals( {}, T.getCategories() )	self:assertDeepEquals( {}, T.getCategories('\n\nc') )	self:assertDeepEquals( {}, T.getCategories('[[Category:A]]', 0) )	self:assertDeepEquals( {'[[Category:B]]', 2 ) ) self:assertDeepEquals( {''}, T.getCategories('[[Category:C]]', '2-3') )

self:assertEquals( '[[Category:A]]', T.get('Module:Transcluder/test#Categories', { categories = 1 } ) ) self:assertEquals( '[[Category:B]]', T.get('Module:Transcluder/test#Categories', { categories = 2 } ) ) end

function Suite:testErrors self:assertThrows( function T.get end, 'No page given' ) self:assertThrows( function T.get('') end, 'No page given' ) self:assertThrows( function T.get(' ') end, 'No page given' ) self:assertThrows( function T.get('Fake') end, "Page 'Fake' not found" ) self:assertThrows( function T.get('Module:Transcluder/test#Fake') end, "Section 'Fake' not found" ) end

function Suite:testFiles self:assertThrows( function T.getFiles end ) self:assertThrows( function T.getFiles({}) end ) self:assertThrows( function T.getFiles(false) end )

self:assertDeepEquals( {}, T.getFiles('') ) self:assertDeepEquals( {}, T.getFiles('a') ) self:assertDeepEquals( {}, T.getFiles() ) self:assertDeepEquals( {}, T.getFiles() ) self:assertDeepEquals( {,}, T.getFiles('') ) self:assertDeepEquals( {,}, T.getFiles('\n\n\nc') ) self:assertDeepEquals( {}, T.getFiles('', 0 ) ) self:assertDeepEquals( {}, T.getFiles(, 2 ) ) self:assertDeepEquals( {,}, T.getFiles('', '-2' ) ) self:assertDeepEquals( {,}, T.getFiles('', '2-3') ) self:assertDeepEquals( {}, T.getFiles(, 'A.png') ) self:assertDeepEquals( {,}, T.getFiles('', '-A.png') ) self:assertDeepEquals( {,}, T.getFiles('', 'A.png, C.png') ) self:assertDeepEquals( {}, T.getFiles(, '-A.png, C.png') )

self:assertDeepEquals( {,}, T.getFiles('', -1 ) ) self:assertDeepEquals( {}, T.getFiles(, '-2-3' ) ) self:assertDeepEquals( {}, T.getFiles(, { [1] = true } ) ) self:assertDeepEquals( {,}, T.getFiles('', { [1] = false } ) )

self:assertEquals( 'ab', T.get('Module:Transcluder/test#Files', { files = 1 } ) ) self:assertEquals( 'ab', T.get('Module:Transcluder/test#Files', { files = 2 } ) ) end

function Suite:testGet self:assertEquals( '\nb\n*c\n*d\n{|\n|e\n|}\n\ng\n#h\n#i\nj\n{|\n|k\n|}\nl', T.get('Module:Transcluder/test#Get') ) self:assertEquals( 'b\n\n\ng\n#h\n#i\nj\n{|\n|k\n|}\nl', T.get('Module:Transcluder/test#Get', { files = 2, tables = 2, lists = 2 } ) ) end

function Suite:testLead self:assertEquals( "This test page interacts with Module:Transcluder/testcases.", T.get('Module:Transcluder/test#') ) self:assertEquals( 'This test page interacts with Module:Transcluder/testcases.', T.get('Module:Transcluder/test#', { noBold = true } ) ) end

function Suite:testLists self:assertDeepEquals( {}, T.getLists('') ) self:assertDeepEquals( {}, T.getLists('a') ) self:assertDeepEquals( {'*a\n*b'}, T.getLists('*a\n*b') ) self:assertDeepEquals( {'*b\n*c'}, T.getLists('a\n*b\n*c\nd') ) self:assertDeepEquals( {'*b\n*c','#e\n#f'}, T.getLists('a\n*b\n*c\nd\n#e\n#f\ng') ) self:assertDeepEquals( {'#e\n#f'}, T.getLists('a\n*b\n*c\nd\n#e\n#f\ng', 2 ) ) self:assertDeepEquals( {'#e\n#f','*h\n*i'}, T.getLists('a\n*b\n*c\nd\n#e\n#f\ng\n*h\n*i', '2-3' ) )

self:assertEquals( '*b\n*c\n\n#e\n#f', T.get('Module:Transcluder/test#Lists', { only = 'lists' } ) ) self:assertEquals( '#e\n#f', T.get('Module:Transcluder/test#Lists', { only = 'lists', lists = 2 } ) ) end

function Suite:testOnly self:assertEquals( '{|\n|e\n|}\n\n{|\n|k\n|}\n\n*c\n*d\n\n#h\n#i', T.get('Module:Transcluder/test#Only', { only = 'tables, lists' } ) ) self:assertEquals( '*c\n*d\n\n#h\n#i\n\n{|\n|e\n|}\n\n{|\n|k\n|}', T.get('Module:Transcluder/test#Only', { only = 'lists, tables' } ) ) self:assertEquals( '*c\n*d\n\n{|\n|e\n|}\n\n{|\n|k\n|}', T.get('Module:Transcluder/test#Only', { only = 'lists, tables', lists = 1 } ) ) end

function Suite:testParagraphs self:assertDeepEquals( {'a'}, T.getParagraphs('a') ) self:assertDeepEquals( {'a'}, T.getParagraphs('a') ) self:assertDeepEquals( {'b'}, T.getParagraphs('b') ) self:assertDeepEquals( {}, T.getParagraphs('') ) self:assertDeepEquals( {}, T.getParagraphs('') ) self:assertDeepEquals( {}, T.getParagraphs('\n\n\n\n') ) self:assertDeepEquals( {'a'}, T.getParagraphs('a\n\n') ) self:assertDeepEquals( {'b'}, T.getParagraphs('\n\nb') ) self:assertDeepEquals( {'b'}, T.getParagraphs('b') ) self:assertDeepEquals( {'a','b','c'}, T.getParagraphs('a\n\nb\n\nc') ) self:assertDeepEquals( {'a','c'}, T.getParagraphs('a\n\n\n\nc') ) self:assertDeepEquals( {'a','c','d','e'}, T.getParagraphs('a\n\nb\n\nc\n\nd\n\ne', '1,3-5' ) ) self:assertDeepEquals( {'e'}, T.getParagraphs('\n\n\n\ne', 1 ) )

self:assertEquals( 'a\n\n c ', T.get('Module:Transcluder/test#Paragraphs', { only = 'paragraphs' } ) ) self:assertEquals( 'a', T.get('Module:Transcluder/test#Paragraphs', { only = 'paragraphs', paragraphs = 1 } ) ) self:assertEquals( ' c ', T.get('Module:Transcluder/test#Paragraphs', { only = 'paragraphs', paragraphs = 2 } ) ) end

function Suite:testParameters self:assertDeepEquals( {}, T.getParameters('', 0 ) ) self:assertDeepEquals( {}, T.getParameters('', 1 ) ) self:assertDeepEquals( {}, T.getParameters('', 2 ) ) self:assertDeepEquals( {}, T.getParameters('', 1 ) ) self:assertDeepEquals( {}, T.getParameters('', 'd' ) ) self:assertDeepEquals( {['b']='c'}, T.getParameters('', 'b' ) ) self:assertDeepEquals( {['d']='e'}, T.getParameters('', 'd' ) ) self:assertDeepEquals( {['f']='g'}, T.getParameters('', ' f ' ) ) self:assertDeepEquals( {['b']='c',['d']='e'}, T.getParameters('', 'b,d' ) ) self:assertDeepEquals( {['b']=}, T.getParameters(, 'b' ) ) self:assertDeepEquals( {['b']=' d '}, T.getParameters('', 'b' ) ) self:assertDeepEquals( {['b']=}, T.getParameters(, 'b' ) ) self:assertDeepEquals( {['b']='c|d'}, T.getParameters('', 'b' ) ) self:assertDeepEquals( {[1]='f'}, T.getParameters('', 1 ) ) self:assertDeepEquals( {[1]='d',[2]='e',[3]='h'}, T.getParameters('', '1-3' ) )

self:assertEquals( 'd', T.get('Module:Transcluder/test', { only = 'parameters', parameters = 'b' } ) ) self:assertEquals( 'c', T.get('Module:Transcluder/test#Parameters', { only = 'parameters', parameters = 'b', templates = 'aa' } ) ) self:assertEquals( 'd', T.get('Module:Transcluder/test', { only = 'parameters', parameters = 'b', templates = 'bb' } ) ) end

function Suite:testReferences self:assertDeepEquals( {}, T.getReferences('a') ) self:assertDeepEquals( {' '}, T.getReferences('a ') ) self:assertDeepEquals( {}, T.getReferences('a ', 0) ) self:assertDeepEquals( {}, T.getReferences('a ') ) self:assertDeepEquals( {' '}, T.getReferences('a c ', 2) ) self:assertDeepEquals( {' ',' '}, T.getReferences('a d ') ) self:assertDeepEquals( {' '}, T.getReferences('a d ', 'b') )

self:assertEquals( 'acf', T.get('Module:Transcluder/test#References', { references = 0 } ) ) self:assertEquals( ' \n\n ', T.get('Module:Transcluder/test', { only = 'references' } ) ) end

function Suite:testSection self:assertThrows( function T.getSection('a', 'a') end, "Section 'a' not found" ) self:assertThrows( function T.getSection('==z==', 'z') end, "Section 'z' is empty" )

self:assertEquals( 'b', T.getSection('==a==\nb', 'a') ) self:assertEquals( 'b', T.getSection('==a==\nb\n==c==\nd', 'a') ) self:assertEquals( 'b\n===c===\nd', T.getSection('==a==\nb\n===c===\nd', 'a') ) self:assertEquals( 'd', T.getSection('==a==\nb\n===c===\nd', 'c') )

self:assertEquals( 'a\n===Subsection===\nb', T.get('Module:Transcluder/test#Section') ) self:assertEquals( 'b', T.get('Module:Transcluder/test#Subsection') ) self:assertEquals( 'a', T.get('Module:Transcluder/test#Section', { sections = 0 } ) ) end

function Suite:testSections self:assertEquals( "This test page interacts with Module:Transcluder/testcases.", T.get('Module:Transcluder/test', { sections = 0 } ) ) self:assertEquals( "a\n===Subsection===\nb", T.get('Module:Transcluder/test#Section', { sections = 1 } ) ) self:assertEquals( "a\n===Subsection===\nb", T.get('Module:Transcluder/test#Section', { sections = 'Subsection' } ) )

-- tags self:assertThrows( function T.get('Module:Transcluder/test#a') end, "Section tag 'a' is empty" ) self:assertEquals( 'b', T.get('Module:Transcluder/test#b' ) ) self:assertEquals( '{|\n!c\n|}', T.get('Module:Transcluder/test#c' ) ) end

function Suite:testSelfLink self:assertEquals( "This test page interacts with Module:Transcluder/testcases.", T.get('Module:Transcluder/test', { noSelfLinks = true, sections = 0 } ) ) self:assertEquals( 'Module:Transcluder/testcases module:Transcluder/testcases a a', T.get('Module:Transcluder/test#Self links', { noSelfLinks = true, sections = 0 } ) ) end

function Suite:testTables self:assertEquals( '{|\n!b\n|}\n\n{|\n|d\n|}\n\n{|id="e"\n|e\n|}', T.get('Module:Transcluder/test#Tables', { only = 'tables' } ) ) self:assertEquals( '{|\n!b\n|}', T.get('Module:Transcluder/test#Tables', { only = 'tables', tables = 1 } ) ) self:assertEquals( '{|\n|d\n|}', T.get('Module:Transcluder/test#Tables', { only = 'tables', tables = 2 } ) ) self:assertEquals( '{|\n!b\n|}\n\n{|id="e"\n|e\n|}', T.get('Module:Transcluder/test#Tables', { only = 'tables', tables = '1,3' } ) ) self:assertEquals( '{|\n|d\n|}\n\n{|id="e"\n|e\n|}', T.get('Module:Transcluder/test#Tables', { only = 'tables', tables = '2-3' } ) ) self:assertEquals( '{|id="e"\n|e\n|}', T.get('Module:Transcluder/test#Tables', { only = 'tables', tables = 'e' } ) ) end

function Suite:testTemplates self:assertDeepEquals( {,,''}, T.getTemplates( 'ae' ) ) self:assertDeepEquals( {''}, T.getTemplates( 'ae', 2 ) ) self:assertDeepEquals( {''}, T.getTemplates( 'ae', 'D' ) ) self:assertDeepEquals( {''}, T.getTemplates( 'ae', 'b' ) ) self:assertDeepEquals( {}, T.getTemplates( , 'a' ) ) self:assertDeepEquals( {,}, T.getTemplates( 'ae', '-d' ) ) self:assertDeepEquals( {,}, T.getTemplates( 'ae', 'c,d' ) ) self:assertDeepEquals( {,}, T.getTemplates( 'ae', '1,d' ) ) self:assertDeepEquals( {,}, T.getTemplates( 'ae', { ['c'] = true, ['d'] = true } ) ) self:assertDeepEquals( {,}, T.getTemplates( 'ae', { [1] = true, ['d'] = true } ) ) self:assertDeepEquals( {,}, T.getTemplates( 'ae', { [1] = false } ) )

self:assertEquals( '\n\n\n\n', T.get('Module:Transcluder/test#Templates', { only = 'templates' } ) ) self:assertEquals( '', T.get('Module:Transcluder/test#Templates', { only = 'templates', templates = 2 } ) ) self:assertEquals( '', T.get('Module:Transcluder/test#Templates', { only = 'templates', templates = 'd' } ) ) self:assertEquals( '\n\n', T.get('Module:Transcluder/test#Templates', { only = 'templates', templates = 'c,d' } ) ) end

return Suite