Module:WikitextParser/testcases explained

local W = require('Module:WikitextParser')local testpage = mw.title.new('Module:WikitextParser/testpage'):getContentlocal ScribuntoUnit = require('Module:ScribuntoUnit')local Suite = ScribuntoUnit:new

function Suite:testLead self:assertEquals(, W.getLead()) self:assertEquals(, W.getLead('

b

')) self:assertEquals('a', W.getLead('a')) self:assertEquals('a', W.getLead('a', 'a\n

b

')) self:assertEquals('This test page interacts with .', W.getLead(testpage))end

function Suite:testSection self:assertEquals(nil, W.getSection('a', 'a')) self:assertEquals(, W.getSection('

a

', 'a')) self:assertEquals('b', W.getSection('

a

\nb', 'a')) self:assertEquals('b', W.getSection('

a

\nb\n

c

\nd', 'a')) self:assertEquals('b', W.getSection('

a

\nb\n

a

\nd', 'a')) self:assertEquals('b\n

c

\nd', W.getSection('

a

\nb\n

c

\nd', 'a')) self:assertEquals('d', W.getSection('

a

\nb\n

c

\nd', 'c')) self:assertEquals('a\n

Subsection

\nb', W.getSection(testpage, 'Section')) self:assertEquals('b', W.getSection(testpage, 'Subsection'))end

function Suite:testSectionTag self:assertEquals(nil, W.getSectionTag('a', 'a')) self:assertEquals(nil, W.getSectionTag('a

c', 'a')) self:assertEquals(, W.getSectionTag('a
c', 'b')) self:assertEquals('c', W.getSectionTag('a
c
d', 'b')) self:assertEquals(, W.getSectionTag(testpage, 'a')) self:assertEquals('b', W.getSectionTag(testpage, 'b')) self:assertEquals('

c\n
', W.getSectionTag(testpage, 'c')) self:assertEquals(nil, W.getSectionTag(testpage, 'd'))end

function Suite:testSections self:assertDeepEquals(W.getSections()) self:assertDeepEquals(W.getSections('a')) self:assertDeepEquals(W.getSections('

a

')) self:assertDeepEquals(W.getSections('a\n

b

')) self:assertDeepEquals(W.getSections('

a

\n

b

')) self:assertDeepEquals(W.getSections('

a

\nb')) self:assertDeepEquals(W.getSections('a\n

b

\nc')) self:assertDeepEquals(W.getSections('a\n

b

\nc\n

d

\ne'))end

function Suite:testLists self:assertDeepEquals(W.getLists()) self:assertDeepEquals(W.getLists('a')) self:assertDeepEquals(W.getLists('*a')) self:assertDeepEquals(W.getLists('*a\n*b')) self:assertDeepEquals(W.getLists('a\n*b\n*c\nd')) self:assertDeepEquals(W.getLists('a\n*b\n*c\nd\n#e\n#f\ng')) self:assertDeepEquals(W.getLists(testpage))end

function Suite:testParagraphs self:assertDeepEquals(W.getParagraphs()) self:assertDeepEquals(W.getParagraphs('')) self:assertDeepEquals(W.getParagraphs('')) self:assertDeepEquals(W.getParagraphs('\n\n')) self:assertDeepEquals(W.getParagraphs('\n\n\n\n')) self:assertDeepEquals(W.getParagraphs('a')) self:assertDeepEquals(W.getParagraphs('a')) self:assertDeepEquals(W.getParagraphs('b')) self:assertDeepEquals(W.getParagraphs('a\n\n')) self:assertDeepEquals(W.getParagraphs('\n\nb')) self:assertDeepEquals(W.getParagraphs('b')) self:assertDeepEquals(W.getParagraphs('a\n\nb\n\nc')) self:assertDeepEquals(W.getParagraphs('a\n\n\n\nc')) self:assertDeepEquals(W.getParagraphs(W.getSection(testpage, 'Paragraphs')))end

function Suite:testTemplates self:assertDeepEquals(W.getTemplates('a')) self:assertDeepEquals(W.getTemplates('')) self:assertDeepEquals(W.getTemplates('ac')) self:assertDeepEquals(W.getTemplates('')) self:assertDeepEquals(W.getTemplates('')) self:assertDeepEquals(W.getTemplates('ace')) self:assertDeepEquals(W.getTemplates('ace')) self:assertDeepEquals(W.getTemplates('')) self:assertDeepEquals(W.getTemplates(testpage))end

function Suite:testTemplate self:assertEquals('', W.getTemplate('', 'a')) self:assertEquals('', W.getTemplate('', 'a')) self:assertEquals('', W.getTemplate('', 'A')) self:assertEquals('

A:1\n
B:2\n
D:4\n
C:3\n

', W.getTemplate(testpage, 'Infobox'))end

function Suite:testParameters self:assertDeepEquals(W.getParameters('')) --self:assertDeepEquals(W.getParameters('')) self:assertDeepEquals(W.getParameters('')) self:assertDeepEquals(W.getParameters('')) self:assertDeepEquals(W.getParameters('')) self:assertDeepEquals(W.getParameters(''))end

function Suite:testTags self:assertDeepEquals(W.getTags('a')) self:assertDeepEquals(W.getTags('

a')) self:assertDeepEquals(

' }, W.getTags('

')) self:assertDeepEquals(W.getTags('a

b')) self:assertDeepEquals(W.getTags('

a

')) self:assertDeepEquals(W.getTags('a

b

c')) self:assertDeepEquals(W.getTags('< div >a')) self:assertDeepEquals(W.getTags('

b

')) self:assertDeepEquals(W.getTags('

')) self:assertDeepEquals(W.getTags('a

b

c

d

e')) self:assertDeepEquals(W.getTags('

a

')) self:assertDeepEquals(W.getTags(testpage))end

function Suite:testGalleries self:assertDeepEquals(W.getGalleries('a')) self:assertDeepEquals(W.getGalleries('')) self:assertDeepEquals(W.getGalleries('ac')) self:assertDeepEquals(W.getGalleries('')) self:assertDeepEquals(W.getGalleries('ab')) self:assertDeepEquals(W.getGalleries(testpage))end

function Suite:testReferences self:assertDeepEquals(W.getReferences('a')) self:assertDeepEquals(W.getReferences('[1] ')) self:assertDeepEquals(W.getReferences('a[2] c')) self:assertDeepEquals(W.getReferences('a[3] c[4] ')) self:assertDeepEquals(W.getReferences('a[5] d')) self:assertDeepEquals(W.getReferences(testpage))end

function Suite:testTables self:assertDeepEquals(W.getTables('a')) self:assertDeepEquals(W.getTables('a\n

b\n
\nc')) self:assertDeepEquals(W.getTables('a\n
b\n
\nc\n
d\n
\n
e\n
f')) self:assertDeepEquals(W.getTables(testpage))end

function Suite:testLinks self:assertDeepEquals(W.getLinks('a')) self:assertDeepEquals(W.getLinks('a')) self:assertDeepEquals(W.getLinks('b')) self:assertDeepEquals(W.getLinks('abc')) self:assertDeepEquals(W.getLinks('abcde')) self:assertDeepEquals(W.getLinks(testpage))end

function Suite:testCategories self:assertDeepEquals(W.getCategories('a')) self:assertDeepEquals(W.getCategories('a')) self:assertDeepEquals(W.getCategories('')) self:assertDeepEquals(W.getCategories('')) self:assertDeepEquals(W.getCategories('ac')) self:assertDeepEquals(W.getCategories('ad')) self:assertDeepEquals(W.getCategories(testpage))end

function Suite:testFiles self:assertDeepEquals(W.getFiles('a')) self:assertDeepEquals(W.getFiles('a')) self:assertDeepEquals(W.getFiles('')) self:assertDeepEquals(W.getFiles('')) self:assertDeepEquals(W.getFiles('ac')) self:assertDeepEquals(W.getFiles('ad')) self:assertDeepEquals(W.getFiles(testpage))end

function Suite:testExternalLinks self:assertDeepEquals(W.getExternalLinks()) self:assertDeepEquals(W.getExternalLinks('a')) self:assertDeepEquals(W.getExternalLinks('a')) self:assertDeepEquals(W.getExternalLinks('[//www.example.com]')) self:assertDeepEquals(W.getExternalLinks('http://www.example.com')) self:assertDeepEquals(W.getExternalLinks('https://www.example.com')) self:assertDeepEquals(W.getExternalLinks('[//www.example.com example]')) self:assertDeepEquals(W.getExternalLinks('example')) self:assertDeepEquals(W.getExternalLinks('example'))end

return Suite

Notes and References

  1. a
  2. b
  3. b
  4. d
  5. c