<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.limswiki.org/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://www.limswiki.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AUnitTests%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://www.limswiki.org/index.php?title=Module:UnitTests/doc&amp;action=history"/>
	<updated>2026-04-04T17:19:46Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>https://www.limswiki.org/index.php?title=Module:UnitTests/doc&amp;diff=13211&amp;oldid=prev</id>
		<title>Shawndouglas: Created as needed.</title>
		<link rel="alternate" type="text/html" href="https://www.limswiki.org/index.php?title=Module:UnitTests/doc&amp;diff=13211&amp;oldid=prev"/>
		<updated>2013-10-31T15:54:18Z</updated>

		<summary type="html">&lt;p&gt;Created as needed.&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 '''require'''. Following is a sample from [[Module:Bananas/testcases]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Unit tests for [[Module:Bananas]]. Click talk page to run tests.&lt;br /&gt;
local p = require('Module:UnitTests')&lt;br /&gt;
 &lt;br /&gt;
function p:test_hello()&lt;br /&gt;
    self:preprocess_equals('{{#invoke:Bananas | hello}}', 'Hello, world!')&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
return p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The talk page [[Module talk:Bananas/testcases]] executes it with &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#invoke: Bananas/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(differs_at)}}: Runs all tests. If &amp;quot;differs_at=1&amp;quot; is specified, a column will be added showing the first character position where the expected and actual results differ. Normally used on talk page of unit tests.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    {{#invoke:Bananas/testcases|run_tests}}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== preprocess_equals ===&lt;br /&gt;
* {{code|1=preprocess_equals(text, expected)}}: 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('{{#invoke:Bananas | hello}}', 'Hello, world!')&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== preprocess_equals_many ===&lt;br /&gt;
* {{code|1=preprocess_equals_many(prefix, suffix, cases)}}: 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('{{#invoke:BananasArgs | add |', '}}', {&lt;br /&gt;
        {'2|3', '5'},&lt;br /&gt;
        {'-2|2', '0'},&lt;br /&gt;
    })&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== preprocess_equals_preprocess ===&lt;br /&gt;
* {{code|1=preprocess_equals_preprocess(text, expected)}}: 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('{{#invoke:Bananas | hello}}', '{{Hello}}')&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== preprocess_equals_preprocess_many ===&lt;br /&gt;
* {{code|1=preprocess_equals_preprocess_many(prefix, suffix, cases)}}: 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('{{#invoke:Foo | spellnum |', '}}', '{{spellnum', '}}', {&lt;br /&gt;
        {'2'}, -- equivalent to {'2','2'},&lt;br /&gt;
        {'-2', '-2.0'},&lt;br /&gt;
    })&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== equals ===&lt;br /&gt;
* {{code|1=equals(name, actual, expected)}}: 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('Simple addition', 2 + 2, 4)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== equals_deep ===&lt;br /&gt;
* {{code|1=equals_deep(name, actual, expected)}}: 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('Table comparison', createRange(1,3), {1,2,3})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Shawndouglas</name></author>
	</entry>
</feed>