Module:UnitTests/documentation

This module facilitates creating unit tests for Lua modules.

Put the following at : Then put the following on :

Tests should be written as Lua methods whose names start with lua. The lua object contains the following methods, which may be called from the method:


 * lua
 * Will check whether expanding templates in lua results in lua.


 * lua
 * lua
 * Will check whether expanding templates in lua and lua results in the same string.


 * lua
 * lua
 * Will check whether two primitive values are equal. lua will be used as the row header. When the value is a table, lua should be used.


 * lua
 * Will check whether two values, which may be tables, are equal. lua will be used as the row header.


 * lua
 * Create a heading in the table, which appears after the last-called checking function.


 * lua
 * Requires an array as its first argument. Iterates over the items in the array. If the item in the array is an array, a function will be called on the contents of the array. If the item is a string, a heading is created using lua.
 * Two variations:
 * lua
 * Here, lua is a string, the name of a method in the lua object. For instance, lua calls lua and lua. This lua method must be defined separately.
 * lua
 * Same as above, except the second argument is a function. For instance, lua will call lua and lua.

lua should be given in a table or omitted. Currently, these are the options supported:
 * lua: Causes both the expected and the actual values to be wrapped in &lt;nowiki&gt; tags when rendering the results table.
 * lua: A comment to be added to the rightmost column of table.
 * lua: A function to yield the form actually displayed in the table. This is used in testcases for pronunciation modules to make the IPA transcriptions display with the correct fonts.
 * lua: If this is set to lua (or any truthy value besides a function), failing tests will have the first offending character highlighted in red (that is, the first character in the "actual" string that is different from the corresponding character in the "expected" string). If this is a function, the character will be highlighted using the function. (Currently only available in the lua checking function. The highlighter will highlight combining characters together with the characters they are placed on.)