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: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" ) self:assertThrows( function Transclude.get('Module:Transclude/test', { fragment = 'empty' } ) end, "Fragment 'empty' is empty" )

-- @todo this test fails because #lst doesn't distinguish between an empty fragment and a non-existent fragment --self:assertThrows( function Transclude.get('Module:Transclude/test', { fragment = 'fake' } ) end, "Fragment 'fake' not found" ) end

function Suite:testFiles self:assertDeepEquals( {}, Transclude.getFiles() ) self:assertDeepEquals( {}, Transclude.getFiles() ) self:assertDeepEquals( {,}, Transclude.getFiles('') ) self:assertDeepEquals( {,}, Transclude.getFiles('\n\n\nc') ) end

function Suite:testFragments self:assertEquals( 'Some text.', Transclude.get('Module:Transclude/test', { fragment = 'text' } ) )

-- @todo this test fails because por some reason parse deletes the table --self:assertEquals( '{|\n!a\n|}', Transclude.get('Module:Transclude/test', { fragment = 'table' } ) ) end

function Suite:testLeads 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( {'*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', { lists = { [2] = true } } ) )

self:assertEquals( '*b\n*c\n\n#e\n#f', Transclude.get('Module:Transclude/test#Lists', { only = 'list' } ) ) 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] = true } } ) ) 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'}, Transclude.getParagraphs('a\n\nb\n\nc', { paragraphs = { [1] = true, [3] = true } } ) )

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

function Suite:testSections self:assertEquals( 'Content of the first section.', Transclude.get('Module:Transclude/test#Section') ) self:assertEquals( 'Content of the first subsection.', Transclude.get('Module:Transclude/test#Subsection') ) self:assertEquals( 'Content of the first section.\n\n=== Subsection ===\n\nContent of the first subsection.', Transclude.get('Module:Transclude/test#Section', { keepSubsections = true } ) ) end

function Suite:testTables self:assertEquals( 'a\n\nc', Transclude.get('Module:Transclude/test#Tables') ) self:assertEquals( 'a\n\n{|\n!b\n|}\n\nc\n\n{|\n|d\n|}', Transclude.get('Module:Transclude/test#Tables', { keepTables = true } ) ) self:assertEquals( '{|\n!b\n|}\n\n{|\n|d\n|}', Transclude.get('Module:Transclude/test#Tables', { keepTables = true, only = 'table' } ) ) self:assertEquals( '{|\n!b\n|}\n\n{|\n|d\n|}', Transclude.get('Module:Transclude/test#Tables', { keepTables = true, only = 'tables' } ) ) self:assertEquals( '{|\n!b\n|}\n\n{|\n|d\n|}', Transclude.get('Module:Transclude/test#Tables', { keepTables = true, tablesOnly = true } ) ) self:assertEquals( '{|\n!b\n|}', Transclude.get('Module:Transclude/test#Tables', { keepTables = true, only = 'tables', tables = { [1] = true } } ) ) self:assertEquals( '{|\n|d\n|}', Transclude.get('Module:Transclude/test#Tables', { keepTables = true, only = 'tables', tables = { [2] = true } } ) ) end

function Suite:testTemplates self:assertEquals( 'Text with .', Transclude.get('Module:Transclude/test#Template') ) end

return Suite