local frame = mw.getCurrentFramelocal title = frame and frame.args and frame.args.module or 'Transcluder/sandbox'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(T.getCategories('')) self:assertDeepEquals(T.getCategories('')) self:assertDeepEquals(T.getCategories('')) self:assertDeepEquals(T.getCategories('')) self:assertDeepEquals(T.getCategories('')) self:assertDeepEquals(T.getCategories('\n\n\nc')) self:assertDeepEquals(T.getCategories('', 0)) self:assertDeepEquals(T.getCategories('', 2)) self:assertDeepEquals(T.getCategories('', '2-3')) self:assertDeepEquals(T.getCategories('', 'X2')) self:assertDeepEquals(T.getCategories('', '-X2'))
self:assertEquals('', T.get('Module:Transcluder/testpage#Categories',)) self:assertEquals('', T.get('Module:Transcluder/testpage#Categories',)) self:assertEquals('\n\n', T.get('Module:Transcluder/testpage#Categories',))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('2 > 1') end, 'Title «2 > 1» is not valid') self:assertThrows(function T.get('Non-existent page') end, "Page 'Non-existent page' not found") self:assertThrows(function T.get('Module:Transcluder/testpage#Non-existent section') end, "Section 'Non-existent section' 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('',)) self:assertDeepEquals(T.getFiles('',))
self:assertEquals('ab', T.get('Module:Transcluder/testpage#Files',)) self:assertEquals('ab', T.get('Module:Transcluder/testpage#Files',))end
function Suite:testGet self:assertEquals('\nb\n*c\n*d\n
e\n |
k\n |
k\n |
function Suite:testInclude self:assertEquals('ac', T.get('Module:Transcluder/testpage#Include'))end
function Suite:testLead self:assertEquals("This test page interacts with .", T.get('Module:Transcluder/testpage#')) self:assertEquals('This test page interacts with .', T.get('Module:Transcluder/testpage#',))end
function Suite:testLinks self:assertEquals('a b c d e', T.get('Module:Transcluder/testpage#Links',))end
function Suite:testLists self:assertDeepEquals(T.getLists()) self:assertDeepEquals(T.getLists('a')) self:assertDeepEquals(T.getLists('*a\n*b')) self:assertDeepEquals(T.getLists('a\n*b\n*c\nd')) self:assertDeepEquals(T.getLists('a\n*b\n*c\nd\n#e\n#f\ng')) self:assertDeepEquals(T.getLists('a\n*b\n*c\nd\n#e\n#f\ng', 2)) self:assertDeepEquals(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/testpage#Lists',)) self:assertEquals('#e\n#f', T.get('Module:Transcluder/testpage#Lists',))end
function Suite:testOnly self:assertEquals('
e\n |
k\n |
function Suite:testParagraphs self:assertDeepEquals(T.getParagraphs('a')) self:assertDeepEquals(T.getParagraphs('a')) self:assertDeepEquals(T.getParagraphs('b')) self:assertDeepEquals(T.getParagraphs('')) self:assertDeepEquals(T.getParagraphs('')) self:assertDeepEquals(T.getParagraphs('\n\n\n\n')) self:assertDeepEquals(T.getParagraphs('a\n\n')) self:assertDeepEquals(T.getParagraphs('\n\nb')) self:assertDeepEquals(T.getParagraphs('b')) self:assertDeepEquals(T.getParagraphs('a\n\nb\n\nc')) self:assertDeepEquals(T.getParagraphs('a\n\n\n\nc')) self:assertDeepEquals(T.getParagraphs('a\n\nb\n\nc\n\nd\n\ne', '1,3-5')) self:assertDeepEquals(T.getParagraphs('\n\n\n\ne', 1))
self:assertEquals('\nX1\n
X2\n |
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(T.getParameters('', 'b')) self:assertDeepEquals(T.getParameters('', 'b')) self:assertDeepEquals(T.getParameters('', 'd')) self:assertDeepEquals(T.getParameters('', ' f ')) self:assertDeepEquals(T.getParameters('', 'b,d')) self:assertDeepEquals(T.getParameters('', 'b')) self:assertDeepEquals(T.getParameters('', 'b')) self:assertDeepEquals(T.getParameters('', 'b')) self:assertDeepEquals(T.getParameters('', 'b')) self:assertDeepEquals(T.getParameters('', 'b')) self:assertDeepEquals(T.getParameters('', 1)) self:assertDeepEquals(T.getParameters('', '1-3'))
self:assertEquals('d', T.get('Module:Transcluder/testpage#Parameters',)) self:assertEquals('d', T.get('Module:Transcluder/testpage#Parameters',)) self:assertEquals('d', T.get('Module:Transcluder/testpage#Parameters',))end
function Suite:testReferences self:assertDeepEquals(T.getReferences('a')) self:assertDeepEquals(T.getReferences('a[1] ')) self:assertDeepEquals(T.getReferences('a[2] ', 0)) self:assertDeepEquals(T.getReferences('a')) self:assertDeepEquals(T.getReferences('a[3] c[4] ', 2)) self:assertDeepEquals(T.getReferences('a[5] d[6] ')) self:assertDeepEquals(T.getReferences('a[7] d[8] ', 'b'))
self:assertEquals('acfgk', T.get('Module:Transcluder/testpage#References',)) self:assertEquals('[9] \n\n[10] \n\n[11] ', T.get('Module:Transcluder/testpage#References',)) self:assertEquals('[12] \n\n[13] \n\n[14] ', T.get('Module:Transcluder/testpage#References',))end
function Suite:testSection self:assertThrows(function T.getSection('a', 'a') end, "Section 'a' not found") self:assertThrows(function T.getSection('
', 'z') end, "Section 'z' is empty")
self:assertEquals('b', T.getSection('
\nb', 'a')) self:assertEquals('b', T.getSection('
\nb\n
\nd', 'a')) self:assertEquals('b\n
\nd', T.getSection('
\nb\n
\nd', 'a')) self:assertEquals('d', T.getSection('
\nb\n
\nd', 'c'))
self:assertEquals('a\n
\nb', T.get('Module:Transcluder/testpage#Section')) self:assertEquals('b', T.get('Module:Transcluder/testpage#Subsection')) self:assertEquals('a', T.get('Module:Transcluder/testpage#Section',))end
function Suite:testSections self:assertEquals("This test page interacts with .", T.get('Module:Transcluder/testpage',)) self:assertEquals('a\n
\nb', T.get('Module:Transcluder/testpage#Section')) self:assertEquals('a', T.get('Module:Transcluder/testpage#Section',)) self:assertEquals('a', T.get('Module:Transcluder/testpage#Section',)) self:assertEquals('a', T.get('Module:Transcluder/testpage#Section',)) self:assertEquals('a\n
\nb', T.get('Module:Transcluder/testpage#Section',)) self:assertEquals('a\n
\nb', T.get('Module:Transcluder/testpage#Section',)) self:assertEquals('d', T.get('Module:Transcluder/testpage#Subsection with link')) self:assertEquals('e\n
\nf', T.get('Module:Transcluder/testpage#Section with (parenthesis)'))
--
c\n |
---|
function Suite:testSelfLink self:assertEquals("This test page interacts with .", T.get('Module:Transcluder/testpage',)) self:assertEquals('Module talk:Transcluder/testcases module talk:Transcluder/testcases a a', T.get('Module:Transcluder/testpage#Self links',))end
function Suite:testTables self:assertEquals('
b\n |
---|
d\n |
e\n |
b\n |
---|
d\n |
b\n |
---|
e\n |
d\n |
e\n |
e\n |
function Suite:testTags self:assertDeepEquals(T.getTags('a')) -- no tags self:assertDeepEquals(T.getTags('
a')) -- unclosed tag self:assertDeepEquals(
'}, T.getTags('
')) -- empty tag self:assertDeepEquals(T.getTags('a
b')) self:assertDeepEquals(T.getTags('
a
')) -- simple case self:assertDeepEquals(T.getTags('a
b
c')) self:assertDeepEquals(T.getTags('< div >a div >')) -- weird spacing self:assertDeepEquals(T.getTags('
b
')) -- attributes
-- Nested tags self:assertDeepEquals(T.getTags('
')) self:assertDeepEquals(T.getTags('a
b
c
d
e')) self:assertDeepEquals(T.getTags('
a')) self:assertDeepEquals(T.getTags('
a', 'span')) self:assertDeepEquals(T.getTags('
a', '-span'))
self:assertEquals('\n\n[15] \n\n
\n\n
\n\n
a
b
\n\n
b
', T.get('Module:Transcluder/testpage',)) self:assertEquals('
bd\n\nd', T.get('Module:Transcluder/testpage',))endfunction 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',)) self:assertDeepEquals(T.getTemplates('ae',)) self:assertDeepEquals(T.getTemplates('ae',))
self:assertEquals('\n\n\n\n', T.get('Module:Transcluder/testpage#Templates',)) self:assertEquals('', T.get('Module:Transcluder/testpage#Templates',)) self:assertEquals('', T.get('Module:Transcluder/testpage#Templates',)) self:assertEquals('\n\n', T.get('Module:Transcluder/testpage#Templates',))end
return Suite