diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/custom/00_syntax/24_null_coalesce | 50 | ||||
-rw-r--r-- | tests/custom/00_syntax/25_and_or_assignment | 55 | ||||
-rw-r--r-- | tests/custom/00_syntax/26_exponentiation | 56 |
3 files changed, 161 insertions, 0 deletions
diff --git a/tests/custom/00_syntax/24_null_coalesce b/tests/custom/00_syntax/24_null_coalesce new file mode 100644 index 0000000..26b89f1 --- /dev/null +++ b/tests/custom/00_syntax/24_null_coalesce @@ -0,0 +1,50 @@ +Null coalescing operators return the right hand side of an expression of +the left hand side is null. + + +1. The `??` operator returns the right hand side of the expression if the +left hand side evaluates to `null`. + +-- Expect stdout -- +is null +false +0 +-- End -- + +-- Testcase -- +{% + x = null; + y = false; + z = 0; + + print(x ?? "is null", "\n"); + print(y ?? "is null", "\n"); + print(z ?? "is null", "\n"); +%} +-- End -- + + +2. The `??=` nullish assignment operator sets the left hand side variable +or value to the right hand side expression if the existing value is null. + +-- Expect stdout -- +is null +false +0 +-- End -- + +-- Testcase -- +{% + x = null; + y = false; + z = 0; + + x ??= "is null"; + y ??= "is null"; + z ??= "is null"; + + print(x, "\n"); + print(y, "\n"); + print(z, "\n"); +%} +-- End -- diff --git a/tests/custom/00_syntax/25_and_or_assignment b/tests/custom/00_syntax/25_and_or_assignment new file mode 100644 index 0000000..4dbc5f3 --- /dev/null +++ b/tests/custom/00_syntax/25_and_or_assignment @@ -0,0 +1,55 @@ +The logical AND and logical OR assignment operators set the left hand side +variable or value to the right hand side expression result depending on +whether the lhs value is truish. + + +1. The `&&=` operator overwrites the lhs variable or field with the rhs +expression result if the lhs is truish. + +-- Expect stdout -- +[ + null, + false, + "is truish" +] +-- End -- + +-- Testcase -- +{% + x = null; + y = false; + z = true; + + x &&= "is truish"; + y &&= "is truish"; + z &&= "is truish"; + + printf("%.J\n", [ x, y, z ]); +%} +-- End -- + + +2. The `||=` operator overwrites the lhs variable or field with the rhs +expression result if the lhs is falsy. + +-- Expect stdout -- +[ + "is falsy", + "is falsy", + true +] +-- End -- + +-- Testcase -- +{% + x = null; + y = false; + z = true; + + x ||= "is falsy"; + y ||= "is falsy"; + z ||= "is falsy"; + + printf("%.J\n", [ x, y, z ]); +%} +-- End -- diff --git a/tests/custom/00_syntax/26_exponentiation b/tests/custom/00_syntax/26_exponentiation new file mode 100644 index 0000000..1aab257 --- /dev/null +++ b/tests/custom/00_syntax/26_exponentiation @@ -0,0 +1,56 @@ +The exponentiation and exponentiation assignment operands allow raising +the base operand value to the given power. + + +1. The `**` operator returns the result of raising the first operand to +the power of the second operand. + +-- Expect stdout -- +[ + 1, + 4, + 9223372036854775808, + -9223372036854775808, + -0.25, + 2.75568 +] +-- End -- + +-- Testcase -- +{% + printf("%.J\n", [ + 2 ** 0, + 2 ** 2, + 2 ** 63, + -2 ** 63, + -2 ** -2, + 1.5 ** 2.5 + ]); +%} +-- End -- + + +2. The `**=` operator raises the lhs variable or field value to the +power value in the rhs expression. + +-- Expect stdout -- +[ + 4, + -0.25, + 2.75568 +] +-- End -- + +-- Testcase -- +{% + x = 2; + y = -2; + z = 1.5; + + x **= 2; + y **= -2; + z **= 2.5; + + printf("%.J\n", [ x, y, z ]); +%} +-- End -- |