Template:Test case
This template uses Lua: |
This template generates a test case for two or more templates. Each template is called with the same parameters, and the test case can be displayed in various different formats.
All parameters passed to this template are passed through to the test-case templates, with the exception of parameters starting with an underscore character (_
), which are reserved for internal use.
Usage
[edit source]Basic syntax
[edit source]If no templates are explicitly specified, the module uses the root page of the current page as the first template, and its /sandbox subpage as the second template.
{{Test case | [parameter1] = [value1] | [parameter2] = [value2] | [parameter3] = [value3] … }}
If only one template is explicitly specified, its /sandbox subpage is used as the second template.
Common syntax
[edit source]The following options will work with all different test case formats.
{{Test case <!-- Output formatting and style --> | _format = | _output = | _collapsible = | _resetRefs = | _code = | _showcode = <!-- Template selection and display name choices --> | _template = | _template1 = | _heading1 = | _template2 = | _heading2 = | _template3 = | _heading3 = … <!-- Remaining unprefixed parameters are passed through to called templates --> | [parameter1] = [value1] | [parameter2] = [value2] | [parameter3] = [value3] … }}
Some test case formats accept additional parameters as well. See their sections for documentation.
Common parameters
[edit source]Parameter | Description |
---|---|
|_format= |
The display format used for the output of the test cases. This can be 'columns', 'rows', 'tablerows', 'inline' or 'default'. |
|_output= |
Allows changes in how the template's output is displayed. The default output is displayed when the |_output= parameter is not specified, or when it is set to any unsupported value. A nowiki version of the template's output is displayed when |_output=nowiki ; this is helpful when there are differences in the underlying wikitext which are not visible in the default output. Both the default output and nowiki version are displayed when |_output=nowiki+ .
|
|_collapsible= |
If set to yes or y , the test case is made collapsible. In fact, if after parsing it determines that the template outputs are functionally identical, the output is automatically collapsed and the visible header background turns green. However, if any of the template outputs differ, the test case is left expanded and the header has a yellow background. See the § Collapsible test cases section below for other parameters which only work in concert with |_collapsible= .
|
|_template1= ,|_template2= ,|_template3= … |
The names of the templates to be tested. |_template1= 's default is the root page of the current page. If |_template1= is explicitly specified, |_template2= 's default becomes its /sandbox subpage; otherwise, the default for |_template2= is the /sandbox subpage of the current page's root page. Template names should be entered as you would use them in a normal template invocation, i.e. 3x, not Template:3x. If you need to test a page in the main namespace, simply use a bare colon prefix, i.e. :article name.
|
|_template= |
An alias for |_template1= . If both |_template= and |_template1= are specified, the former takes precedence and the latter is ignored.
|
|_showtemplate1= ,|_showtemplate2= ,|_showtemplate3= … |
If this is set to no or n , then no output is shown for that template. This is useful if you only want to show either the main template or the sandbox template.
|
|_heading1= ,|_heading2= ,|_heading3= … |
Custom headings for each of the template outputs. |
|_showheader= |
If this is set to no or n , then no headers are shown.
|
|_resetRefs= |
If set to yes or y , any references generated by the templates tested are reset after each template is expanded.
|
|_showcode= |
Show the template code used to make the test case in addition to the parsed output. If an invocation is specified with the |_code= parameter (see below), then that is used. Otherwise, an approximation is generated from the arguments. This approximation is not perfect―white space in named arguments is lost and duplicate arguments are ignored—but it should be fine for template code that is input all on one line without spaces between parameters.
|
|_code= |
Used to specify template code inside <nowiki>...</nowiki> tags in concert with the |_showcode= parameter (see above) to display the template invocation while preserving white space. You must use the magic word __TEMPLATENAME__ instead of the template name. For example: | _code = <nowiki>{{__TEMPLATENAME__|first|second|foo=bar}}</nowiki> .
|
Test case formats
[edit source]
Default format
[edit source]This format is used when |_format=
is not specified, or when it's set to |_format=default
. It is not impacted by any extra parameters.
Example
[edit source]{{Ombox}}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
{{Ombox/sandbox}}
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
Columnar format
[edit source]Set |_format=columns
to arrange the test cases side-by-side in a table. This is especially useful for comparing long and thin templates, such as infoboxes. It is impacted by the following extra parameters:
Parameter | Description |
---|---|
|_class= |
Extra CSS classes to declare for the table itself. For instance, |_class=wikitable formats it as a standard wikitable.
|
|_style= |
Custom inline CSS style declarations for the table itself. |
|_caption= |
Custom caption for the table, replacing the default 'Side-by-side comparison'. |
|_rowheader= |
An extra heading for the row containing the templates. |
|_heading0= |
If |_rowheader= is supplied, this is an optional heading above it in the template row.
|
|_before= |
This text is displayed before the output of each template. |
|_after= |
This text is displayed after the output of each template. |
Example
[edit source]{{Ombox}} | {{Ombox/sandbox}} | ||||
---|---|---|---|---|---|
|
|
Rows and tablerows formats
[edit source]Setting |_format=rows
or |_format=tablerows
arranges the test case outputs in a vertical line, one above another, in a table. These two formats differ primarily in the placement of the headings: |_format=rows
puts them above the table, whereas |_format=tablerows
has them to the left of the table. They are impacted by the following extra parameters:
Parameter | Description |
---|---|
|_class= |
Extra CSS classes to declare for the table itself. For instance, |_class=wikitable formats it as a standard wikitable.
|
|_style= |
Custom inline CSS style declarations for the table itself. |
|_caption= |
Custom caption for the table. |
Rows example
[edit source]{{Ombox}} | ||
| ||
{{Ombox/sandbox}} | ||
|
Tablerows example
[edit source]{{Ombox}} | → |
| ||
---|---|---|---|---|
{{Ombox/sandbox}} | → |
|
Inline format
[edit source]Set |_format=inline
for test cases that can be displayed entirely on a single line. If used with templates that display over multiple lines, it may produce unexpected results. This format creates a bulleted list by placing *
before each line of output. It is impacted by the following extra parameters:
Parameter | Description |
---|---|
|_addline= |
Text to be added as the last entry in the list, after the template outputs. |
|_prefix= |
Character to replace * with at the start of each line of output. Using |_prefix=# would display an ordered list instead.
|
As this format starts with a bullet, a new line will always be inserted at the start of the template output due to MediaWiki Bug #14974. |
Examples
[edit source]- Using {{Smallcaps}}
Default:
- Lorem ipsum
- Lorem ipsum
With |_showcode=yes
:
{{Smallcaps|Lorem ipsum}}
→ Lorem ipsum{{Smallcaps/sandbox|Lorem ipsum}}
→ Lorem ipsum
- Using {{Rndfrac}}
With |_prefix=#
and |_addline=
:
{{Rndfrac|0.1234|8}}
→ 1⁄8{{Rndfrac/sandbox|0.1234|8}}
→ 1⁄8{{Dec to frac|0.125|8}}
→ 1⁄8
Output
[edit source]The |_output=
parameter allows changes in how the template's output is displayed. It should work with any of the test case formats; the following examples use |format=tablerows
.
Default output
[edit source]The default output is displayed when the |_output=
parameter is not specified, or when it is set to any unsupported value; this example uses |_output=default
.
{{URL}} | → | example.com |
---|---|---|
{{URL/sandbox}} | → | example.com |
Nowiki output
[edit source]A nowiki version of the template's output is displayed when |_output=nowiki
. This is helpful if there are differences in the underlying wikitext which are not visible in the default output.
{{URL}} | → | <span class="url">[https://www.example.com example.com]</span> |
---|---|---|
{{URL/sandbox}} | → | <span class="url">[https://www.example.com example.com]</span> |
Nowiki+ output
[edit source]Both the default output and nowiki version are displayed when |_output=nowiki+
.
{{URL}} | → |
example.com<span class="url">[https://www.example.com example.com]</span> |
---|---|---|
{{URL/sandbox}} | → |
example.com<span class="url">[https://www.example.com example.com]</span> |
Collapsible test cases
[edit source]If |_collapsible=y
or |_collapsible=yes
, the test case is made collapsible. The test case is collapsed and given a green heading if all the template outputs are the same. If any of the template outputs differ, the test case is expanded and given a yellow heading. It has the following extra parameters:
Parameter | Description |
---|---|
|_title=
|
Use |_title= to display a custom title for collapsible test cases.
|
|_titlecode=
|
Use |_titlecode=yes to display the template's code as the title of a collapsible test case.
|
|_notcollapsed=
|
If |_notcollapsed=yes or |_notcollapsed=y , the test case will always be expanded upon loading the page. If set to no or n , it will always be collapsed upon loading the page. This setting overrides the default functionality in which the test case is collapsed unless two or more outputs do not match.
|
Examples
[edit source]Default title
[edit source]{{Ombox}}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
{{Ombox/sandbox}}
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
With |_title=
[edit source]{{Ombox}} | {{Ombox/sandbox}} | ||||
---|---|---|---|---|---|
|
|
{{Ombox}} | ||
| ||
{{Ombox/sandbox}} | ||
|
{{Ombox}}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
{{Tmbox}}
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
With |_titlecode=yes
[edit source]This is useful for templates with a small number of parameters. It displays the template code in the title, eliminating the need for both |_title=
and |_showcode=yes
. For actual tests implemented with |_titlecode=yes
, see Template:URL/testcases.
{{URL}} | → |
www.example.com<span class="url">[http://www.example.com www.example.com]</span> |
---|---|---|
{{URL/sandbox}} | → |
www.example.com<span class="url">[http://www.example.com www.example.com]</span> |
With |_notcollapsed=yes
[edit source]If |_notcollapsed=yes
, the test case will always be expanded upon loading the page. This setting overrides the default functionality in which the test case is collapsed unless two or more outputs do not match. The following example would normally be collapsed, as indicated by green background of title:
With |_notcollapsed=no
[edit source]If |_notcollapsed=no
, the test case will always be collapsed upon loading the page. This setting overrides the default functionality in which the test case is collapsed unless two or more outputs do not match. The following would normally be expanded, as indicated by yellow background of title:
Additional examples
[edit source]With |_showcode=
[edit source]Usage
[edit source]{{Test case|_template1=Ombox|_showcode=yes|text=Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.}}
Output
[edit source]{{Ombox|text=Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.}}
{{Ombox}}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
{{Ombox/sandbox}}
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
With |_showcode=
, using a nowiki invocation via |_code=
[edit source]Usage
[edit source]{{Test case|_template1=Ombox|_showcode=yes |_code = <nowiki>{{__TEMPLATENAME__ | text = Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. }}</nowiki> |text=Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. }}
Output
[edit source]{{Ombox | text = Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. }}
{{Ombox}}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
{{Ombox/sandbox}}
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
With |_showcode=
and |_collapsible=
[edit source]Usage
[edit source]{{Test case|_template1=Ombox|_showcode=yes|_collapsible=yes|text=Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.}}
Output
[edit source]{{Ombox|text=Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.}}
{{Ombox}}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
{{Ombox/sandbox}}
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
Technical limitations
[edit source]The template has the following known technical limitations:
- An error will be generated if processing the entire page takes more than 10 seconds. This is an intentional limit in the Scribunto extension that runs Module:Template test case, on which this template is based. If a test cases page takes more than 10 seconds to load, you may need to split it up into different pages.
- When generating the template code used with
|_showcode=
, whitespace in named parameters is ignored, numbered parameters like|1=
may be incorrectly displayed as positional parameters, and duplicate parameters are ignored. This is due to how template parameters are processed before they are passed to Module:Template test case. - When using a template invocation inside nowiki tags with the
|_code=
parameter, the HTML entities <, > and " are converted to the literal characters <, > and ". This is due to the way nowiki tags work. - For collapsible test cases, all text inside each extension tag (e.g.
<ref>
,<references>
,<gallery>
or<nowiki>
) is treated as equal. These tags are converted to strip markers before they are passed to the template, and all strip markers include a unique hexadecimal string. Even if strip markers were unstripped before being compared, the same wikitext would not be guaranteed to result in exactly the same unstripped code. So this module ignores the content of strip markers for the purposes of testing equality. This has the unwanted side effect that e.g. all<ref>...</ref>
tags are treated as though they are equal, but should be adequate for most uses.