Module:Convert/tester/doc
![]() | This is a documentation subpage for Module:Convert/tester. It may contain usage information, categories and other content that is not part of the original module page. |
This module runs unit tests to compare template output with expected text.
While intended for testing Module:Convert, the tester should be useful with other templates that require many tests using a simple format for the test input.
Example:
- Module:Convert/sandbox/testcases – templates to be tested, with expected outputs
- Module talk:Convert/sandbox/testcases – view test results
It is not necessary to save the testcases page before viewing test results. For example, Module:Convert/sandbox/testcases could be edited to change the tests. While still editing that page, paste "Module talk:Convert/sandbox/testcases
" (without quotes) into the page title box under "Preview page with this template", then click "Show preview".
The testcases talk page (for example, Module talk:Convert/sandbox/testcases) contains:
{{#invoke:Convert/sandbox/testcases | run_tests }}
The testcases module page (for example, Module:Convert/sandbox/testcases) may contain:
local tests = [==[ A line without a template, like this line, is ignored. {{convert/sandbox|1|acre|lk=on}} 1 [[acre]] (0.40 [[hectare|ha]]) {{convert/sandbox|1|m2|acres|lk=on}} 1 [[square metre]] (0.00025 [[acre]]s) {{convert/sandbox|0.16|/l|2|disp=table}} align="right"|0.16\n|align="right"|0.61 ]==] local p = require('Module:Convert/tester') p.tests = tests return p
The tests
variable is a multiline string. Any line without a template is ignored. Processed lines consist of a template, then whitespace, then the wikitext that should result from expanding the template.
The expected output must be entered in a single line. If the template outputs multiple lines, those lines must be joined with "\n" (two characters—backslash n
).
The templates do not have to be the same, for example, the following tests would work:
local tests = [==[ {{convert|12|m}} 12 metres (39 ft) {{convert/sandbox|12|m}} 12 metres (39 ft) {{age|1989|7|23|2003|7|14}} 13 {{age in days|2007|5|24|2008|4|23}} 335 ]==]