!! 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}} }} }} !! html3
!! 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 }} }} }} }} !! html2
!! 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 }} }} !! html6
!! end !! test Check if a key exists !! wikitext {{#af_print: {{#af_exists: {{#af_object: hello=world }} | hello }} }} !! htmltrue
!! end !! test Check if an index exists !! wikitext {{#af_print: {{#af_exists: {{#af_list: a | b | c }} | 2 }} }} !! htmltrue
!! end !! test Check if a nested key exists !! wikitext {{#af_print: {{#af_exists: {{#af_get: {{#af_list: a | {{#af_list: b | c }} }} | 1 }} | 2 }} }} !! htmlfalse
!! end !! test Create an opaque representation of a float !! wikitext {{#af_float: 1.298 }}, {{#af_float: 0 }} !! htmlfloat__^__1.298, float__^__0
!! end !! test Create an array containing a float !! wikitext {{#af_print: {{#af_list: {{#af_float: 1.298 }} }} }} !! htmlHello, John!
Hello, Steve!
Hello, Harry!
Hello, John!
Hi, Steve!
Welcome, Harry!
b
!! end !! test Get a subarray !! wikitext {{#af_print: {{#af_get: {{#af_list: a | {{#af_list: b | c }} }} | 1 }} }} !! htmlworld
!! end !! test Check if a value is an array !! wikitext {{#af_if: {{#af_isarray: not an array }} | A beautiful array! | Not an array! }} !! htmlNot 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}} }} }} !! htmltrue
!! end !! test Check if a string is an array !! wikitext {{#af_print: {{#af_isarray: Hello, World! }} }} !! htmlfalse
!! end !! test Join a one-dimensional array !! wikitext {{#af_join: {{#af_list: a | b | c }} }} !! htmlabc
!! end !! test Join a one-dimensional array using a separator !! wikitext {{#af_join: {{#af_list: a | b | c }} | \s-\s }} !! htmla - 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 }} !! htmla - 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 }} }} !! htmltrue
!! end !! test Print a list !! wikitext {{#af_print: {{#af_list: a | b | c }} }} !! htmlab
!! end !! test Invoking a template with an object !! wikitext {{#af_print: {{#af_template: EchoObject | {{#af_object: foo=bar | boo=far }} }} }} !! htmlbarfar
!! end !! test Remove duplicates from an array !! wikitext {{#af_print: {{#af_unique: {{#af_list: a | a | b | c | b }} }} }} !! html1
!! end !! test Show a value !! wikitext {{#af_show: Hello World! }} !! htmlHello World!
!! end