Jump to content

Module:Template test case/testcases

From Simple English Wikipedia, the free encyclopedia

This module provides a framework for making templates which produce a template test case. While test cases can be made manually, using Lua-based templates such as the ones provided by this module has the advantage that the template arguments only need to be input once, thus reducing the effort involved in making test cases and reducing the possibility of errors in the input.

This module should not usually be called directly. Instead, you should use one of the following templates:

Parameter-based templates:

The only difference between these templates is their default arguments. For example, it is possible to display test cases side by side in Template:Testcase rows by specifying |_format=columns

Nowiki-based templates:

It is also possible to use a format of {{#invoke:template test case|main|parameters}}. This uses the same defaults as Template:Test case; please see that page for documentation of the parameters.

There is no direct interface to this module for other Lua modules. Lua modules should generally use Lua-based test case modules such as Module:UnitTests or Module:ScribuntoUnit. If it is really necessary to use this module, you can use frame:expandTemplate with one of the templates listed above.

Configuration

[change source]

This module has a configuration module at Module:Template test case/config. You can edit it to add new wrapper templates, or to change the messages that the module outputs.

Tracking categories

[change source]

-- Unit tests for [[Module:Template test case]]. Click talk page to run tests.

local p = require('Module:UnitTests')

function p:test01_columns()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=columns |_caption=_caption |_rowheader=_rowheader |_heading0=_heading0 |_heading1=_heading1 |_heading2=_heading2 |_heading3=_heading3 |_before=_before |_after=_after |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        '{{#invoke:Template test case         |main |_format=columns |_caption=_caption |_rowheader=_rowheader |_heading0=_heading0 |_heading1=_heading1 |_heading2=_heading2 |_heading3=_heading3 |_before=_before |_after=_after |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}'
    )
end

function p:test01_columns_nowiki()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=columns |_caption=_caption |_rowheader=_rowheader |_heading0=_heading0 |_heading1=_heading1 |_heading2=_heading2 |_heading3=_heading3 |_before=_before |_after=_after |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        '{{#invoke:Template test case         |main |_format=columns |_caption=_caption |_rowheader=_rowheader |_heading0=_heading0 |_heading1=_heading1 |_heading2=_heading2 |_heading3=_heading3 |_before=_before |_after=_after |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        {nowiki=1}
    )
end

function p:test02_showheader()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=columns |_showheader=no |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        '{{#invoke:Template test case         |main |_format=columns |_showheader=no |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}'
    )
end

function p:test02_showheader_nowiki()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=columns |_showheader=no |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        '{{#invoke:Template test case         |main |_format=columns |_showheader=no |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        {nowiki=1}
    )
end

function p:test03_caption()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=columns |_caption=  |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        '{{#invoke:Template test case         |main |_format=columns |_caption=  |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}'
    )
end

function p:test03_caption_nowiki()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=columns |_caption=  |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        '{{#invoke:Template test case         |main |_format=columns |_caption=  |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        {nowiki=1}
    )
end

function p:test04_showcaption()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=columns |_showcaption=no |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        '{{#invoke:Template test case         |main |_format=columns |_showcaption=no |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}'
    )
end

function p:test04_showcaption_nowiki()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=columns |_showcaption=no |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        '{{#invoke:Template test case         |main |_format=columns |_showcaption=no |_template1=Commons-inline |_template2=Commons category-inline |_template3=Commons and category-inline |Lorem ipsum|Lorem ipsum}}',
        {nowiki=1}
    )
end

function p:test05_addline()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=inline |_showcode=yes |_template1=Height |m=1.51 |_addline=Output of Convert template: {{Cvt|1.51|m|frac=2}} }}',
        '{{#invoke:Template test case         |main |_format=inline |_showcode=yes |_template1=Height |m=1.51 |_addline=Output of Convert template: {{Cvt|1.51|m|frac=2}} }}'
    )
end

function p:test05_addline_nowiki()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=inline |_showcode=yes |_template1=Height |m=1.51 |_addline=Output of Convert template: {{Cvt|1.51|m|frac=2}} }}',
        '{{#invoke:Template test case         |main |_format=inline |_showcode=yes |_template1=Height |m=1.51 |_addline=Output of Convert template: {{Cvt|1.51|m|frac=2}} }}',
        {nowiki=1}
    )
end

function p:test06_output()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_output=nowiki |_format=inline |_showcode=yes |_template1=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_output=nowiki |_format=inline |_showcode=yes |_template1=Height |m=1.51}}'
    )
end

function p:test07_output()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_output=nowiki+ |_format=inline |_showcode=yes |_template1=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_output=nowiki+ |_format=inline |_showcode=yes |_template1=Height |m=1.51}}'
    )
end

function p:test08_prefix()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=inline |_prefix=# |_showcode=yes |_template1=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_format=inline |_prefix=# |_showcode=yes |_template1=Height |m=1.51}}'
    )
end

function p:test09_prefix()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_format=inline |_prefix=: |_template1=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_format=inline |_prefix=: |_template1=Height |m=1.51}}'
    )
end

function p:test10_collapsible()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_showcode=yes |_template=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_showcode=yes |_template=Height |m=1.51}}',
        {stripmarker=true}
    )
end

function p:test10_collapsible_nowiki()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_showcode=yes |_template=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_showcode=yes |_template=Height |m=1.51}}',
        {stripmarker=true, nowiki=true}
    )
end

function p:test11_collapsible_title()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_showcode=yes |_title=Testing height template |_template=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_showcode=yes |_title=Testing height template |_template=Height |m=1.51}}',
        {stripmarker=true}
    )
end

function p:test11_collapsible_title_nowiki()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_showcode=yes |_title=Testing height template |_template=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_showcode=yes |_title=Testing height template |_template=Height |m=1.51}}',
        {stripmarker=true, nowiki=true}
    )
end

function p:test12_collapsible_titlecode()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_titlecode=yes |_template=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_titlecode=yes |_template=Height |m=1.51}}'
    )
end

function p:test12_collapsible_titlecode_nowiki()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_titlecode=yes |_template=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_titlecode=yes |_template=Height |m=1.51}}',
        {nowiki=true}
    )
end


function p:test13_wantdiff()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template=Height |m=1.51}}',
        {stripmarker=true}
    )
end

function p:test13_wantdiff_nowiki()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template=Height |m=1.51}}',
        {stripmarker=true, nowiki=true}
    )
end

function p:test13_wantdiff_2_wiki()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template1=Commons-inline |_template2=Commons category-inline |Lorem ipsum|Lorem ipsum}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template1=Commons-inline |_template2=Commons category-inline |Lorem ipsum|Lorem ipsum}}',
        {stripmarker=true}
    )
end

function p:test13_wantdiff_2()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template1=Commons-inline |_template2=Commons category-inline |Lorem ipsum|Lorem ipsum}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template1=Commons-inline |_template2=Commons category-inline |Lorem ipsum|Lorem ipsum}}',
        {stripmarker=true, nowiki=true}
    )
end

function p:test13_wantdiff_3()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template1=Commons-inline |_template2=Commons category-inline |Lorem ipsum|Lorem ipsum}}',
        {stripmarker=true}
    )
end

function p:test13_wantdiff_3_nowiki()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template=Height |m=1.51}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template1=Commons-inline |_template2=Commons category-inline |Lorem ipsum|Lorem ipsum}}',
        {stripmarker=true, nowiki=true}
    )
end

function p:test14_equals_sign_parameter()
    self:preprocess_equals_preprocess(
        '{{#invoke:Template test case/sandbox |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template=3x |{{=}}|name=value}}',
        '{{#invoke:Template test case         |main |_collapsible=yes |_wantdiff=yes |_showcode=yes |_template=3x |{{=}}|name=value}}',
        {stripmarker=true, nowiki=true}
    )
end


return p