Module:Convert/tester/doc

From blackwiki
< Module:Convert‎ | tester
Revision as of 10:54, 24 September 2013 by blackwiki>Johnuniq (create)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This is the documentation page for Module:Convert/tester

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:

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&nbsp;[[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&nbsp;ft)
{{convert/sandbox|12|m}}                    12 metres (39&nbsp;ft)
{{age|1989|7|23|2003|7|14}}                 13
{{age in days|2007|5|24|2008|4|23}}         335

]==]