Jump to content

Module:Params/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Grufo (talk | contribs) at 13:01, 31 May 2024 (Helper subtemplate {{./tmaps}}: New section). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Here are some tools for testing {{#invoke:params}} and its sandbox version.

This is the testcases page for checking the behaviour of Module:Params.

As the module provides most of its functionalities only when called by templates, this page uses helper subtemplates to do its tests. You can find a complete list of these here. Several helper subtemplates come in two versions, one that depends on {{#invoke:params}} and one that depends on {{#invoke:params/sandbox}}. Example templates, used by the documentation page, are available at /doc/examples.

General tests

Multi-purpose helper subtemplates

Helper subtemplate {{./tmulti}}

The {{./tmulti}} subtemplate allows to simulate in one single call both the incoming parameters and the parameters manually concatenated to {{#invoke:params|...|function|...}}, using a single hyphen (-) as a delimiter between the two groups. This allows to make general experiments directly from the preview window without having to edit separate templates.

For instance, writing

{{module:params/testcases/tmulti|
	setting|i/p|<br />|: |list|
	-|hello|world|foo=bar}}

will simulate a call with |1=hello, |2=world, and |foo=bar to a template whose content is {{#invoke:params|setting|i/p|<br />|: |list}}, thus producing:

1: hello
2: world
foo: bar

information Note: An identical subtemplate that uses Module:Params/sandbox instead of Module:Params is available at {{./tmulti sandbox}}.

Single-purpose helper subtemplates

Helper subtemplate {{./tdelimiters}}

The {{./tdelimiters}} subtemplate allows to test the behaviour of delimiter strings between the arguments it was called with, invoking several functions of the module at once. For instance,

{{module:params/testcases/tdelimiters|foo|bar|Jupiter|hello=world}}

generates

list [HEADER][1=foo], [2=bar], [3=Jupiter] and [hello=world][FOOTER]
list_values [HEADER][foo], [bar], [Jupiter] and [world][FOOTER]
for_each [HEADER][1=foo], [2=bar], [3=Jupiter] and [hello=world][FOOTER]
call_for_each [HEADER][1=1][2=foo], [1=2][2=bar], [1=3][2=Jupiter] and [1=hello][2=world][FOOTER]
invoke_for_each [HEADER][1=1][2=foo], [1=2][2=bar], [1=3][2=Jupiter] and [1=hello][2=world][FOOTER]
magic_for_each [HEADER][foo], [bar], [Jupiter] and [world][FOOTER]
call_for_each_value [HEADER][1=foo], [1=bar], [1=Jupiter] and [1=world][FOOTER]
invoke_for_each_value [HEADER][1=foo], [1=bar], [1=Jupiter] and [1=world][FOOTER]
magic_for_each_value [HEADER][foo], [bar], [Jupiter] and [world][FOOTER]

information Note: An identical subtemplate that uses Module:Params/sandbox instead of Module:Params is available at {{./tdelimiters sandbox}}.

Helper subtemplate {{./tnumerical}}

The {{./tnumerical}} subtemplate allows to test the behaviour of functions that focus on numerical and sequential arguments. As these require at most two arguments, the template uses the |#first= and |#second= special parameters to do its tests. For instance,

{{module:params/testcases/tnumerical
	| #first = 2
	| #second = 2
	| -2 = minus two
	| 0 = zero
	| 1 = one
	| 2 = two
	| 3 = three
	| 19 = nineteen
	| 20 = twenty
}}

generates

Function name Result for |#first=2 and |#second=2
squeezing |1=minus two|2=zero|3=one|4=two|5=three|6=nineteen|7=twenty
filling_the_gaps |-2=minus two|-1=|0=zero|1=one|2=two|3=three|4=|5=|6=|7=|8=|9=|10=|11=|12=|13=|14=|15=|16=|17=|18=|19=nineteen|20=twenty
clearing |1=one|2=two|3=three
cutting|2|2] |-2=minus two|0=zero|16=nineteen|17=twenty
cropping|2|2 |0=zero|1=one|2=two|3=three
purging|2|2 |-2=minus two|0=zero|1=one|17=nineteen|18=twenty
backpurging|2|2 |-2=minus two|0=zero|1=three|17=nineteen|18=twenty
rotating Lua error: Module:Params: The function ‘rotating’ does not exist.
sorting_sequential_values |-2=minus two|0=zero|1=one|2=three|3=two|19=nineteen|20=twenty

information Note: An identical subtemplate that uses Module:Params/sandbox instead of Module:Params is available at {{./tnumerical sandbox}}.

Helper subtemplate {{./tmaps}}

The {{./tmaps}} subtemplate allows to test the behaviour of all the mapping_* and renaming_* class of modifiers using {{replace}} and {{#invoke:string|replace}} as callbacks. For instance,

{{module:params/testcases/tmaps
	| it is true = true
	| on the window = sorry, not today
}}

generates

mapping_by_calling
Modifier and arguments Result
...|mapping_by_calling|module:params/testcases/tdummy echo sb|let|foo|bar|2|hello|world|... it is true → [1=true][2=hello][3=world][foo=bar]
on the window → [1=sorry, not today][2=hello][3=world][foo=bar]
...|mapping_by_calling|module:params/testcases/tdummy echo sb|names_and_values|let|foo|bar|2|hello|world|... it is true → [1=it is true][2=true][3=hello][4=world][foo=bar]
on the window → [1=on the window][2=sorry, not today][3=hello][4=world][foo=bar]
...|mapping_by_calling|module:params/testcases/tdummy echo sb|values_and_names|let|foo|bar|2|hello|world|... it is true → [1=true][2=it is true][3=hello][4=world][foo=bar]
on the window → [1=sorry, not today][2=on the window][3=hello][4=world][foo=bar]
...|mapping_by_calling|module:params/testcases/tdummy echo sb|names_only|let|foo|bar|2|hello|world|... it is true → [1=it is true][2=hello][3=world][foo=bar]
on the window → [1=on the window][2=hello][3=world][foo=bar]
...|mapping_by_calling|module:params/testcases/tdummy echo sb|names_and_values_as|my_name|my_value|let|foo|bar|2|hello|world|... it is true → [1=hello][2=world][my_name=it is true][my_value=true][foo=bar]
on the window → [1=hello][2=world][my_name=on the window][my_value=sorry, not today][foo=bar]
...|mapping_by_calling|module:params/testcases/tdummy echo sb|names_only_as|my_name|let|foo|bar|2|hello|world|... it is true → [1=hello][2=world][my_name=it is true][foo=bar]
on the window → [1=hello][2=world][my_name=on the window][foo=bar]
...|mapping_by_calling|module:params/testcases/tdummy echo sb|values_only_as|my_value|let|foo|bar|2|hello|world|... it is true → [1=hello][2=world][foo=bar][my_value=true]
on the window → [1=hello][2=world][foo=bar][my_value=sorry, not today]
...|mapping_by_calling|module:params/testcases/tdummy echo sb|blindly|let|foo|bar|2|hello|world|... it is true → [1=hello][2=world][foo=bar]
on the window → [1=hello][2=world][foo=bar]
renaming_by_calling
Modifier and arguments Result
...|renaming_by_calling|module:params/testcases/tdummy echo sb|let|foo|bar|2|hello|world|... [1=it is true][2=hello][3=world][foo=bar] → true
[1=on the window][2=hello][3=world][foo=bar] → sorry, not today
...|renaming_by_calling|module:params/testcases/tdummy echo sb|names_and_values|let|foo|bar|2|hello|world|... [1=it is true][2=true][3=hello][4=world][foo=bar] → true
[1=on the window][2=sorry, not today][3=hello][4=world][foo=bar] → sorry, not today
...|renaming_by_calling|module:params/testcases/tdummy echo sb|values_and_names|let|foo|bar|2|hello|world|... [1=true][2=it is true][3=hello][4=world][foo=bar] → true
[1=sorry, not today][2=on the window][3=hello][4=world][foo=bar] → sorry, not today
...|renaming_by_calling|module:params/testcases/tdummy echo sb|values_only|let|foo|bar|2|hello|world|... [1=true][2=hello][3=world][foo=bar] → true
[1=sorry, not today][2=hello][3=world][foo=bar] → sorry, not today
...|renaming_by_calling|module:params/testcases/tdummy echo sb|names_and_values_as|my_name|my_value|let|foo|bar|2|hello|world|... [1=hello][2=world][my_name=it is true][my_value=true][foo=bar] → true
[1=hello][2=world][my_name=on the window][my_value=sorry, not today][foo=bar] → sorry, not today
...|renaming_by_calling|module:params/testcases/tdummy echo sb|names_only_as|my_name|let|foo|bar|2|hello|world|... [1=hello][2=world][my_name=it is true][foo=bar] → true
[1=hello][2=world][my_name=on the window][foo=bar] → sorry, not today
...|renaming_by_calling|module:params/testcases/tdummy echo sb|values_only_as|my_value|let|foo|bar|2|hello|world|... [1=hello][2=world][foo=bar][my_value=true] → true
[1=hello][2=world][foo=bar][my_value=sorry, not today] → sorry, not today
...|renaming_by_calling|module:params/testcases/tdummy echo sb|blindly|let|foo|bar|2|hello|world|... [1=hello][2=world][foo=bar] → sorry, not today
mapping_by_invoking
Modifier and arguments Result
...|mapping_by_invoking|params/testcases/mdummy|echo_sb|let|foo|bar|2|hello|world|... it is true → [1=true][2=hello][3=world][foo=bar]
on the window → [1=sorry, not today][2=hello][3=world][foo=bar]
...|mapping_by_invoking|params/testcases/mdummy|echo_sb|names_and_values|let|foo|bar|2|hello|world|... it is true → [1=it is true][2=true][3=hello][4=world][foo=bar]
on the window → [1=on the window][2=sorry, not today][3=hello][4=world][foo=bar]
...|mapping_by_invoking|params/testcases/mdummy|echo_sb|values_and_names|let|foo|bar|2|hello|world|... it is true → [1=true][2=it is true][3=hello][4=world][foo=bar]
on the window → [1=sorry, not today][2=on the window][3=hello][4=world][foo=bar]
...|mapping_by_invoking|params/testcases/mdummy|echo_sb|names_only|let|foo|bar|2|hello|world|... it is true → [1=it is true][2=hello][3=world][foo=bar]
on the window → [1=on the window][2=hello][3=world][foo=bar]
...|mapping_by_invoking|params/testcases/mdummy|echo_sb|names_and_values_as|my_name|my_value|let|foo|bar|2|hello|world|... it is true → [1=hello][2=world][my_name=it is true][my_value=true][foo=bar]
on the window → [1=hello][2=world][my_name=on the window][my_value=sorry, not today][foo=bar]
...|mapping_by_invoking|params/testcases/mdummy|echo_sb|names_only_as|my_name|let|foo|bar|2|hello|world|... it is true → [1=hello][2=world][my_name=it is true][foo=bar]
on the window → [1=hello][2=world][my_name=on the window][foo=bar]
...|mapping_by_invoking|params/testcases/mdummy|echo_sb|values_only_as|my_value|let|foo|bar|2|hello|world|... it is true → [1=hello][2=world][foo=bar][my_value=true]
on the window → [1=hello][2=world][foo=bar][my_value=sorry, not today]
...|mapping_by_invoking|params/testcases/mdummy|echo_sb|blindly|let|foo|bar|2|hello|world|... it is true → [1=hello][2=world][foo=bar]
on the window → [1=hello][2=world][foo=bar]
renaming_by_invoking
Modifier and arguments Result
...|renaming_by_invoking|params/testcases/mdummy|echo_sb|let|foo|bar|2|hello|world|... [1=it is true][2=hello][3=world][foo=bar] → true
[1=on the window][2=hello][3=world][foo=bar] → sorry, not today
...|renaming_by_invoking|params/testcases/mdummy|echo_sb|names_and_values|let|foo|bar|2|hello|world|... [1=it is true][2=true][3=hello][4=world][foo=bar] → true
[1=on the window][2=sorry, not today][3=hello][4=world][foo=bar] → sorry, not today
...|renaming_by_invoking|params/testcases/mdummy|echo_sb|values_and_names|let|foo|bar|2|hello|world|... [1=true][2=it is true][3=hello][4=world][foo=bar] → true
[1=sorry, not today][2=on the window][3=hello][4=world][foo=bar] → sorry, not today
...|renaming_by_invoking|params/testcases/mdummy|echo_sb|values_only|let|foo|bar|2|hello|world|... [1=true][2=hello][3=world][foo=bar] → true
[1=sorry, not today][2=hello][3=world][foo=bar] → sorry, not today
...|renaming_by_invoking|params/testcases/mdummy|echo_sb|names_and_values_as|my_name|my_value|let|foo|bar|2|hello|world|... [1=hello][2=world][my_name=it is true][my_value=true][foo=bar] → true
[1=hello][2=world][my_name=on the window][my_value=sorry, not today][foo=bar] → sorry, not today
...|renaming_by_invoking|params/testcases/mdummy|echo_sb|names_only_as|my_name|let|foo|bar|2|hello|world|... [1=hello][2=world][my_name=it is true][foo=bar] → true
[1=hello][2=world][my_name=on the window][foo=bar] → sorry, not today
...|renaming_by_invoking|params/testcases/mdummy|echo_sb|values_only_as|my_value|let|foo|bar|2|hello|world|... [1=hello][2=world][foo=bar][my_value=true] → true
[1=hello][2=world][foo=bar][my_value=sorry, not today] → sorry, not today
...|renaming_by_invoking|params/testcases/mdummy|echo_sb|blindly|let|foo|bar|2|hello|world|... [1=hello][2=world][foo=bar] → sorry, not today
mapping_by_magic
Modifier and arguments Result
...|mapping_by_magic|padleft|2|15|/|... it is true → ///////////true
on the window → sorry, not today
...|mapping_by_magic|plural|names_and_values|1|They are many|... it is true → They are many
on the window → They are many
...|mapping_by_magic|padleft|values_and_names|1|40|... it is true → true
on the window → sorry, not today
...|mapping_by_magic|#ifeq|names_only|3|1|It's January!|It's something else|... it is true → It's something else
on the window → It's something else
...|mapping_by_magic|#switch|names_and_values_as|#default|1|let|January|I|let|February|II|let|March|III|let|April|IV|... it is true → it is true
on the window → on the window
...|mapping_by_magic|#time|names_only_as|2|let|1|curry|2|It's December!|It's something else|... it is true → It's something else
on the window → It's something else
...|mapping_by_magic|#time|values_only_as|2|let|1|m/Y|... it is true → Error: Invalid time.
on the window → Error: Invalid time.
...|mapping_by_magic|#time|blindly|2|U|now|... it is true → 1751544383
on the window → 1751544383
renaming_by_magic
Modifier and arguments Result
...|renaming_by_magic|padleft|2|15|/|... /////it is true → true
//on the window → sorry, not today
...|renaming_by_magic|plural|names_and_values|1|They are many|... They are many → sorry, not today
...|renaming_by_magic|padleft|values_and_names|1|40|... true → true
sorry, not today → sorry, not today
...|renaming_by_magic|#ifeq|values_only|3|January|It's January!|It's something else|... It's something else → sorry, not today
...|renaming_by_magic|#switch|names_and_values_as|#default|1|let|January|I|let|February|II|let|March|III|let|April|IV|... it is true → true
on the window → sorry, not today
...|renaming_by_magic|#time|names_only_as|2|let|1|curry|2|It's December!|It's something else|... It's something else → sorry, not today
...|renaming_by_magic|#time|values_only_as|2|let|1|m/Y|... Error: Invalid time. → sorry, not today
...|renaming_by_magic|#time|blindly|2|U|now|... 1751544383 → sorry, not today


information Note: An identical subtemplate that uses Module:Params/sandbox instead of Module:Params is available at {{./tmaps sandbox}}.

Helper subtemplate {{./tcompare separated entries}}

The {{./tcompare separated entries}} subtemplate compares the behaviours of Module:Params with that of Module:Separated entries. For instance,

{{ module:params/testcases/tcompare separated entries | one | two | three | foo  | bar | Jupiter | hello = world }}

generates

Without a last separator:

{{#invoke:separated entries|main|separator=+}}

one+two+three+foo+bar+Jupiter

{{#invoke:params|sequential|squeezing|trimming_values|setting|i|+|list_values}}

one+two+three+foo+bar+Jupiter

With a last separator (::):

{{#invoke:params|sequential|squeezing|trimming_values|setting|i/l|+|::|list_values}}

one+two+three+foo+bar::Jupiter

{{#invoke:separated entries|main|separator=+|conjunction=::}}

one+two+three+foo+bar::Jupiter

With a last separator (::) and cutting the first three parameters:

{{#invoke:params|sequential|cutting|3|0|squeezing|trimming_values|setting|i/l|+|::|list_values}}

foo+bar::Jupiter

{{#invoke:separated entries|main|separator=+|conjunction=::|start=4}}

foo+bar::Jupiter

Testing individual functions

Testing the list function

Helper subtemplate {{./techo}}

The {{./techo}} subtemplate calls the {{#invoke:params|list}} function to echo the code it was called with.

Example:

Markup Renders as
{{module:params/testcases/techo|hello|world|foo=bar}}

{{Module:Params/testcases/techo|1=hello|2=world|foo=bar}}

Dummies

See also