Changes
Jump to navigation
Jump to search
→See also: add link
{{Documentation subpage}}
{{Lua|Module:Template test case}}
<!-- Categories where indicated at the bottom of this page, please; interwikis at Wikidata -->
This template generates a table of side-by-side testcases comparing two or more templates. Each template is called with the same parameters.
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.
If no templates are specified explicitly, the module uses the base page of the current page as the first template, and its /sandbox subpage as the second template. If only one template is specified explicitly, its /sandbox subpage is used as the second template.
== Usage ==
'''Basic syntax'''
<pre>
{{Testcase table
| [param1] = [value1]
| [param2] = [value2]
| [param3] = [value3]
...
}}
</pre>
'''Full syntax'''
<pre>
{{Testcase table
| _format =
| _class =
| _style =
| _caption =
| _rowheader =
| _heading0 =
| _before =
| _after =
| _collapsible =
| _resetRefs =
| _code =
| _showcode =
| _showheader =
| _template =
| _template1 =
| _showtemplate1 =
| _heading1 =
| _template2 =
| _showtemplate2 =
| _heading2 =
| _template3 =
| _showtemplate3 =
| _heading3 =
...
| [param1] = [value1]
| [param2] = [value2]
| [param3] = [value3]
...
}}
</pre>
== Parameters ==
{| class="wikitable"
! Parameter !! Description
|-
| <code>_template1</code><br/><code>_template2</code><br/>''(etc)'' || Names of the templates to be processed. <code>_template1</code>'s default is the current page's {{tlx|basepage}}. If <code>_template1</code> is specified, the default for <code>_template2</code> is its /sandbox [[Wikipedia:Subpages|subpage]]; if not, the default for <code>_template2</code> is the /sandbox subpage of the current page's basepage. 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 you can use a colon prefix, i.e. ":''article name''".
|-
| <code>_template</code> || Alias for <code>_template1</code>. If both <code>_template</code> and <code>_template1</code> are specified, <code>_template</code> will take precedence.
|-
| <code>_showtemplate1</code>, <code>_showtemplate2</code>, <code>_showtemplate3</code>... || If this is set to "no", then no output is shown for that template. This is useful if you only want to show the main template, or if you only want to show the sandbox template.
|-
| <code>_heading1</code><br/><code>_heading2</code><br/>''(etc)'' || Custom headings for each of the templates.
|-
| <code>_showheader</code> || If this is set to "no", then no headers are shown.
|-
| <code>_class</code> || HTML classes for the table. Use {{para|_class|wikitable}} to format the table as a wikitable.
|-
| <code>_style</code> || Custom inline CSS for the table.
|-
| <code>_caption</code> || Custom caption for the table. The default is "Side by side comparison".
|-
| <code>_rowheader</code> || An extra heading for the row containing the templates.
|-
| <code>_heading0</code> || If <code>_rowheader</code> is supplied, this is an optional heading above it in the template row.
|-
| <code>_before</code>, <code>_after</code> || This text is displayed before or after (respectively) the output of each template. These parameters introduce no whitespace on their own.
|-
| <code>_collapsible</code> || If set to "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.
|-
| <code>_resetRefs</code> || If set to "yes", any references generated by the templates tested are reset after each template is expanded.
|-
| <code>_showcode</code> || Show the template code used to make the test case. If an invocation is specified with the <code>_code</code> parameter, then that is used. Otherwise, an approximation is generated from the arguments. This approximation is not perfect (whitespace in named arguments is lost; duplicate arguments are ignored) but it should be fine for template code that is input all on one line without spaces between parameters.
|-
| <code>_code</code> || Used to specify template code inside {{tag|nowiki}} tags. This is used with the _showcode option to display the template invocation while preserving whitespace. You must use the magic word "__TEMPLATENAME__" instead of the template name. For example: {{para|1=_code|2=<nowiki><nowiki>{{__TEMPLATENAME__|first|second|foo=bar}}</nowiki></nowiki>}}. If you find yourself using this option a lot, you may want to consider using {{tl|Test case nowiki}}, which allows you to generate the entire test case from template code in nowiki tags, saving you from typing in all the arguments twice. <p>Note: due to the way nowiki tags work, the template treats the [[HTML entities]] &lt;, &gt; and &quot; as if they were the literal characters <, > and " when used with this parameter.</p>
|-
| <code>_format</code> || It is possible to use this parameter to display completely different formats, for example test cases arranged in rows. Not all of the parameters here will work with the other formats. For details, see [[Template:Test case]]'s documentation.
|}
== Examples ==
===Example 1===
using [[Template:Year in South Africa]], with {{para|_showcode|true}}
;Usage
<pre style="white-space:pre-wrap; overflow:auto; background-color:#eee;">
{{Testcase table
|_template=Year in South Africa
|_showcode=true
|1600s |nocat=true
}}
</pre>
;Output
{{Testcase table
|_template=Year in South Africa
|_showcode=true
|1600s |nocat=true
}}
===Example 2===
using [[Template:Infobox]], with {{para|_showcode|true}} and {{para|_caption|&nbsp;}}
;Usage
<pre style="white-space:pre-wrap; overflow:auto; background-color:#eee;">
{{Testcase table
|_template=Infobox
|_showcode=true
|_caption=&nbsp;
|title=title |above=above
|header1=header1
|label2=label2 |data2=data2
|label3=label3 |data3=data3
|below=below
}}
</pre>
;Output
{{Testcase table
|_template=Infobox
|_showcode=true
|_caption=
|title=title |above=above
|header1=header1
|label2=label2 |data2=data2
|label3=label3 |data3=data3
|below=below
}}
== Technical limitations ==
See [[Template:Test case#Technical limitations]] for this template's known technical limitations.
== See also ==
Templates invoking [[Module:Template test case]]:
* [[Template:Test case]] – a generalised test case template
* [[Template:Testcase rows]] – for a table of test cases arranged in rows
* [[Template:Inline test case]] – for test cases with small invocations and small output
* [[Template:Collapsible test case]] – for test cases collapsed by default if the results are the same
* [[Template:Test case nowiki]] – for test cases from template invocations enclosed in {{tag|nowiki}} tags
* [[Template:Nowiki template demo]] – for use in template documentation
Other templates:
* [[Template:Parameter names example]] – produces an example of a template by using the names of that template's parameters as the values for those parameters.
<includeonly>{{When on basepage
| <!-- Categories below here, please; interwikis at Wikidata -->
[[Category:Template test cases| ]]
[[Category:Template namespace templates]]
}}</includeonly>
{{Lua|Module:Template test case}}
<!-- Categories where indicated at the bottom of this page, please; interwikis at Wikidata -->
This template generates a table of side-by-side testcases comparing two or more templates. Each template is called with the same parameters.
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.
If no templates are specified explicitly, the module uses the base page of the current page as the first template, and its /sandbox subpage as the second template. If only one template is specified explicitly, its /sandbox subpage is used as the second template.
== Usage ==
'''Basic syntax'''
<pre>
{{Testcase table
| [param1] = [value1]
| [param2] = [value2]
| [param3] = [value3]
...
}}
</pre>
'''Full syntax'''
<pre>
{{Testcase table
| _format =
| _class =
| _style =
| _caption =
| _rowheader =
| _heading0 =
| _before =
| _after =
| _collapsible =
| _resetRefs =
| _code =
| _showcode =
| _showheader =
| _template =
| _template1 =
| _showtemplate1 =
| _heading1 =
| _template2 =
| _showtemplate2 =
| _heading2 =
| _template3 =
| _showtemplate3 =
| _heading3 =
...
| [param1] = [value1]
| [param2] = [value2]
| [param3] = [value3]
...
}}
</pre>
== Parameters ==
{| class="wikitable"
! Parameter !! Description
|-
| <code>_template1</code><br/><code>_template2</code><br/>''(etc)'' || Names of the templates to be processed. <code>_template1</code>'s default is the current page's {{tlx|basepage}}. If <code>_template1</code> is specified, the default for <code>_template2</code> is its /sandbox [[Wikipedia:Subpages|subpage]]; if not, the default for <code>_template2</code> is the /sandbox subpage of the current page's basepage. 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 you can use a colon prefix, i.e. ":''article name''".
|-
| <code>_template</code> || Alias for <code>_template1</code>. If both <code>_template</code> and <code>_template1</code> are specified, <code>_template</code> will take precedence.
|-
| <code>_showtemplate1</code>, <code>_showtemplate2</code>, <code>_showtemplate3</code>... || If this is set to "no", then no output is shown for that template. This is useful if you only want to show the main template, or if you only want to show the sandbox template.
|-
| <code>_heading1</code><br/><code>_heading2</code><br/>''(etc)'' || Custom headings for each of the templates.
|-
| <code>_showheader</code> || If this is set to "no", then no headers are shown.
|-
| <code>_class</code> || HTML classes for the table. Use {{para|_class|wikitable}} to format the table as a wikitable.
|-
| <code>_style</code> || Custom inline CSS for the table.
|-
| <code>_caption</code> || Custom caption for the table. The default is "Side by side comparison".
|-
| <code>_rowheader</code> || An extra heading for the row containing the templates.
|-
| <code>_heading0</code> || If <code>_rowheader</code> is supplied, this is an optional heading above it in the template row.
|-
| <code>_before</code>, <code>_after</code> || This text is displayed before or after (respectively) the output of each template. These parameters introduce no whitespace on their own.
|-
| <code>_collapsible</code> || If set to "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.
|-
| <code>_resetRefs</code> || If set to "yes", any references generated by the templates tested are reset after each template is expanded.
|-
| <code>_showcode</code> || Show the template code used to make the test case. If an invocation is specified with the <code>_code</code> parameter, then that is used. Otherwise, an approximation is generated from the arguments. This approximation is not perfect (whitespace in named arguments is lost; duplicate arguments are ignored) but it should be fine for template code that is input all on one line without spaces between parameters.
|-
| <code>_code</code> || Used to specify template code inside {{tag|nowiki}} tags. This is used with the _showcode option to display the template invocation while preserving whitespace. You must use the magic word "__TEMPLATENAME__" instead of the template name. For example: {{para|1=_code|2=<nowiki><nowiki>{{__TEMPLATENAME__|first|second|foo=bar}}</nowiki></nowiki>}}. If you find yourself using this option a lot, you may want to consider using {{tl|Test case nowiki}}, which allows you to generate the entire test case from template code in nowiki tags, saving you from typing in all the arguments twice. <p>Note: due to the way nowiki tags work, the template treats the [[HTML entities]] &lt;, &gt; and &quot; as if they were the literal characters <, > and " when used with this parameter.</p>
|-
| <code>_format</code> || It is possible to use this parameter to display completely different formats, for example test cases arranged in rows. Not all of the parameters here will work with the other formats. For details, see [[Template:Test case]]'s documentation.
|}
== Examples ==
===Example 1===
using [[Template:Year in South Africa]], with {{para|_showcode|true}}
;Usage
<pre style="white-space:pre-wrap; overflow:auto; background-color:#eee;">
{{Testcase table
|_template=Year in South Africa
|_showcode=true
|1600s |nocat=true
}}
</pre>
;Output
{{Testcase table
|_template=Year in South Africa
|_showcode=true
|1600s |nocat=true
}}
===Example 2===
using [[Template:Infobox]], with {{para|_showcode|true}} and {{para|_caption|&nbsp;}}
;Usage
<pre style="white-space:pre-wrap; overflow:auto; background-color:#eee;">
{{Testcase table
|_template=Infobox
|_showcode=true
|_caption=&nbsp;
|title=title |above=above
|header1=header1
|label2=label2 |data2=data2
|label3=label3 |data3=data3
|below=below
}}
</pre>
;Output
{{Testcase table
|_template=Infobox
|_showcode=true
|_caption=
|title=title |above=above
|header1=header1
|label2=label2 |data2=data2
|label3=label3 |data3=data3
|below=below
}}
== Technical limitations ==
See [[Template:Test case#Technical limitations]] for this template's known technical limitations.
== See also ==
Templates invoking [[Module:Template test case]]:
* [[Template:Test case]] – a generalised test case template
* [[Template:Testcase rows]] – for a table of test cases arranged in rows
* [[Template:Inline test case]] – for test cases with small invocations and small output
* [[Template:Collapsible test case]] – for test cases collapsed by default if the results are the same
* [[Template:Test case nowiki]] – for test cases from template invocations enclosed in {{tag|nowiki}} tags
* [[Template:Nowiki template demo]] – for use in template documentation
Other templates:
* [[Template:Parameter names example]] – produces an example of a template by using the names of that template's parameters as the values for those parameters.
<includeonly>{{When on basepage
| <!-- Categories below here, please; interwikis at Wikidata -->
[[Category:Template test cases| ]]
[[Category:Template namespace templates]]
}}</includeonly>