Module:Transcluder/testcases

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

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

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

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

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

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

self:assertDeepEquals( {}, Transclude.getFiles('') ) self:assertDeepEquals( {}, Transclude.getFiles('a') ) self:assertDeepEquals( {}, Transclude.getFiles() ) self:assertDeepEquals( {}, Transclude.getFiles() ) self:assertDeepEquals( {,}, Transclude.getFiles('') ) self:assertDeepEquals( {,}, Transclude.getFiles('\n\n\nc') ) self:assertDeepEquals( {}, Transclude.getFiles('', 0 ) ) self:assertDeepEquals( {}, Transclude.getFiles(, 2 ) ) self:assertDeepEquals( {,}, Transclude.getFiles('', '2-3') )

self:assertEquals( 'ab', Transclude.get('Module:Transclude/test#Files', { files = 1 } ) ) self:assertEquals( 'ab', Transclude.get('Module:Transclude/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', Transclude.get('Module:Transclude/test#Get') ) self:assertEquals( 'b\n\n\ng\n#h\n#i\nj\n{|\n|k\n|}\nl', Transclude.get('Module:Transclude/test#Get', { files = 2, tables = 2, lists = 2 } ) ) end

function Suite:testFragments self:assertThrows( function Transclude.getFragment('', 'a') end, "Fragment 'a' not found" ) self:assertThrows( function Transclude.getFragment('a', 'a') end, "Fragment 'a' not found" ) self:assertThrows( function Transclude.getFragment(' ', 'a') end, "Fragment 'a' is empty" )

self:assertThrows( function Transclude.get('Module:Transclude/test', { fragment = 'a' } ) end, "Fragment 'a' is empty" ) self:assertThrows( function Transclude.get('Module:Transclude/test', { fragment = 'f' } ) end, "Fragment 'f' not found" )

self:assertEquals( 'b', Transclude.get('Module:Transclude/test', { fragment = 'b' } ) ) self:assertEquals( '{|\n!c\n|}', Transclude.get('Module:Transclude/test', { fragment = 'c' } ) ) end

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

function Suite:testLists self:assertDeepEquals( {}, Transclude.getLists('') ) self:assertDeepEquals( {}, Transclude.getLists('a') ) self:assertDeepEquals( {'*a\n*b'}, Transclude.getLists('*a\n*b') ) self:assertDeepEquals( {'*b\n*c'}, Transclude.getLists('a\n*b\n*c\nd') ) self:assertDeepEquals( {'*b\n*c','#e\n#f'}, Transclude.getLists('a\n*b\n*c\nd\n#e\n#f\ng') ) self:assertDeepEquals( {'#e\n#f'}, Transclude.getLists('a\n*b\n*c\nd\n#e\n#f\ng', 2 ) ) self:assertDeepEquals( {'#e\n#f','*h\n*i'}, Transclude.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', Transclude.get('Module:Transclude/test#Lists', { only = 'lists' } ) ) self:assertEquals( '#e\n#f', Transclude.get('Module:Transclude/test#Lists', { only = 'lists', lists = 2 } ) ) end

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

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

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

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

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

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

self:assertEquals( 'a', Transclude.get('Module:Transclude/test#Section') ) self:assertEquals( 'b', Transclude.get('Module:Transclude/test#Subsection') ) self:assertEquals( 'a\n===Subsection===\nb', Transclude.get('Module:Transclude/test#Section', { subsections = true } ) ) end

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

return Suite