diff --git a/README.md b/README.md index cbb6852..0490e6e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ Another JavaScript interpreter written on Python 3. To run tests: - pytest -- Tox You can get ANTLR [here](https://www.antlr.org/), other dependencies could be installed with pip: ```bash @@ -26,6 +25,12 @@ antlr4 -Xexact-output-dir -o jasminesnake/lex -package lex -Dlanguage=Python3 -l python -m jasminesnake ``` +# Testing +```bash +# Running with -s is optional +python -m pytest -s +``` + ## Credits ESTree specification: diff --git a/tests/apr30_bug.js b/tests/apr30_bug.js deleted file mode 100644 index 7c23e00..0000000 --- a/tests/apr30_bug.js +++ /dev/null @@ -1,2 +0,0 @@ -// Guess what? It should be parsable, but it's not (git rev 44d7e241) -{let a = 15, b; {1_337.2_28, false, "String"}} \ No newline at end of file diff --git a/tests/bugs/r/unicode_escape.ast b/tests/bugs/r/unicode_escape.ast new file mode 100644 index 0000000..3e1a1a7 --- /dev/null +++ b/tests/bugs/r/unicode_escape.ast @@ -0,0 +1,8 @@ +Program at 1:0 ++-- sourceType: script ++-- body: +| +-- 0: ExpressionStatement at 1:0 +| | +-- expression: SequenceExpression at 1:0 +| | | +-- expressions: +| | | | +-- 0: " while executing client event 1" +| | | | | +-- value: while executing client event 1 diff --git a/tests/bugs/t/unicode_escape.js b/tests/bugs/t/unicode_escape.js new file mode 100644 index 0000000..3861554 --- /dev/null +++ b/tests/bugs/t/unicode_escape.js @@ -0,0 +1,2 @@ +// The code below won't work since the grammar treat Unicode +"\x20\x77hil\x65\x20exe\x63uting c\x6cient e\x76\145\x6et 1"; \ No newline at end of file diff --git a/tests/expressions/r/assignments.ast b/tests/expressions/r/assignments.ast new file mode 100644 index 0000000..9edc3bf --- /dev/null +++ b/tests/expressions/r/assignments.ast @@ -0,0 +1,120 @@ +Program at 1:0 ++-- sourceType: script ++-- body: +| +-- 0: ExpressionStatement at 1:0 +| | +-- expression: SequenceExpression at 1:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 1:0 +| | | | | +-- operator: = +| | | | | +-- left: Identifier at 1:0 +| | | | | | +-- name: a +| | | | | +-- right: Literal at 1:4 +| | | | | | +-- value: 1.0 +| +-- 1: ExpressionStatement at 2:0 +| | +-- expression: SequenceExpression at 2:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 2:0 +| | | | | +-- operator: *= +| | | | | +-- left: Identifier at 2:0 +| | | | | | +-- name: q +| | | | | +-- right: Literal at 2:5 +| | | | | | +-- value: 2.0 +| +-- 2: ExpressionStatement at 3:0 +| | +-- expression: SequenceExpression at 3:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 3:0 +| | | | | +-- operator: /= +| | | | | +-- left: Identifier at 3:0 +| | | | | | +-- name: d +| | | | | +-- right: Literal at 3:5 +| | | | | | +-- value: 2.0 +| +-- 3: ExpressionStatement at 4:0 +| | +-- expression: SequenceExpression at 4:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 4:0 +| | | | | +-- operator: %= +| | | | | +-- left: Identifier at 4:0 +| | | | | | +-- name: w +| | | | | +-- right: Literal at 4:5 +| | | | | | +-- value: 15.0 +| +-- 4: ExpressionStatement at 5:0 +| | +-- expression: SequenceExpression at 5:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 5:0 +| | | | | +-- operator: += +| | | | | +-- left: Identifier at 5:0 +| | | | | | +-- name: b +| | | | | +-- right: Literal at 5:5 +| | | | | | +-- value: 12.0 +| +-- 5: ExpressionStatement at 6:0 +| | +-- expression: SequenceExpression at 6:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 6:0 +| | | | | +-- operator: -= +| | | | | +-- left: Identifier at 6:0 +| | | | | | +-- name: c +| | | | | +-- right: Literal at 6:5 +| | | | | | +-- value: 14.0 +| +-- 6: ExpressionStatement at 7:0 +| | +-- expression: SequenceExpression at 7:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 7:0 +| | | | | +-- operator: <<= +| | | | | +-- left: Identifier at 7:0 +| | | | | | +-- name: a +| | | | | +-- right: Literal at 7:6 +| | | | | | +-- value: 1.0 +| +-- 7: ExpressionStatement at 8:0 +| | +-- expression: SequenceExpression at 8:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 8:0 +| | | | | +-- operator: >>= +| | | | | +-- left: Identifier at 8:0 +| | | | | | +-- name: b +| | | | | +-- right: Literal at 8:6 +| | | | | | +-- value: 2.0 +| +-- 8: ExpressionStatement at 9:0 +| | +-- expression: SequenceExpression at 9:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 9:0 +| | | | | +-- operator: >>>= +| | | | | +-- left: Identifier at 9:0 +| | | | | | +-- name: z +| | | | | +-- right: Literal at 9:7 +| | | | | | +-- value: 2.0 +| +-- 9: ExpressionStatement at 10:0 +| | +-- expression: SequenceExpression at 10:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 10:0 +| | | | | +-- operator: &= +| | | | | +-- left: Identifier at 10:0 +| | | | | | +-- name: v +| | | | | +-- right: Literal at 10:5 +| | | | | | +-- value: 1.0 +| +-- 10: ExpressionStatement at 11:0 +| | +-- expression: SequenceExpression at 11:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 11:0 +| | | | | +-- operator: ^= +| | | | | +-- left: Identifier at 11:0 +| | | | | | +-- name: cc +| | | | | +-- right: Identifier at 11:6 +| | | | | | +-- name: cc +| +-- 11: ExpressionStatement at 12:0 +| | +-- expression: SequenceExpression at 12:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 12:0 +| | | | | +-- operator: |= +| | | | | +-- left: Identifier at 12:0 +| | | | | | +-- name: vv +| | | | | +-- right: Identifier at 12:5 +| | | | | | +-- name: a +| +-- 12: ExpressionStatement at 13:0 +| | +-- expression: SequenceExpression at 13:0 +| | | +-- expressions: +| | | | +-- 0: AssignmentExpression at 13:0 +| | | | | +-- operator: **= +| | | | | +-- left: Identifier at 13:0 +| | | | | | +-- name: x +| | | | | +-- right: Literal at 13:6 +| | | | | | +-- value: 2.0 diff --git a/tests/expressions/r/binary_ops.ast b/tests/expressions/r/binary_ops.ast new file mode 100644 index 0000000..20e4527 --- /dev/null +++ b/tests/expressions/r/binary_ops.ast @@ -0,0 +1,42 @@ +Program at 1:0 ++-- sourceType: script ++-- body: +| +-- 0: ExpressionStatement at 1:0 +| | +-- expression: SequenceExpression at 1:0 +| | | +-- expressions: +| | | | +-- 0: BinaryExpression at 1:0 +| | | | | +-- operator: + +| | | | | +-- left: Literal at 1:0 +| | | | | | +-- value: 2.0 +| | | | | +-- right: BinaryExpression at 1:2 +| | | | | | +-- operator: * +| | | | | | +-- left: Literal at 1:2 +| | | | | | | +-- value: 2.0 +| | | | | | +-- right: Literal at 1:4 +| | | | | | | +-- value: 2.0 +| +-- 1: ExpressionStatement at 2:0 +| | +-- expression: SequenceExpression at 2:0 +| | | +-- expressions: +| | | | +-- 0: BinaryExpression at 2:0 +| | | | | +-- operator: == +| | | | | +-- left: BinaryExpression at 2:0 +| | | | | | +-- operator: + +| | | | | | +-- left: Literal at 2:0 +| | | | | | | +-- value: 2.0 +| | | | | | +-- right: Literal at 2:6 +| | | | | | | +-- value: 2.0 +| | | | | +-- right: Literal at 2:11 +| | | | | | +-- value: 5.0 +| +-- 2: ExpressionStatement at 3:0 +| | +-- expression: SequenceExpression at 3:0 +| | | +-- expressions: +| | | | +-- 0: BinaryExpression at 3:0 +| | | | | +-- operator: !== +| | | | | +-- left: BinaryExpression at 3:0 +| | | | | | +-- operator: / +| | | | | | +-- left: Literal at 3:0 +| | | | | | | +-- value: 1.0 +| | | | | | +-- right: Literal at 3:2 +| | | | | | | +-- value: 0.0 +| | | | | +-- right: Identifier at 3:8 +| | | | | | +-- name: infty diff --git a/tests/expressions/r/empty_expr.ast b/tests/expressions/r/empty_expr.ast new file mode 100644 index 0000000..c050524 --- /dev/null +++ b/tests/expressions/r/empty_expr.ast @@ -0,0 +1,7 @@ +Program at 1:1 ++-- sourceType: script ++-- body: +| +-- 0: EmptyStatement at 1:1 +| +-- 1: EmptyStatement at 2:0 +| +-- 2: EmptyStatement at 2:2 +| +-- 3: EmptyStatement at 3:1 diff --git a/tests/expressions/r/inc_dec.ast b/tests/expressions/r/inc_dec.ast new file mode 100644 index 0000000..7cc56bf --- /dev/null +++ b/tests/expressions/r/inc_dec.ast @@ -0,0 +1,32 @@ +Program at 1:0 ++-- sourceType: script ++-- body: +| +-- 0: ExpressionStatement at 1:0 +| | +-- expression: SequenceExpression at 1:0 +| | | +-- expressions: +| | | | +-- 0: UpdateExpression at 1:0 +| | | | | +-- operator: ++ +| | | | | +-- argument: Identifier at 1:2 +| | | | | | +-- name: a +| | | | | +-- prefix: True +| +-- 1: ExpressionStatement at 1:5 +| | +-- expression: SequenceExpression at 1:5 +| | | +-- expressions: +| | | | +-- 0: UpdateExpression at 1:5 +| | | | | +-- operator: ++ +| | | | | +-- argument: Identifier at 1:5 +| | | | | | +-- name: b +| | | | | +-- prefix: False +| +-- 2: ExpressionStatement at 2:0 +| | +-- expression: SequenceExpression at 2:0 +| | | +-- expressions: +| | | | +-- 0: UpdateExpression at 2:0 +| | | | | +-- operator: -- +| | | | | +-- argument: Identifier at 2:0 +| | | | | | +-- name: a +| | | | | +-- prefix: False +| | | | +-- 1: UpdateExpression at 2:5 +| | | | | +-- operator: -- +| | | | | +-- argument: Identifier at 2:7 +| | | | | | +-- name: b +| | | | | +-- prefix: True diff --git a/tests/expressions/t/assignments.js b/tests/expressions/t/assignments.js new file mode 100644 index 0000000..77d341e --- /dev/null +++ b/tests/expressions/t/assignments.js @@ -0,0 +1,13 @@ +a = 1; +q *= 2; +d /= 2; +w %= 15; +b += 12; +c -= 14; +a <<= 1; +b >>= 2; +z >>>= 2; +v &= 1; +cc ^= cc; +vv|= a; +x **= 2; diff --git a/tests/expressions/t/binary_ops.js b/tests/expressions/t/binary_ops.js new file mode 100644 index 0000000..315829a --- /dev/null +++ b/tests/expressions/t/binary_ops.js @@ -0,0 +1,3 @@ +2+2*2; +2 + 2 == 5; +1/0 !== infty; \ No newline at end of file diff --git a/tests/expressions/t/empty_expr.js b/tests/expressions/t/empty_expr.js new file mode 100644 index 0000000..b40b50c --- /dev/null +++ b/tests/expressions/t/empty_expr.js @@ -0,0 +1,3 @@ + ; +; ; + ; \ No newline at end of file diff --git a/tests/expressions/t/inc_dec.js b/tests/expressions/t/inc_dec.js new file mode 100644 index 0000000..6919793 --- /dev/null +++ b/tests/expressions/t/inc_dec.js @@ -0,0 +1,2 @@ +++a; b++; +a--, --b; \ No newline at end of file diff --git a/tests/js_test_suite.py b/tests/js_test_suite.py new file mode 100644 index 0000000..a2e00d4 --- /dev/null +++ b/tests/js_test_suite.py @@ -0,0 +1,103 @@ +from typing import List, Optional +import os +from pathlib import Path +import difflib +from jasminesnake.js_stream import JSStringStream +import jasminesnake.ast as js_ast + + +class JSTest: + _test_name: str + _test_file: str + _result_file: Optional[str] + + @property + def name(self): + return self._test_name + + def __init__(self, name: str, test_file: str, result_file: Optional[str]): + self._test_name = name + self._test_file = test_file + self._result_file = result_file + + def run(self, must_fail: bool = False): + payload = Path(self._test_file).read_text() + jst = JSStringStream(payload) + tree = jst.parse() + ast_tree = None + try: + ast_tree = js_ast.from_parse_tree(tree) + except NotImplementedError as e: + print("Seems like some nodes are not implemented :^)") + print("Error message: ") + if hasattr(e, "message"): + print(e.message) + else: + print(e) + + return must_fail + + expected = None + if self._result_file is not None: + expected = Path(self._result_file).read_text() + + got = js_ast.to_ascii_tree(ast_tree, ast_format="short") + + del jst + del tree + del ast_tree + + if expected is not None: + if expected == got: + print("Test {} OK...".format(self._test_name)) + else: + print( + "Error in test `{}':\nExpected:\n```{}```\nGot:\n```{}```".format( + self._test_name, expected, got + ) + ) + # for i, s in enumerate(difflib.ndiff(expected, got)): + # if s[0] != " ": + # print(s[0], ord(s[-1]), "at", i) + + return False + else: + print("Test {} has no result file!\nGot:\n{}".format(self._test_name, got)) + return False + + return True + + +class JSTestCollection: + tests: List[JSTest] + + def __init__(self, module_path: str): + self.tests = [] + basedir = os.path.abspath(module_path) + tests_dir = os.path.join(basedir, "t") + results_dir = os.path.join(basedir, "r") + + # Collect tests + test_files = [ + os.path.join(tests_dir, f) + for f in os.listdir(tests_dir) + if os.path.isfile(os.path.join(tests_dir, f)) + ] + test_names = [ + os.path.splitext(os.path.basename(path))[0] for path in test_files + ] + + for (test_name, test_file) in zip(test_names, test_files): + result_file = os.path.join(results_dir, test_name) + ".ast" + print(test_name, test_file, result_file) + if not os.path.isfile(result_file): + result_file = None + + test_case = JSTest(test_name, test_file, result_file) + self.tests.append(test_case) + + def run_all(self, must_fail: bool = False): + for test in self.tests: + if not test.run(must_fail): + return False + return True diff --git a/tests/literals/r/0001.ast b/tests/literals/r/0001.ast new file mode 100644 index 0000000..f67c2b8 --- /dev/null +++ b/tests/literals/r/0001.ast @@ -0,0 +1,18 @@ +Program at 1:0 ++-- sourceType: script ++-- body: +| +-- 0: ExpressionStatement at 1:0 +| | +-- expression: SequenceExpression at 1:0 +| | | +-- expressions: +| | | | +-- 0: ArrayExpression at 1:0 +| | | | | +-- elements: +| | | | | | +-- 0: Literal at 1:1 +| | | | | | | +-- value: 4.0 +| | | | | | +-- 1: Literal at 1:3 +| | | | | | | +-- value: 4.0 +| | | | | | +-- 2: Literal at 1:5 +| | | | | | | +-- value: 4.0 +| | | | | | +-- 3: Literal at 1:7 +| | | | | | | +-- value: 4.0 +| | | | | | +-- 4: Literal at 1:9 +| | | | | | | +-- value: 4.0 diff --git a/tests/literals/r/0002.ast b/tests/literals/r/0002.ast new file mode 100644 index 0000000..f64420a --- /dev/null +++ b/tests/literals/r/0002.ast @@ -0,0 +1,13 @@ +Program at 1:0 ++-- sourceType: script ++-- body: +| +-- 0: ExpressionStatement at 1:0 +| | +-- expression: SequenceExpression at 1:0 +| | | +-- expressions: +| | | | +-- 0: ArrayExpression at 1:0 +| | | | | +-- elements: +| | | | | | +-- 0: SpreadElement at 1:1 +| | | | | | | +-- argument: Identifier at 1:4 +| | | | | | | | +-- name: a +| | | | | | +-- 1: Identifier at 1:7 +| | | | | | | +-- name: b diff --git a/tests/literals/r/0003.ast b/tests/literals/r/0003.ast new file mode 100644 index 0000000..88057b9 --- /dev/null +++ b/tests/literals/r/0003.ast @@ -0,0 +1,19 @@ +Program at 1:0 ++-- sourceType: script ++-- body: +| +-- 0: VariableDeclaration at 1:0 +| | +-- kind: let +| | +-- declarations: +| | | +-- 0: VariableDeclarator at 1:4 +| | | | +-- id: ArrayPattern at 1:4 +| | | | | +-- elements: +| | | | | | +-- 0: Identifier at 1:5 +| | | | | | | +-- name: a +| | | | | | +-- 1: Identifier at 1:8 +| | | | | | | +-- name: b +| | | | +-- init: ArrayExpression at 1:13 +| | | | | +-- elements: +| | | | | | +-- 0: Literal at 1:14 +| | | | | | | +-- value: 4.0 +| | | | | | +-- 1: Literal at 1:17 +| | | | | | | +-- value: 4.0 diff --git a/tests/literals/r/0004.ast b/tests/literals/r/0004.ast new file mode 100644 index 0000000..ead44c5 --- /dev/null +++ b/tests/literals/r/0004.ast @@ -0,0 +1,33 @@ +Program at 1:0 ++-- sourceType: script ++-- body: +| +-- 0: ExpressionStatement at 1:0 +| | +-- expression: SequenceExpression at 1:0 +| | | +-- expressions: +| | | | +-- 0: Literal at 1:0 +| | | | | +-- value: 4444.0 +| +-- 1: ExpressionStatement at 2:0 +| | +-- expression: SequenceExpression at 2:0 +| | | +-- expressions: +| | | | +-- 0: Literal at 2:0 +| | | | | +-- value: 444444444.4444444 +| +-- 2: ExpressionStatement at 3:0 +| | +-- expression: SequenceExpression at 3:0 +| | | +-- expressions: +| | | | +-- 0: Literal at 3:0 +| | | | | +-- value: 4.0 +| +-- 3: ExpressionStatement at 4:0 +| | +-- expression: SequenceExpression at 4:0 +| | | +-- expressions: +| | | | +-- 0: true +| | | | | +-- value: True +| +-- 4: ExpressionStatement at 5:0 +| | +-- expression: SequenceExpression at 5:0 +| | | +-- expressions: +| | | | +-- 0: false +| | | | | +-- value: False +| +-- 5: ExpressionStatement at 6:0 +| | +-- expression: SequenceExpression at 6:0 +| | | +-- expressions: +| | | | +-- 0: "String literal" +| | | | | +-- value: String literal diff --git a/tests/literals/r/0005.ast b/tests/literals/r/0005.ast new file mode 100644 index 0000000..94d397d --- /dev/null +++ b/tests/literals/r/0005.ast @@ -0,0 +1,8 @@ +Program at 1:0 ++-- sourceType: script ++-- body: +| +-- 0: ExpressionStatement at 1:0 +| | +-- expression: SequenceExpression at 1:0 +| | | +-- expressions: +| | | | +-- 0: "String literal, but single quoted" +| | | | | +-- value: String literal, but single quoted diff --git a/tests/literals/t/0001.js b/tests/literals/t/0001.js new file mode 100644 index 0000000..2918627 --- /dev/null +++ b/tests/literals/t/0001.js @@ -0,0 +1 @@ +[4,4,4,4,4,]; diff --git a/tests/literals/t/0002.js b/tests/literals/t/0002.js new file mode 100644 index 0000000..63b1e47 --- /dev/null +++ b/tests/literals/t/0002.js @@ -0,0 +1 @@ +[...a, b]; \ No newline at end of file diff --git a/tests/literals/t/0003.js b/tests/literals/t/0003.js new file mode 100644 index 0000000..b34dd8f --- /dev/null +++ b/tests/literals/t/0003.js @@ -0,0 +1 @@ +let [a, b] = [4, 4]; \ No newline at end of file diff --git a/tests/literals/t/0004.js b/tests/literals/t/0004.js new file mode 100644 index 0000000..4019e17 --- /dev/null +++ b/tests/literals/t/0004.js @@ -0,0 +1,6 @@ +4444; +444_444_444.444_444_444; +4; +true; +false; +"String literal"; \ No newline at end of file diff --git a/tests/literals/t/0005.js b/tests/literals/t/0005.js new file mode 100644 index 0000000..61fd94e --- /dev/null +++ b/tests/literals/t/0005.js @@ -0,0 +1 @@ +'String literal, but single quoted' \ No newline at end of file diff --git a/tests/statements/r/block_stmt.ast b/tests/statements/r/block_stmt.ast new file mode 100644 index 0000000..12d7c07 --- /dev/null +++ b/tests/statements/r/block_stmt.ast @@ -0,0 +1,38 @@ +Program at 1:0 ++-- sourceType: script ++-- body: +| +-- 0: BlockStatement at 1:0 +| | +-- body: +| | | +-- 0: VariableDeclaration at 1:1 +| | | | +-- kind: let +| | | | +-- declarations: +| | | | | +-- 0: VariableDeclarator at 1:5 +| | | | | | +-- id: Identifier at 1:5 +| | | | | | | +-- name: a +| | | | | | +-- init: Literal at 1:9 +| | | | | | | +-- value: 15.0 +| | | | | +-- 1: VariableDeclarator at 1:13 +| | | | | | +-- id: Identifier at 1:13 +| | | | | | | +-- name: b +| | | | | | +-- init: None +| | | +-- 1: BlockStatement at 1:16 +| | | | +-- body: +| | | | | +-- 0: ExpressionStatement at 1:17 +| | | | | | +-- expression: SequenceExpression at 1:17 +| | | | | | | +-- expressions: +| | | | | | | | +-- 0: Literal at 1:17 +| | | | | | | | | +-- value: 1337.228 +| | | | | | | | +-- 1: false +| | | | | | | | | +-- value: False +| | | | | | | | +-- 2: "String" +| | | | | | | | | +-- value: String +| | | +-- 2: EmptyStatement at 1:45 +| | | +-- 3: BlockStatement at 1:47 +| | | | +-- body: +| | | | | +-- 0: VariableDeclaration at 1:48 +| | | | | | +-- kind: var +| | | | | | +-- declarations: +| | | | | | | +-- 0: VariableDeclarator at 1:52 +| | | | | | | | +-- id: Identifier at 1:52 +| | | | | | | | | +-- name: aaaaaaaaaaaaaa +| | | | | | | | +-- init: None diff --git a/tests/statements/r/variable_decl.ast b/tests/statements/r/variable_decl.ast new file mode 100644 index 0000000..7659df8 --- /dev/null +++ b/tests/statements/r/variable_decl.ast @@ -0,0 +1,65 @@ +Program at 1:0 ++-- sourceType: script ++-- body: +| +-- 0: VariableDeclaration at 1:0 +| | +-- kind: let +| | +-- declarations: +| | | +-- 0: VariableDeclarator at 1:4 +| | | | +-- id: Identifier at 1:4 +| | | | | +-- name: a +| | | | +-- init: None +| +-- 1: VariableDeclaration at 2:0 +| | +-- kind: var +| | +-- declarations: +| | | +-- 0: VariableDeclarator at 2:4 +| | | | +-- id: Identifier at 2:4 +| | | | | +-- name: b +| | | | +-- init: None +| +-- 2: VariableDeclaration at 4:0 +| | +-- kind: let +| | +-- declarations: +| | | +-- 0: VariableDeclarator at 4:4 +| | | | +-- id: Identifier at 4:4 +| | | | | +-- name: zzz +| | | | +-- init: Literal at 4:10 +| | | | | +-- value: 0.0 +| | | +-- 1: VariableDeclarator at 4:13 +| | | | +-- id: Identifier at 4:13 +| | | | | +-- name: k +| | | | +-- init: None +| +-- 3: VariableDeclaration at 5:0 +| | +-- kind: let +| | +-- declarations: +| | | +-- 0: VariableDeclarator at 5:4 +| | | | +-- id: Identifier at 5:4 +| | | | | +-- name: cc +| | | | +-- init: None +| | | +-- 1: VariableDeclarator at 5:8 +| | | | +-- id: Identifier at 5:8 +| | | | | +-- name: asa +| | | | +-- init: None +| +-- 4: VariableDeclaration at 6:0 +| | +-- kind: let +| | +-- declarations: +| | | +-- 0: VariableDeclarator at 6:4 +| | | | +-- id: Identifier at 6:4 +| | | | | +-- name: cccccc +| | | | +-- init: None +| | | +-- 1: VariableDeclarator at 6:12 +| | | | +-- id: Identifier at 6:12 +| | | | | +-- name: asasa +| | | | +-- init: Literal at 6:20 +| | | | | +-- value: 0.0 +| +-- 5: VariableDeclaration at 8:0 +| | +-- kind: var +| | +-- declarations: +| | | +-- 0: VariableDeclarator at 8:4 +| | | | +-- id: Identifier at 8:4 +| | | | | +-- name: x +| | | | +-- init: Literal at 8:8 +| | | | | +-- value: 0.0 +| | | +-- 1: VariableDeclarator at 8:11 +| | | | +-- id: Identifier at 8:11 +| | | | | +-- name: y +| | | | +-- init: Literal at 8:15 +| | | | | +-- value: 0.0 diff --git a/tests/statements/t/block_stmt.js b/tests/statements/t/block_stmt.js new file mode 100644 index 0000000..f4eb03d --- /dev/null +++ b/tests/statements/t/block_stmt.js @@ -0,0 +1 @@ +{let a = 15, b; {1_337.2_28, false, "String"}; {var aaaaaaaaaaaaaa}} \ No newline at end of file diff --git a/tests/statements/t/variable_decl.js b/tests/statements/t/variable_decl.js new file mode 100644 index 0000000..bef832d --- /dev/null +++ b/tests/statements/t/variable_decl.js @@ -0,0 +1,8 @@ +let a; +var b; + +let zzz = 0, k; +let cc, asa; +let cccccc, asasa = 0; + +var x = 0, y = 0 \ No newline at end of file diff --git a/tests/test.js b/tests/test.js deleted file mode 100644 index ab5e07c..0000000 --- a/tests/test.js +++ /dev/null @@ -1,15 +0,0 @@ -// The code below won't work since the grammar treat Unicode -//"\x20\x77hil\x65\x20exe\x63uting c\x6cient e\x76\145\x6et "; - -//{let a = 15, b} - - -{{{let t = false, n = true}}} -//++a15; -var a, b=14; -let c; -; -4444444444444444444444; -//228,1444444444444;t,fnm -//if (1) 0; -//function f4444444(){} diff --git a/tests/test_ast.py b/tests/test_ast.py new file mode 100644 index 0000000..214c6c6 --- /dev/null +++ b/tests/test_ast.py @@ -0,0 +1,30 @@ +import os +import pytest +from js_test_suite import * + +BASE_PATH = os.path.dirname(os.path.abspath(__file__)) + + +class TestAST: + def test_literals(self): + tcl = JSTestCollection(os.path.join(BASE_PATH, "literals")) + assert tcl.run_all() + + def test_statements(self): + tcs = JSTestCollection(os.path.join(BASE_PATH, "statements")) + assert tcs.run_all() + + # @pytest.mark.skip(reason="Not yet implemented") + def test_expressions(self): + tce = JSTestCollection(os.path.join(BASE_PATH, "expressions")) + assert tce.run_all() + + # @pytest.mark.xfail(reason="Not yet implemented features.") + def test_todos(self): + tcb = JSTestCollection(os.path.join(BASE_PATH, "todos")) + assert tcb.run_all(must_fail=True) + + @pytest.mark.xfail(reason="Bugs.") + def test_bugs(self): + tcb = JSTestCollection(os.path.join(BASE_PATH, "bugs")) + assert tcb.run_all(must_fail=True) diff --git a/tests/todos/t/conditions.js b/tests/todos/t/conditions.js new file mode 100644 index 0000000..4e2a812 --- /dev/null +++ b/tests/todos/t/conditions.js @@ -0,0 +1 @@ +if (1) 0; \ No newline at end of file diff --git a/tests/todos/t/for_loops.js b/tests/todos/t/for_loops.js new file mode 100644 index 0000000..fe1d6d7 --- /dev/null +++ b/tests/todos/t/for_loops.js @@ -0,0 +1,4 @@ +for (let a = 0; a < b; ++a) c++; +for (;b > c; --b) {a = b/c} + +for (;;) {} \ No newline at end of file diff --git a/tests/todos/t/obj_literals.js b/tests/todos/t/obj_literals.js new file mode 100644 index 0000000..a720fa1 --- /dev/null +++ b/tests/todos/t/obj_literals.js @@ -0,0 +1,4 @@ +// Object literals? +let a = {a: 4, b: 4}; +let k = {"a444": 444, 'b555': 555}; +