<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.stiles.casa/index.php?action=history&amp;feed=atom&amp;title=Module%3AUnitTests%2Fdoc</id>
	<title>Module:UnitTests/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.stiles.casa/index.php?action=history&amp;feed=atom&amp;title=Module%3AUnitTests%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://wiki.stiles.casa/index.php?title=Module:UnitTests/doc&amp;action=history"/>
	<updated>2026-05-07T09:05:36Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.2</generator>
	<entry>
		<id>https://wiki.stiles.casa/index.php?title=Module:UnitTests/doc&amp;diff=6559&amp;oldid=prev</id>
		<title>Maxwells: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.stiles.casa/index.php?title=Module:UnitTests/doc&amp;diff=6559&amp;oldid=prev"/>
		<updated>2022-06-11T21:07:39Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:07, 11 June 2022&lt;/td&gt;
				&lt;/tr&gt;
&lt;!-- diff cache key wikidb:diff::1.12:old-6558:rev-6559 --&gt;
&lt;/table&gt;</summary>
		<author><name>Maxwells</name></author>
	</entry>
	<entry>
		<id>https://wiki.stiles.casa/index.php?title=Module:UnitTests/doc&amp;diff=6558&amp;oldid=prev</id>
		<title>en&gt;Aidan9382: /* preprocess_equals_preprocess */ consistent spacing</title>
		<link rel="alternate" type="text/html" href="https://wiki.stiles.casa/index.php?title=Module:UnitTests/doc&amp;diff=6558&amp;oldid=prev"/>
		<updated>2022-05-20T10:39:17Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;preprocess_equals_preprocess: &lt;/span&gt; consistent spacing&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;UnitTests provides a unit test facility that can be used by other scripts using &amp;#039;&amp;#039;&amp;#039;require&amp;#039;&amp;#039;&amp;#039;. See [[Stiles.casa Wiki:Lua#Unit_testing]] for details. Following is a sample from [[Module:Example/testcases]]:&lt;br /&gt;
&lt;br /&gt;
{{#tag:syntaxhighlight|&lt;br /&gt;
-- Unit tests for [[Module:Example]]. Click talk page to run tests.&lt;br /&gt;
local p = require(&amp;#039;Module:UnitTests&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
function p:test_hello()&lt;br /&gt;
    self:preprocess_equals(&amp;#039;{{#invoke:Example | hello}}&amp;#039;, &amp;#039;Hello World!&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;br /&gt;
|lang=&amp;quot;lua&amp;quot;}}&lt;br /&gt;
&lt;br /&gt;
The talk page [[Module talk:Example/testcases]] executes it with &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#invoke: Example/testcases | run_tests}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;. Test methods like test_hello above must begin with &amp;quot;test&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Methods ==&lt;br /&gt;
=== run_tests ===&lt;br /&gt;
* {{code|1=run_tests}}: Runs all tests. Normally used on talk page of unit tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    {{#invoke:Example/testcases|run_tests}}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If {{code|1=differs_at=1}} is specified, a column will be added showing the first character position where the expected and actual results differ. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    {{#invoke:Example/testcases|run_tests|differs_at=1}}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If {{code|live_sandbox=yes}} is specified, the header will show the columns &amp;quot;Test&amp;quot;, &amp;quot;Live&amp;quot;, &amp;quot;Sandbox&amp;quot;, &amp;quot;Expected&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals ===&lt;br /&gt;
* {{code|1=preprocess_equals(text, expected, options)}}: Gives a piece of wikitext to preprocess and an expected resulting value. Scripts and templates can be invoked in the same manner they would be in a page.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
    self:preprocess_equals(&amp;#039;{{#invoke:Example | hello}}&amp;#039;, &amp;#039;Hello, world!&amp;#039;,{nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals_many ===&lt;br /&gt;
* {{code|1=preprocess_equals_many(prefix, suffix, cases, options)}}: Performs a series of preprocess_equals() calls on a set of given pairs. Automatically adds the given prefix and suffix to each text.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
    self:preprocess_equals_many(&amp;#039;{{#invoke:Example | hello_to |&amp;#039;, &amp;#039;}}&amp;#039;, {&lt;br /&gt;
        {&amp;#039;John&amp;#039;, &amp;#039;Hello, John!&amp;#039;},&lt;br /&gt;
        {&amp;#039;Jane&amp;#039;, &amp;#039;Hello, Jane!&amp;#039;},&lt;br /&gt;
    },{nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals_preprocess ===&lt;br /&gt;
* {{code|1=preprocess_equals_preprocess(text, expected, options)}}: Gives two pieces of wikitext to preprocess and determines if they produce the same value. Useful for comparing scripts to existing templates.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
    self:preprocess_equals_preprocess(&amp;#039;{{#invoke:Example | hello}}&amp;#039;, &amp;#039;{{Hello}}&amp;#039;,{nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals_preprocess_many ===&lt;br /&gt;
* {{code|1=preprocess_equals_preprocess_many(prefix1, suffix1, prefix2, suffix2, cases, options)}}: Performs a series of preprocess_equals_preprocess() calls on a set of given pairs. The prefix/suffix supplied for both arguments is added automatically. If in any case the second part is not specified, the first part will be used.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
    self:preprocess_equals_preprocess_many(&amp;#039;{{#invoke:ConvertNumeric | numeral_to_english|&amp;#039;, &amp;#039;}}&amp;#039;, &amp;#039;{{spellnum&amp;#039;, &amp;#039;}}&amp;#039;, {&lt;br /&gt;
        {&amp;#039;2&amp;#039;}, -- equivalent to {&amp;#039;2&amp;#039;,&amp;#039;2&amp;#039;},&lt;br /&gt;
        {&amp;#039;-2&amp;#039;, &amp;#039;-2.0&amp;#039;},&lt;br /&gt;
    },{nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== preprocess_equals_sandbox_many ===&lt;br /&gt;
* {{code|1=preprocess_equals_sandbox_many(module, function, cases, options)}}: Performs a series of preprocess_equals_compare() calls on a set of given pairs. The test compares the live version of the module vs the /sandbox version and vs an expected result.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
    self:preprocess_equals_sandbox_many(&amp;#039;{{#invoke:Example&amp;#039;, &amp;#039;hello_to&amp;#039;, {&lt;br /&gt;
        {&amp;#039;John&amp;#039;, &amp;#039;Hello, John!&amp;#039;},&lt;br /&gt;
        {&amp;#039;Jane&amp;#039;, &amp;#039;Hello, Jane!&amp;#039;},&lt;br /&gt;
    },{nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== equals ===&lt;br /&gt;
* {{code|1=equals(name, actual, expected, options)}}: Gives a computed value and the expected value, and checks if they are equal according to the == operator. Useful for testing modules that are designed to be used by other modules rather than using #invoke.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
    self:equals(&amp;#039;Simple addition&amp;#039;, 2 + 2, 4,{nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== equals_deep ===&lt;br /&gt;
* {{code|1=equals_deep(name, actual, expected, options)}}: Like equals, but handles tables by doing a deep comparison. Neither value should contain circular references, as they are not handled by the current implementation and may result in an infinite loop.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
    self:equals_deep(&amp;#039;Table comparison&amp;#039;, createRange(1,3), {1,2,3},{nowiki=1})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Module:ScribuntoUnit]] – alternative unit test module&lt;br /&gt;
&lt;br /&gt;
&amp;lt;includeonly&amp;gt;{{#ifeq:{{SUBPAGENAME}}|sandbox||&lt;br /&gt;
&amp;lt;!-- Categories go here and interwikis go in Wikidata. --&amp;gt;&lt;br /&gt;
[[Category:Modules for test tools|Test tools, {{PAGENAME}}]]&lt;br /&gt;
[[Category:Modules that check for strip markers]]&lt;br /&gt;
}}&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>en&gt;Aidan9382</name></author>
	</entry>
</feed>