Module:Wikitext Parsing/testcases explained

--Go to the talk page to see the results of the tests--Consider making sure that other modules that rely heavily on this module (E.g.) also pass their testcaseslocal p = require('Module:UnitTests')

local frame = mw.getCurrentFramelocal function preprocess(text, IsPrepared) local content = mw.text.unstrip(frame:preprocess(text)) if IsPrepared then content = mw.text.decode(content) end return contentend

function p:_internal_test(module, name) --All PrepareText runs have keepComments set to true for testing convenience --Test conditions: --1) The escaped text should match our expectation for escaped text --2) The escaped text should always preprocess to the same as the original text (we only nowiki nowiki'd content) local PrepareTextTestN = 1 local function TestPrepareText(...) local OriginalString = "" local ExpectedEscapedString = "" local args = for i = 1, #args do OriginalString = OriginalString .. args[i] ExpectedEscapedString = ExpectedEscapedString .. (i%2

1 and args[i] or mw.text.nowiki(args[i])) end local ModuleEscapedString = module.PrepareText(OriginalString, true) self:equals(name.."PrepareText Escape Test "..PrepareTextTestN, ExpectedEscapedString, ModuleEscapedString,) self:equals(name.."PrepareText Preprocess Test "..PrepareTextTestN, preprocess(OriginalString), preprocess(ModuleEscapedString, true),) PrepareTextTestN = PrepareTextTestN + 1 end --

PrepareText

-- --Standard comment escape TestPrepareText(-- R------, NW------, R----- "BA" )

--Even when there's no end, the content inside is escaped TestPrepareText(-- R----------, NW----------, R------ "", ">|B}}" )

--A decently complex case TestPrepareText(-- R-------------, NW-----------, R--, NW------------, R---, NW------, "Hey!\nA", "|Should see|Shouldn't see}}" )

--Another decently complex case TestPrepareText(-- R---------------------------------------------------------------, "|A B=Success}}" )end

function p:test_live p:_internal_test(require("Module:Wikitext Parsing"), "Live ")end

function p:test_sandbox p:_internal_test(require("Module:Wikitext Parsing/sandbox"), "Sandbox ")end

-- Code for testing ParseTemplates that doesn't exactly work (not a primary feature so not a huge concern)--[====[ --Test conditions: --1) The parsed information matches the expected information local ParseTemplatesTestN = 1 local function TestParseTemplates(OriginalString, ExpectedInformation) local ModuleInformation = module.ParseTemplates(OriginalString)[1] ModuleInformation.Children = nil --This isn't gonna be tested properly rn due to reasons mw.logObject(ModuleInformation) self:equals_deep(name.."ParseTemplates Test "..ParseTemplatesTestN, ExpectedInformation, ModuleInformation,) ParseTemplatesTestN = ParseTemplatesTestN + 1 end

--

ParseTemplates

-- -- Just the one test since this feature isn't entirely developed local TestString = "