diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-08 21:19:06 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-08 21:19:06 +0200 |
commit | c77a5bebc9ae8df17b851b6256cb42fa5d763dba (patch) | |
tree | 77c7dac828ad7ef8bad17972f2a256ac632fbea3 /tests/01_arithmetic/04_inc_dec | |
parent | c735882bb492ff81f98773186652dbe878ff3d60 (diff) |
tests: add further arithmetic and syntax test cases
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/01_arithmetic/04_inc_dec')
-rw-r--r-- | tests/01_arithmetic/04_inc_dec | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/01_arithmetic/04_inc_dec b/tests/01_arithmetic/04_inc_dec new file mode 100644 index 0000000..6647ced --- /dev/null +++ b/tests/01_arithmetic/04_inc_dec @@ -0,0 +1,50 @@ +Utpl implements C-style pre- and postfix increment and decrement operators. + +Pre-increment or -decrement operations first mutate the value and then return +the resulting value while post-increment or -decrement operations first return +the initial value and then mutate the operand. + +Since the decrement and increment operators mutate their operand, they +may only be applied to variables, not constant literal expressions. + +If an undefined variable is incremented or decremented, its initial value +is assumed to be "0". + +If a non-numeric value is incremented or decremented, it is converted to a +number first. If the value is not convertible, the result of the increment +or decrement operation is NaN. + +-- Expect stdout -- +Incrementing a not existing variable assumes "0" as initial value: + + - Postfix increment result: null, value after: 1 + - Prefix increment result: 1, value after: 1 + - Postfix decrement result: null, value after: -1 + - Prefix decrement result: -1, value after: -1 + +Incrementing a non-numeric value will convert it to a number: + +124 +3.5 +2 +NaN + +-- End -- + +-- Testcase -- +Incrementing a not existing variable assumes "0" as initial value: + + - Postfix increment result: {{ "" + a++ }}, value after: {{ a }} + - Prefix increment result: {{ "" + ++b }}, value after: {{ b }} + - Postfix decrement result: {{ "" + c-- }}, value after: {{ c }} + - Prefix decrement result: {{ "" + --d }}, value after: {{ d }} + +Incrementing a non-numeric value will convert it to a number: + +{% + n = "123"; n++; print(n, "\n"); + n = "4.5"; n--; print(n, "\n"); + n = true; n++; print(n, "\n"); + n = { some: "object" }; n--; print(n, "\n"); +%} +-- End -- |