Jump to content
Wikipedia The Free Encyclopedia

Module:Wikitext Parsing/testcases

From Wikipedia, the free encyclopedia
This is the test cases page for the module Module:Wikitext Parsing. Results of the test cases.
 --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. [[Module:Template parameter value]]) also pass their testcases
 localp=require('Module:UnitTests')

 localframe=mw.getCurrentFrame()
 localfunctionpreprocess(text,IsPrepared)
 localcontent=mw.text.unstrip(frame:preprocess(text))
 ifIsPreparedthen
 content=mw.text.decode(content)
 end
 returncontent
 end

 functionp:_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)
 localPrepareTextTestN=1
 localfunctionTestPrepareText(...)
 localOriginalString=""
 localExpectedEscapedString=""
 localargs={...}
 fori=1,#argsdo
 OriginalString=OriginalString..args[i]
 ExpectedEscapedString=ExpectedEscapedString..(i%2==1andargs[i]ormw.text.nowiki(args[i]))
 end
 localModuleEscapedString=module.PrepareText(OriginalString,true)
 self:equals(name.."PrepareText Escape Test "..PrepareTextTestN,ExpectedEscapedString,ModuleEscapedString,{nowiki=1})
 self:equals(name.."PrepareText Preprocess Test "..PrepareTextTestN,preprocess(OriginalString),preprocess(ModuleEscapedString,true),{nowiki=1})
 PrepareTextTestN=PrepareTextTestN+1
 end

 --== PrepareText ==--
 --Standard comment escape
 TestPrepareText(
 --	R------, NW------, R-----
 "B<!--","\nHey!","-->A"
 )

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

 --A decently complex case
 TestPrepareText(
 --	R-------------, NW-----------, R--, NW------------, R---, NW------,
 "Hey!{{Text|<","nowiki | ||",">","\nHey! }}\nA","</","nowiki",
 --	R-------, NW---------, R------------------------------
 ">|<!--","AAAAA|AAA","-->Should see|Shouldn't see}}"
 )

 --Another decently complex case
 TestPrepareText(
 --	R---------------------------------------------------------------,
 "{{User:Aidan9382/templates/dummy\n|A|B|C {{{A|B}}} { } } {\n|<",
 --	NW------, R--, NW-, R---, NW------, R------, NW---, R--, NW-----, R---,
 "nowiki",">","D","</","nowiki",">\n|<","pre",">","E\n|F","</",
 --	NW---, R-------------------------------------------------, NW------,
 "pre",">\n|G|=|a=|A = [[{{PAGENAME}}|A=B]]{{Text|1==<","nowiki",
 --	R--, NW--, R---, NW------, R------------------
 ">","}}","</","nowiki",">}}|A B=Success}}"
 )
 end

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

 functionp: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, {nowiki=1})
 		ParseTemplatesTestN = ParseTemplatesTestN + 1
 	end

 	--== ParseTemplates ==--
 	-- Just the one test since this feature isn't entirely developed
 	local TestString = "{{User:Aidan9382/templates/dummy\n|A|B|C {{{A|B}}} { } "
 		.. "} {\n|<nowiki>D</nowiki>\n|<pre>E\n|F</pre>\n|G|=|a=|A = [[{{PAGE"
 		.. "NAME}}|A=B]]{{Text|1==<nowiki>}}</nowiki>}}|A B=Success}}"
 	TestParseTemplates(
 		"\nA"..TestString.."B\n",
 		{
 			Text = TestString, Name = "User:Aidan9382.templates/dummy",
 			ArgOrder = {"1", "2", "3", "4", "5", "6", "", "a", "A", "A B"},
 			Args = {
 				["1"]="A", ["2"]="B", ["3"]="C {{{A|B}}} { } } {",
 				["4"]="<nowiki>D</nowiki>", ["5"]="<pre>E\n|F</pre>",
 				["6"]="G", [""]="", a="",
 				A="[[{{PAGENAME}}|A=B]]{{Text|1==<nowiki>}}</nowiki>}}",
 				["A B"]="Success"
 			}
 		}
 	)
 ]====]

 returnp

AltStyle によって変換されたページ (->オリジナル) /