Template:Test case/doc

From Path of Exile Wiki
Jump to navigation Jump to search

This subpage provides documentation for Template:Test case.

Lua logo

This template uses the following modules:

This template is an easy way to write test cases that examine both the main and sandbox version of a template. It will even show you when the outputs of the main and sandbox version differ, so you can test changes more easily.

There's lots of built-in functionality, that you can find in the Wikipedia documentation. But here is a guide to how to write quick and easy test cases.

Suppose I want to write a quick testcases page for the {{Update}} template. There are two cases I want to test:

{{Update|reason=This has all changed in [[version 3.12.0]].|talk=Changes in version 3.12.0}}

and

{{Update|section|reason=This section makes no sense}}

To do that, here's all I need to put on the Template:Update/testcases page:

{{Testcases notice}}
{{Test case|_title=With reason and talk link|reason=This has all changed in [[version 3.12.0]]|talk=Changes in version 3.12.0}}
{{Test case|1=section|reason=This section makes no sense}}
  • The {{Testcases notice}} template puts a notice at the top of the page giving information about how things work.
  • The first {{Test case}} template runs the first test.
    • The parameters with names that don't start with an underline are parameters to the template being tested. So in this case, we're passing the parameters |reason=This has all changed in [[version 3.12.0]]|talk=Changes in version 3.12.0 to the {{Update}} template.
    • Any parameter starting with an underline controls the behavior of the {{Test case}} template itself. Normally, the only parameter like this that you may need to use is |_title=, which sets the title of the test case -- in this case, |_title=With reason and talk link.
  • The second {{Test case}} template runs the second test.
    • There are two differences here. The first is that we're not bothering to set |_title=. That's fine; the template will use the code you're calling as the title. The second difference is that the code that we want to test has an unnamed parameter, |section. We express that in the test case by adding |1=section.

That's it! Now the Template:Update/testcases page will show these test cases, demonstrating the output from both the main and sandbox versions of the template. The title bar for each test case will be green if the outputs of the main and sandbox templates match exactly, and yellow if they do not.

Debugging tip: If the title bar for a test case is yellow but you can't see any difference between the outputs of the main and sandbox templates, you can temporarily add |_output= to the parameters in the affected test. This will show the HTML produced by each template, and you can compare the two.

By default, all test cases display in collapsible format. You can override this by setting |_collapsible=false in a test case.
If you do not specify a |_title=, the code you're testing will be displayed as the title of the test case, as if |_titlecode= were true.

This template was adapted from Template:Test case/doc on Wikipedia.
Adaptation is noted for reference and attribution only. This template may differ from the original in function or in usage.