!! Version 2 # Force the test runner to ensure the extension is loaded (we only test for the existence of "af_print", and assume the # other parser functions are available if it exists). !! functionhooks af_print !! endfunctionhooks # This file tests the examples given in the extension's documentation !! article Template:EchoList !! text {{{1}}}{{{2}}} !! endarticle !! article Template:PushIfArray !! text {{#af_if: {{#af_isarray: {{{1}}} }} | {{#af_push: {{{1}}} | {{{2}}} }} }} !! endarticle !! article Template:EchoObject !! text {{{foo}}}{{{boo}}} !! endarticle !! test Create an opaque representation of a boolean !! wikitext {{#af_bool: yes }}, {{#af_bool: no }}, {{#af_bool: true }} !! html

boolean__^__1, boolean__^__0, boolean__^__1

!! end !! test Create an array containing a boolean !! wikitext {{#af_print: {{#af_list: {{#af_bool: yes}} }} }} !! html !! end !! test Count the number of items in a one-dimensional list !! wikitext {{#af_print: {{#af_count: {{#af_list: a | b | c }} }} }} !! html

3

!! end !! test Count the number of items in a multi-dimensional list !! wikitext {{#af_print: {{#af_count: {{#af_list: {{#af_list: a | b }} | {{#af_list: c | d }} }} }} }} !! html

2

!! end !! test Recursively count the number of items in a multi-dimensional list !! wikitext {{#af_print: {{#af_count: {{#af_list: {{#af_list: a | b }} | {{#af_list: c | d }} }} | recursive=true }} }} !! html

6

!! end !! test Check if a key exists !! wikitext {{#af_print: {{#af_exists: {{#af_object: hello=world }} | hello }} }} !! html

true

!! end !! test Check if an index exists !! wikitext {{#af_print: {{#af_exists: {{#af_list: a | b | c }} | 2 }} }} !! html

true

!! end !! test Check if a nested key exists !! wikitext {{#af_print: {{#af_exists: {{#af_get: {{#af_list: a | {{#af_list: b | c }} }} | 1 }} | 2 }} }} !! html

false

!! end !! test Create an opaque representation of a float !! wikitext {{#af_float: 1.298 }}, {{#af_float: 0 }} !! html

float__^__1.298, float__^__0

!! end !! test Create an array containing a float !! wikitext {{#af_print: {{#af_list: {{#af_float: 1.298 }} }} }} !! html !! end !! test Iterate over a list !! wikitext {{#af_foreach: {{#af_list: John | Steve | Harry }} | | name | Hello, {{{name}}}!
}} !! html

Hello, John!
Hello, Steve!
Hello, Harry!

!! end !! test Iterate over an object !! wikitext {{#af_foreach: {{#af_object: Hello=John | Hi=Steve | Welcome=Harry }} | greeting | name | {{{greeting}}}, {{{name}}}!
}} !! html

Hello, John!
Hi, Steve!
Welcome, Harry!

!! end !! test Get a top-level element !! wikitext {{#af_get: {{#af_list: a | b | c }} | 1 }} !! html

b

!! end !! test Get a subarray !! wikitext {{#af_print: {{#af_get: {{#af_list: a | {{#af_list: b | c }} }} | 1 }} }} !! html !! end !! test Get a nested element !! wikitext {{#af_get: {{#af_list: a | {{#af_object: hello=world }} }} | 1 | hello }} !! html

world

!! end !! test Check if a value is an array !! wikitext {{#af_if: {{#af_isarray: not an array }} | A beautiful array! | Not an array! }} !! html

Not an array!

!! end !! test Conditionally pushing to an array !! wikitext {{#af_print: {{PushIfArray| {{#af_list: a | b | c }} | d }} }} {{#af_print: {{PushIfArray| foobar | d }} }} !! html

!! end !! test Create an opaque representation of an integer !! wikitext {{#af_int: 42 }}, {{#af_int: -12 }} !! html

integer__^__42, integer__^__-12

!! end !! test Create an array containing an integer !! wikitext {{#af_print: {{#af_list: {{#af_int: -129}} }} }} !! html !! end !! test Check if an array is an array !! wikitext {{#af_print: {{#af_isarray: {{#af_list: a | b | c }} }} }} !! html

true

!! end !! test Check if a string is an array !! wikitext {{#af_print: {{#af_isarray: Hello, World! }} }} !! html

false

!! end !! test Join a one-dimensional array !! wikitext {{#af_join: {{#af_list: a | b | c }} }} !! html

abc

!! end !! test Join a one-dimensional array using a separator !! wikitext {{#af_join: {{#af_list: a | b | c }} | \s-\s }} !! html

a - b - c

!! end !! test Join a multi-dimensional array using a separator !! wikitext {{#af_join: {{#af_list: a | b | {{#af_list: c | d }} }} | \s-\s }} !! html

a - b - c - d

!! end !! test Sort based on age !! wikitext {{#af_print: {{#af_keysort: {{#af_list: {{#af_object: name=John | age=56 }} | {{#af_object: name=Harry | age=12 }} | {{#af_object: name=Bob | age=24 }} }} | age }} }} !! html !! end !! test Sort based on age, in descending order !! wikitext {{#af_print: {{#af_keysort: {{#af_list: {{#af_object: name=John | age=56 }} | {{#af_object: name=Harry | age=12 }} | {{#af_object: name=Bob | age=24 }} }} | age | descending=true }} }} !! html !! end !! test Create a simple one-dimensional list !! wikitext {{#af_print: {{#af_list: a | b | c }} }} !! html !! end !! test Create a multi-dimensional list !! wikitext {{#af_print: {{#af_list: {{#af_list: a | b }} | {{#af_list: c | d }} }} }} !! html !! end !! test Create a list of objects !! wikitext {{#af_print: {{#af_list: {{#af_object: name=Harry | age=22 }} | {{#af_object: name=Bobby | age=29 }} }} }} !! html !! end !! test Appending a string to each element !! wikitext {{#af_print: {{#af_map: {{#af_list: a | b | c }} | v | {{{v}}}-appended }} }} !! html !! end !! test Altering list elements !! wikitext {{#af_print: {{#af_map: {{#af_list: {{#af_list: a }} | {{#af_list: b }} }} | v | {{#af_push: {{{v}}} | c }} }} }} !! html !! end !! test Create a simple one-dimensional object !! wikitext {{#af_print: {{#af_object: a=b | b=c | c=d }} }} !! html !! end !! test Create a multi-dimensional object !! wikitext {{#af_print: {{#af_object: head={{#af_object: title=MediaWiki | meta={{#af_list: {{#af_object: charset=UTF-8 }} }} }} }} }} !! html !! end !! test Print a boolean !! wikitext {{#af_print: {{#af_bool: yes }} }} !! html

true

!! end !! test Print a list !! wikitext {{#af_print: {{#af_list: a | b | c }} }} !! html !! end !! test Push a value !! wikitext {{#af_print: {{#af_push: {{#af_list: a | b }} | c }} }} !! html !! end !! test Replace an existing value !! wikitext {{#af_print: {{#af_set: d | {{#af_list: a | b | c }} | 2 }} }} !! html !! end !! test Create a new index !! wikitext {{#af_print: {{#af_set: far | {{#af_object: foo=bar }} | boo }} }} !! html !! end !! test Create a new subarray !! wikitext {{#af_print: {{#af_set: far | {{#af_object: foo=bar }} | boo | far }} }} !! html !! end !! test Get the first two elements !! wikitext {{#af_print: {{#af_slice: {{#af_list: a | b | c }} | 0 | 2 }} }} !! html !! end !! test Get the last element !! wikitext {{#af_print: {{#af_slice: {{#af_list: a | b | c }} | -1 }} }} !! html !! end !! test Sort a list in ascending order !! wikitext {{#af_print: {{#af_sort: {{#af_list: b | c | a }} }} }} !! html !! end !! test Sort a list in descending order !! wikitext {{#af_print: {{#af_sort: {{#af_list: b | c | a }} | descending=true }} }} !! html !! end !! test Invoking a template with a list !! wikitext {{#af_print: {{#af_template: EchoList | {{#af_list: a | b }} }} }} !! html

ab

!! end !! test Invoking a template with an object !! wikitext {{#af_print: {{#af_template: EchoObject | {{#af_object: foo=bar | boo=far }} }} }} !! html

barfar

!! end !! test Remove duplicates from an array !! wikitext {{#af_print: {{#af_unique: {{#af_list: a | a | b | c | b }} }} }} !! html !! end !! test Remove a top-level index !! wikitext {{#af_print: {{#af_unset: {{#af_list: a | b | c }} | 2 }} }} !! html !! end !! test Remove a top-level index, keys not reset !! wikitext {{#af_print: {{#af_unset: {{#af_list: a | b | c }} | 1 }} }} !! html !! end !! test Remove a nested index !! wikitext {{#af_print: {{#af_unset: {{#af_object: foo={{#af_object: bar=quz | far=buz }} }} | foo | bar }} }} !! html !! end !! test Search for a value in an array !! wikitext {{#af_print: {{#af_search: {{#af_list: a | b | c }} | b }} }} !! html

1

!! end !! test Show a value !! wikitext {{#af_show: Hello World! }} !! html

Hello World!

!! end