Content deleted Content added
→templatestyles: new section |
|||
Line 41:
Why ''{<!-- -->{#invoke:UnitTests/testcases/frame | _test}}'' give [[Module talk:UnitTests/testcases|different result]] for direct #invoke vs. invoke via UnitTests module?
--[[User:Ans|Ans]] ([[User talk:Ans|talk]]) 13:58, 11 October 2017 (UTC)
== templatestyles ==
[[Module:Citation/CS1]] supports some 25 live templates and [[Module:Citation/CS1/sandbox]] supports an equal number of sandbox templates. We could have added [[WP:TemplateStyles]] markup ({{tag|templatestyles|params=src="<{{var|name}}>/styles.css"|s}}) 25× to the live templates and 25× to the sandboxen but that just seemed dumb so each of the modules concatenate template styles to the end of the cs1|2 template rendering using this (where <code>styles</code> is the name of the appropriate css page):
:<source lang="lua">frame:extensionTag ('templatestyles', '', {src=styles})})</source>
and that works great.
Except in [[Module:Citation/CS1/testcases]].
Where every test fails. 318 failures. There are differences between the live and sandbox modules but not that many.
Because of TemplateStyles. Why? Because TemplateStyles inserts a stripmarker at the end of every cs1|2 template rendering and each stripmarker has a unique id number. So, this always fails:
:<code><nowiki>{{#ifeq:{{cite book |title=Title}}|{{cite book |title=Title}}|ok|FAIL}}</nowiki></code>
::{{#ifeq:{{cite book |title=Title}}|{{cite book |title=Title}}|ok|FAIL}}
even though the two {{tlx|cite book}} templates are identically written.
Here are two transclusions of identical templates; note the stripmakers at the ends:
:{{code|{{cite book|title}}}}
:{{code|{{cite book|title}}}}
To get round this, I have hacked [[Module:UnitTests]] function <code>preprocess_equals_preprocess()</code> (called only by <code>preprocess_equals_preprocess_many()</code>) to accept a new <code>option.templatestyles</code>. When that option is set to <code>true</code>, the code looks at the content of <code>expected</code> and extracts the <code>templatestyles</code> stripmarker identifier (an 8-digit hex number). It then overwrites the <code>templatestyles</code> stripmarker identifier in <code>actual</code> so that they both have the same identifier. Only then does <code>preprocess_equals_preprocess()</code> compare <code>actual</code> against <code>expected</code>.
If you are looking to text changes in ~/sandbox/styles.css compared to ~/styles.css, this change won't help you – and Module:UnitTest is probably the wrong tool anyway because stripmarkers are replaced with their actual content after this module has run.
I suppose that there might be reasons that we might want to expand the capabilities of this functionality though I'm not sure just what those reasons might be. For example these possibilities:
:<code>none</code> – remove <code>templatestyles</code> stripmarkers from both <code>actual</code> and <code>expected</code>; no styling applied to the renderings
:<code>actual</code> – replace <code>templatestyles</code> stripmarker identifier in <code>expected</code> with the <code>templatestyles</code> stripmarker identifier from <code>actual</code>; both use ~/sandbox/styles.css for styling
Perhaps there are others.
—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 19:27, 28 March 2019 (UTC)
|