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: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('==a==', 'a') end, "Section 'a' 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( '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 'a' not found" ) 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: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( {['b']='c'}, t.getParameters('', 'b' ) ) self:assertDeepEquals( {['b']='c'}, t.getParameters('', ' b ' ) ) self:assertDeepEquals( {['b']='c',['d']='e'}, t.getParameters('', 'b,d' ) ) 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', { only = 'parameters', parameters = 'b', templates = 'aa' } ) ) --self:assertEquals( 'd', t.get('Module:Transcluder/test', { only = 'parameters', parameters = 'b', templates = 'bb' } ) ) 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', '-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