summaryrefslogtreecommitdiffhomepage
path: root/tests/00_syntax/13_object_literals
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-02-17 18:28:01 +0100
committerGitHub <noreply@github.com>2021-02-17 18:28:01 +0100
commit679270fd3afa93cca84ab31b5041922037fec0c5 (patch)
treee55752bae52bf7eed38b91c42e990a8b116b6621 /tests/00_syntax/13_object_literals
parent77580a893283f2bde7ab46496bd3a3d7b2fc6784 (diff)
parent14e46b8e225dc329f4e14777960b10abb8a09699 (diff)
Merge pull request #2 from jow-/rewrite
treewide: rewrite ucode interpreter
Diffstat (limited to 'tests/00_syntax/13_object_literals')
-rw-r--r--tests/00_syntax/13_object_literals82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/00_syntax/13_object_literals b/tests/00_syntax/13_object_literals
index 60c9f32..18fbbed 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 --
@@ -90,3 +91,84 @@ of object properties into other objects.
]), "\n");
%}
-- End --
+
+
+ES2015 short hand property notation is supported as well.
+
+-- Expect stdout --
+{ "a": 123, "b": true, "c": "test" }
+-- End --
+
+-- Testcase --
+{%
+ a = 123;
+ b = true;
+ c = "test";
+
+ o = { a, b, c };
+
+ print(o, "\n");
+%}
+-- End --
+
+-- Expect stderr --
+Syntax error: Unexpected token
+Expecting ':'
+In line 2, byte 14:
+
+ ` o = { "foo" };`
+ Near here ------^
+
+
+-- End --
+
+-- Testcase --
+{%
+ o = { "foo" };
+%}
+-- End --
+
+
+ES2015 computed property names are supported.
+
+-- Expect stdout --
+{ "test": true, "hello": false, "ABC": 123 }
+-- End --
+
+-- Testcase --
+{%
+ s = "test";
+ o = {
+ [s]: true,
+ ["he" + "llo"]: false,
+ [uc("abc")]: 123
+ };
+
+ print(o, "\n");
+%}
+-- End --
+
+-- Expect stderr --
+Syntax error: Expecting expression
+In line 2, byte 10:
+
+ ` o1 = { []: true };`
+ Near here --^
+
+
+Syntax error: Unexpected token
+Expecting ']'
+In line 3, byte 14:
+
+ ` o2 = { [true, false]: 123 };`
+ Near here ------^
+
+
+-- End --
+
+-- Testcase --
+{%
+ o1 = { []: true };
+ o2 = { [true, false]: 123 };
+%}
+-- End --