User:Xxmarijnw/Extension:MWUnit/Assertions

This appendix lists the various assertion parser functions that are available.

Global assertions edit

#assert_equals edit

{{#assert_equals: string $expected | string $actual [ | string $message ] }}

Reports an error identified by $message if and only if the two variables, $expected and $actual are not identical to each other.

{{#assert_equals: 1 | 1 }} <!-- $message may be omitted -->
{{#assert_equals: {{Template}} | foo | Template is not 'foo' }}

#assert_equals_ignore_case edit

{{#assert_equals_ignore_case: string $expected | string $actual [ | string $message ] }}

Reports an error identified by $message if and only if the two variables, $expected and $actual are not identical to each other. Differences in casing are ignored in the comparison.

{{#assert_equals_ignore_case: 1 | 1 }} <!-- $message may be omitted -->
{{#assert_equals_ignore_case: {{Template}} | Foo | Template is not 'foo' }}

#assert_error edit

{{#assert_error: string $payload [ | string $message ] }}

Reports an error identified by $message if and only if $payload does not contain at least one div, strong, span or p tag with the attribute class="error". Tags with this attribute are usually returned by parser functions.

{{#assert_error: {{#expr: foo + bar }}  }} <!-- $message may be omitted -->
{{#assert_error: {{#expr: foo + 10 }} | The expression is invalid }}

#assert_greater_than edit

{{#assert_greater_than: float $left | float $right | [ | string $message ] }}

Reports an error identified by $message if and only if $left is not greater than $right.

{{#assert_greater_than: 10 | 5  }} <!-- $message may be omitted -->
{{#assert_greater_than: {{Template}} | 5 | Template is not greater than '5' }}

#assert_greater_than_or_equal edit

{{#assert_greater_than_or_equal: float $left | float $right | [ | string $message ] }}

Reports an error identified by $message if and only if $left is not greater than or equal to $right.

{{#assert_greater_than_or_equal: 10 | 10  }} <!-- $message may be omitted -->
{{#assert_greater_than_or_equal: {{Template}} | 5 | Template is not greater than or equal to '5' }}

#assert_has_length edit

{{#assert_has_length: string $haystack | integer $size [ | string $message ] }}

Reports an error identified by $message if and only if $haystack is not exactly $size characters in size.

{{#assert_has_length: foobar | 6  }} <!-- $message may be omitted -->
{{#assert_has_length: 10 | 2 | '10' is not 2 characters long }}

#assert_empty edit

{{#assert_empty: string $haystack [ | string $message ] }}

Reports an error identified by $message if and only if $haystack is not empty.

{{#assert_empty: }} <!-- $message may be omitted -->
{{#assert_empty: {{Template}} | Template is not empty }} <!-- Templates are expanded before the assertion -->

#assert_is_integer edit

{{#assert_is_integer: mixed $haystack [ | string $message ] }}

Reports an error identified by $message if and only if $haystack is not an integer. A value is only considered an integer if it only consists of numeric characters (0-9).

{{#assert_is_integer: 12 }} <!-- $message may be omitted -->
{{#assert_is_integer: {{Template}} | Template is not an integer }}

#assert_is_numeric edit

{{#assert_is_numeric: mixed $haystack [ | string $message ] }}

Reports an error identified by $message if and only if $haystack is not numeric. You can read more about which values are considered numeric on the PHP website.

{{#assert_is_numeric: 12.2867 }} <!-- $message may be omitted -->
{{#assert_is_numeric: {{Template}} | Template is not numeric }}

#assert_less_than edit

{{#assert_less_than: float $left | float $right | [ | string $message ] }}

Reports an error identified by $message if and only if $left is not less than $right.

{{#assert_less_than: 5 | 10  }} <!-- $message may be omitted -->
{{#assert_less_than: {{Template}} | 5 | Template is not less than '5' }}

#assert_less_than_or_equal edit

{{#assert_less_than_or_equal: float $left | float $right | [ | string $message ] }}

Reports an error identified by $message if and only if $left is not less than or equal to $right.

{{#assert_less_than_or_equal: 5| 10  }} <!-- $message may be omitted -->
{{#assert_less_than_or_equal: {{Template}} | 5 | Template is not less than or equal to '5' }}

#assert_no_error edit

{{#assert_error: string $payload [ | string $message ] }}

Reports an error identified by $message if and only if $payload contains at least one div, strong, span or p tag with the attribute class="error". Tags with this element are usually returned by parser functions.

{{#assert_no_error: {{#expr: 5 + 5 }}  }} <!-- $message may be omitted -->
{{#assert_no_error: {{#expr: 10 + 10 }} | The expression is not invalid }}

#assert_not_empty edit

{{#assert_empty: string $haystack [ | string $message ] }}

Reports an error identified by $message if and only if $haystack is empty.

{{#assert_not_empty: }} <!-- $message may be omitted -->
{{#assert_not_empty: {{Template}} | Template is empty }}

#assert_page_exists edit

{{#assert_empty: string $page_name [ | string $message ] }}

Reports an error identified by $message if and only if the page specified by $page_name does not exist. $page_name must include the namespace if the page is not located in the main namespace.

{{#assert_page_exists: Main Page }} <!-- $message may be omitted -->
{{#assert_page_exists: Template:Foobar | The template 'foobar' does not exist }}

#assert_string_contains edit

{{#assert_string_contains: string $needle | string $haystack [ | string $message ] }}

Reports an error identified by $message if and only if $needle is not contained within $haystack.

{{#assert_string_contains: Foo | Foobar }} <!-- $message may be omitted -->
{{#assert_string_contains: Boo | FooBoobar | `Boo` is not contained in `FooBoobar` }}

#assert_string_contains_ignore_case edit

{{#assert_string_contains_ignore_case: string $needle | string $haystack [ | string $message ] }}

Reports an error identified by $message if and only if $needle is not contained within $haystack. Differences in casing are ignored in the comparison.

{{#assert_string_contains_ignore_case: Foo | foobar }} <!-- $message may be omitted -->
{{#assert_string_contains_ignore_case: boo | FooBoobar | `boo` is not contained in `fooboobar` }}

#assert_string_ends_with edit

{{#assert_string_ends_with: string $needle | string $haystack [ | string $message ] }}

Reports an error identified by $message if and only if $needle is not at the end of $haystack.

{{#assert_string_ends_with: bar | foobar }} <!-- $message may be omitted -->
{{#assert_string_ends_with: bar | foobar | `foobar` does not end in `bar` }}

#assert_string_starts_with edit

{{#assert_string_starts_with: string $needle | string $haystack [ | string $message ] }}

Reports an error identified by $message if and only if $needle is not at the start of $haystack.

{{#assert_string_starts_with: foo | foobar }} <!-- $message may be omitted -->
{{#assert_string_starts_with: foo | foobar | `foobar` does not start with `foo` }}

#assert_that edit

{{#assert_that: string $proposition [ | string $message ] }}

Reports an error identified by $message if and only if $proposition is not one of the following values:

  • true
  • yes
  • on
  • 1

This assertion can be useful for asserting more complex propositions.

{{#assert_that: {{{1|true}}} }} <!-- $message may be omitted -->
{{#assert_that: {{#if: {{{1|}}} ||yes }} | `1` is empty }}

Semantic MediaWiki specific assertions edit

These assertions require Semantic MediaWiki to be installed.

#assert_has_property edit

{{#assert_has_property: string $page | string $property [ | string $message ] }}

Reports an error identified by $message if and only if the page given by $page does not have the property given by $property

{{#assert_has_property: Berlin | Located in }} <!-- $message may be omitted -->
{{#assert_has_property: Berlin | Located in | `Berlin` does not have the property `Located in` }}

#assert_property_has_value edit

{{#assert_property_has_value: string $page | string $property | string $expected [ | string $message ] }}

Reports an error identified by $message if and only if the property given by $property on the page given by $page does not have the value given by $expected.

{{#assert_property_has_value: Berlin | Located in | Germany }} <!-- $message may be omitted -->
{{#assert_property_has_value: Berlin | Located in | Germany | `Berlin` is not located in `Germany` }}

Expressions specific assertions edit

These assertions require Expressions to be installed.

#assert_expression edit

{{#assert_expression: string $expression [ | string $message ] }}

Reports an error identified by $message if and only if the expression given by $expression evaluates to false.

{{#assert_expression: 1 > 0 }} <!-- $message may be omitted -->
{{#assert_expression: {{Test}} > 0 | `Test` did not return a value greater than 0 }} 

See also edit