Template:unit-test-equals

Hello, you have come here looking for the meaning of the word Template:unit-test-equals. In DICTIOUS you will not only get to know all the dictionary meanings for the word Template:unit-test-equals, but we will also tell you about its etymology, its characteristics and you will know how to say Template:unit-test-equals in singular and plural. Everything you need to know about the word Template:unit-test-equals you have here. The definition of the word Template:unit-test-equals will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofTemplate:unit-test-equals, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.
Expected:{{{expected}}}
Actual:{{{actual}}}



Usage

This template is for writing "unit-tests"; see ] (the "unit-test" page for {{he-adj/helper}}) for an example. It just compares {{{expected}}} to {{{actual}}} and makes sure that they're equal. If so, you get something like this:

foo

and if not, you get something like this:

Expected:foo
Actual:bar

and the page is added to Category:Unit test failures, unless {{{nocat}}} is set to something non-blank.

Some notes:

  • Unfortunately, it won't work if the parameters evaluate to wiki-text containing <nowiki>…</nowiki> or <nowiki/>, since MediaWiki implements those via an intermediate step that replaces the whole thing with something like ~UNIQ3c52e5057596f478-nowiki-00000002-QINU~. If desired, this can generally be worked around by manually escaping whatever needed to be escaped.
  • To maximize testability, all instances of {{PAGENAME}} can be replaced with {{{PAGENAME|{{PAGENAME}}}}} (and likewise for other such magic words), allowing a unit-test page to "pretend" that it's on a different page by passing a PAGENAME= parameter.
    • If the page-name contains an apostrophe, then {{PAGENAME}} will contain &#39;, so templates that do sophisticated things with {{PAGENAME}} should be tested with PAGENAME={{PAGENAME:foo'bar}} (or whatnot) to make sure they behave as expected in that case.
  • This is a very strict equality test. Even something as minor as one internal space vs. two internal spaces will trigger a "unit-test" "failure", even though that's a non-semantic difference that HTMLtidy will remove anyway. If a "unit-test" "fails" and you can't figure out why, it may help to try something like {{unit-test-equals|expected={{urlencode:foo}}|actual={{urlencode:bar}}}} so that every single byte becomes explicitly visible and you can see where the difference is.
  • If a page of unit-tests is transcluded onto other pages (e.g. using {{unit-test-navbox}}), then you probably only want the unit-test page itself to appear in Category:Unit test failures. To that end, you can pass in nocat=<includeonly>1</includeonly>.

See also