diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/00_syntax/05_block_nesting | 7 | ||||
-rw-r--r-- | tests/00_syntax/13_object_literals | 1 | ||||
-rw-r--r-- | tests/00_syntax/16_for_loop | 23 | ||||
-rw-r--r-- | tests/00_syntax/17_while_loop | 2 | ||||
-rw-r--r-- | tests/00_syntax/19_arrow_functions | 6 | ||||
-rw-r--r-- | tests/00_syntax/21_regex_literals | 2 | ||||
-rw-r--r-- | tests/01_arithmetic/04_inc_dec | 4 | ||||
-rw-r--r-- | tests/02_runtime/00_scoping | 14 | ||||
-rw-r--r-- | tests/02_runtime/02_this | 7 | ||||
-rw-r--r-- | tests/02_runtime/03_try_catch | 107 | ||||
-rw-r--r-- | tests/02_runtime/04_switch_case | 48 | ||||
-rw-r--r-- | tests/02_runtime/06_recursion | 6 |
12 files changed, 187 insertions, 40 deletions
diff --git a/tests/00_syntax/05_block_nesting b/tests/00_syntax/05_block_nesting index 7b74adb..fcfd7da 100644 --- a/tests/00_syntax/05_block_nesting +++ b/tests/00_syntax/05_block_nesting @@ -8,6 +8,13 @@ In line 2, byte 61: Near here --------------------------------------------------^ +Syntax error: Template blocks may not be nested +In line 3, byte 61: + + `We may not nest expression blocks into statement blocks: {% {{ 1 + 2 }} %}.` + Near here --------------------------------------------------^ + + -- End -- -- Testcase -- diff --git a/tests/00_syntax/13_object_literals b/tests/00_syntax/13_object_literals index 60c9f32..67dbd6c 100644 --- a/tests/00_syntax/13_object_literals +++ b/tests/00_syntax/13_object_literals @@ -48,6 +48,7 @@ either JSON or JavaScript notation. print(another_obj, "\n"); print(third_obj, "\n"); print(nested_obj, "\n"); +%} -- End -- diff --git a/tests/00_syntax/16_for_loop b/tests/00_syntax/16_for_loop index 33d1d97..67edc21 100644 --- a/tests/00_syntax/16_for_loop +++ b/tests/00_syntax/16_for_loop @@ -218,11 +218,12 @@ Ensure that for-in loop expressions with more than two variables are rejected. -- Expect stderr -- -Syntax error: Invalid for-in expression -In line 2, byte 14: +Syntax error: Unexpected token +Expecting ';' +In line 2, byte 24: ` for (let x, y, z in {})` - Near here ------^ + Near here ----------------^ -- End -- @@ -238,11 +239,12 @@ In line 2, byte 14: Ensure that assignments in for-in loop expressions are rejected. -- Expect stderr -- -Syntax error: Invalid for-in expression -In line 2, byte 13: +Syntax error: Unexpected token +Expecting ';' +In line 2, byte 25: ` for (let x = 1, y in {})` - Near here -----^ + Near here -----------------^ -- End -- @@ -259,7 +261,7 @@ Ensure that too short for-in loop expressions are rejected (1/2). -- Expect stderr -- Syntax error: Unexpected token -Expecting ',' or 'in' +Expecting ';' In line 2, byte 12: ` for (let x)` @@ -279,11 +281,12 @@ In line 2, byte 12: Ensure that too short for-in loop expressions are rejected (2/2). -- Expect stderr -- -Syntax error: Invalid for-in expression -In line 2, byte 14: +Syntax error: Unexpected token +Expecting ';' +In line 2, byte 15: ` for (let x, y)` - Near here ------^ + Near here -------^ -- End -- diff --git a/tests/00_syntax/17_while_loop b/tests/00_syntax/17_while_loop index 4dfaccc..1e68d6b 100644 --- a/tests/00_syntax/17_while_loop +++ b/tests/00_syntax/17_while_loop @@ -32,7 +32,7 @@ Iteration 8 Iteration 9 A counting while-loop using the alternative syntax: -Iteration null +Iteration 0 Iteration 1 Iteration 2 Iteration 3 diff --git a/tests/00_syntax/19_arrow_functions b/tests/00_syntax/19_arrow_functions index 4847d8a..102c527 100644 --- a/tests/00_syntax/19_arrow_functions +++ b/tests/00_syntax/19_arrow_functions @@ -108,11 +108,11 @@ subsequent testcase asserts that case. -- Expect stderr -- Syntax error: Unexpected token -Expecting Label -In line 2, byte 5: +Expecting ';' +In line 2, byte 10: ` (a + 1) => { print("test\n") }` - ^-- Near here + Near here --^ -- End -- diff --git a/tests/00_syntax/21_regex_literals b/tests/00_syntax/21_regex_literals index 4aef33f..3af53bb 100644 --- a/tests/00_syntax/21_regex_literals +++ b/tests/00_syntax/21_regex_literals @@ -35,7 +35,7 @@ Testing invalid flag characters. -- Expect stderr -- Syntax error: Unexpected token -Expecting ',' or ';' +Expecting ';' In line 2, byte 8: ` /test/x` diff --git a/tests/01_arithmetic/04_inc_dec b/tests/01_arithmetic/04_inc_dec index 5a048fe..ae50ceb 100644 --- a/tests/01_arithmetic/04_inc_dec +++ b/tests/01_arithmetic/04_inc_dec @@ -17,9 +17,9 @@ or decrement operation is NaN. -- Expect stdout -- Incrementing a not existing variable assumes "0" as initial value: - - Postfix increment result: null, value after: 1 + - Postfix increment result: 0, value after: 1 - Prefix increment result: 1, value after: 1 - - Postfix decrement result: null, value after: -1 + - Postfix decrement result: 0, value after: -1 - Prefix decrement result: -1, value after: -1 Incrementing a non-numeric value will convert it to a number: diff --git a/tests/02_runtime/00_scoping b/tests/02_runtime/00_scoping index 2bca2ab..5fadf43 100644 --- a/tests/02_runtime/00_scoping +++ b/tests/02_runtime/00_scoping @@ -12,7 +12,7 @@ c_global=true c_local=false -When seting a nonlet variable, it is set in the nearest parent +When seting a nonlocal variable, it is set in the nearest parent scope containing the variable or in the root scope if the variable was not found. @@ -25,13 +25,13 @@ Variables implicitly declared by for-in or counting for loops follow the same scoping rules. inner2 f_a=3 -inner2 f_b=3 +inner2 f_b= inner2 f_c=3 -inner2 f_d=3 +inner2 f_d= inner2 f_e=3 inner f_a=3 -inner f_b=3 +inner f_b= inner f_c=3 inner f_d= inner f_e=3 @@ -73,7 +73,7 @@ c_global={{ !!c_global }} c_local={{ !!c_local }} -When seting a nonlet variable, it is set in the nearest parent +When seting a nonlocal variable, it is set in the nearest parent scope containing the variable or in the root scope if the variable was not found. @@ -110,7 +110,7 @@ scoping rules. {% function scope3() { - // f_a is not declared let and be set i nthe root scope + // f_a is not declared local and be set in the root scope for (f_a = 1; f_a < 3; f_a++) ; @@ -120,7 +120,7 @@ scoping rules. let f_c; function scope4() { - // f_c is not declared let but declared in the parent scope, it + // f_c is not declared local but declared in the parent scope, it // will be set there for (f_c in [1, 2, 3]) ; diff --git a/tests/02_runtime/02_this b/tests/02_runtime/02_this index e629853..d8e85d2 100644 --- a/tests/02_runtime/02_this +++ b/tests/02_runtime/02_this @@ -13,7 +13,8 @@ true } // When invoked, "this" will point to the object containing the function - let o = { + let o; + o = { test: function() { return (this === o); } @@ -34,7 +35,8 @@ true -- Testcase -- {% - let o = { + let o; + o = { test: function() { return (this === o); } @@ -45,3 +47,4 @@ true print(o.test(dummy.foo, dummy.bar), "\n"); print(o.test(dummy.foo, o.test(dummy.foo, dummy.bar)), "\n"); %} +-- End -- diff --git a/tests/02_runtime/03_try_catch b/tests/02_runtime/03_try_catch index 518c1f1..751ca1d 100644 --- a/tests/02_runtime/03_try_catch +++ b/tests/02_runtime/03_try_catch @@ -29,3 +29,110 @@ After exceptions. print("After exceptions.\n"); %} -- End -- + + +Ensure that exceptions are propagated through C function calls. + +-- Expect stderr -- +exception +In [anonymous function](), line 3, byte 18: + called from function replace ([C]) + called from anonymous function ([stdin]:4:3) + + ` die("exception");` + Near here -------------^ + + +-- End -- + +-- Testcase -- +{% + replace("test", "t", function(m) { + die("exception"); + }); +%} +-- End -- + + +Ensure that exception can be catched through C function calls. + +-- Expect stdout -- +Caught exception: exception +-- End -- + +-- Testcase -- +{% + try { + replace("test", "t", function(m) { + die("exception"); + }); + } + catch (e) { + print("Caught exception: ", e, "\n"); + } +%} +-- End -- + + +Ensure that exceptions are propagated through user function calls. + +-- Expect stderr -- +exception +In a(), line 3, byte 18: + called from function b ([stdin]:7:5) + called from function c ([stdin]:11:5) + called from anonymous function ([stdin]:14:4) + + ` die("exception");` + Near here -------------^ + + +-- End -- + +-- Testcase -- +{% + function a() { + die("exception"); + } + + function b() { + a(); + } + + function c() { + b(); + } + + c(); +%} +-- End -- + + +Ensure that exceptions can be caught in parent functions. + +-- Expect stdout -- +Caught exception: exception +-- End -- + +-- Testcase -- +{% + function a() { + die("exception"); + } + + function b() { + a(); + } + + function c() { + try { + b(); + } + catch (e) { + print("Caught exception: ", e, "\n"); + } + } + + c(); +%} +-- End -- diff --git a/tests/02_runtime/04_switch_case b/tests/02_runtime/04_switch_case index 0de87dc..4c1fc57 100644 --- a/tests/02_runtime/04_switch_case +++ b/tests/02_runtime/04_switch_case @@ -84,7 +84,26 @@ default -- End -- -4. Ensure that duplicate default cases emit a syntax +4. Ensure that a single default case matches. + +-- Expect stdout -- +default +default +-- End -- + +-- Testcase -- +{% + for (n in [1, 3]) { + switch (n) { + default: + print("default\n"); + } + } +%} +-- End -- + + +5. Ensure that duplicate default cases emit a syntax error during parsing. -- Expect stderr -- @@ -95,6 +114,13 @@ In line 6, byte 3: ^-- Near here +Syntax error: Expecting expression +In line 8, byte 2: + + ` }` + ^-- Near here + + -- End -- -- Testcase -- @@ -110,7 +136,7 @@ In line 6, byte 3: -- End -- -5. Ensure that case values use strict comparison. +6. Ensure that case values use strict comparison. -- Expect stdout -- b @@ -142,7 +168,7 @@ b -- End -- -6. Ensure that case values may be complex expressions. +7. Ensure that case values may be complex expressions. -- Expect stdout -- 2, 3, 1 @@ -159,7 +185,7 @@ b -- End -- -7. Ensure that empty switch statements are accepted by the +8. Ensure that empty switch statements are accepted by the parser and that the test expression is evaluated. -- Expect stdout -- @@ -179,7 +205,7 @@ true -- End -- -8. Ensure that `return` breaks out of switch statements. +9. Ensure that `return` breaks out of switch statements. -- Expect stdout -- one @@ -207,7 +233,7 @@ two -- End -- -9. Ensure that `continue` breaks out of switch statements. +10. Ensure that `continue` breaks out of switch statements. -- Expect stdout -- one @@ -234,7 +260,7 @@ two -- End -- -10. Ensure that exceptions break out of switch statements. +11. Ensure that exceptions break out of switch statements. -- Expect stdout -- one @@ -242,11 +268,11 @@ one -- Expect stderr -- Died -In test(), line 6, byte 7: - called from anonymous function ([stdin]:17:12) +In test(), line 6, byte 8: + called from anonymous function ([stdin]:17:14) ` die();` - Near here -----^ + Near here ------^ -- End -- @@ -273,7 +299,7 @@ In test(), line 6, byte 7: -- End -- -11. Ensure that consecutive cases values are properly handled. +12. Ensure that consecutive cases values are properly handled. -- Expect stdout -- three and four diff --git a/tests/02_runtime/06_recursion b/tests/02_runtime/06_recursion index b222640..470fc3a 100644 --- a/tests/02_runtime/06_recursion +++ b/tests/02_runtime/06_recursion @@ -39,11 +39,11 @@ Testing recursive invocations. -- Expect stderr -- Runtime error: Too much recursion -In test(), line 3, byte 7: - called from anonymous function ([stdin]:6:6) +In test(), line 3, byte 8: + called from anonymous function ([stdin]:6:7) ` test();` - Near here --^ + Near here ---^ -- End -- |