jaclang 0.8.9__py3-none-any.whl → 0.8.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of jaclang might be problematic. Click here for more details.
- jaclang/cli/cli.py +147 -25
- jaclang/cli/cmdreg.py +144 -8
- jaclang/compiler/__init__.py +6 -1
- jaclang/compiler/codeinfo.py +16 -1
- jaclang/compiler/constant.py +33 -13
- jaclang/compiler/jac.lark +130 -31
- jaclang/compiler/larkparse/jac_parser.py +2 -2
- jaclang/compiler/parser.py +567 -176
- jaclang/compiler/passes/__init__.py +2 -1
- jaclang/compiler/passes/ast_gen/__init__.py +5 -0
- jaclang/compiler/passes/ast_gen/base_ast_gen_pass.py +54 -0
- jaclang/compiler/passes/ast_gen/jsx_processor.py +344 -0
- jaclang/compiler/passes/ecmascript/__init__.py +25 -0
- jaclang/compiler/passes/ecmascript/es_unparse.py +576 -0
- jaclang/compiler/passes/ecmascript/esast_gen_pass.py +2068 -0
- jaclang/compiler/passes/ecmascript/estree.py +972 -0
- jaclang/compiler/passes/ecmascript/tests/__init__.py +1 -0
- jaclang/compiler/passes/ecmascript/tests/fixtures/advanced_language_features.jac +170 -0
- jaclang/compiler/passes/ecmascript/tests/fixtures/class_separate_impl.impl.jac +30 -0
- jaclang/compiler/passes/ecmascript/tests/fixtures/class_separate_impl.jac +14 -0
- jaclang/compiler/passes/ecmascript/tests/fixtures/client_jsx.jac +89 -0
- jaclang/compiler/passes/ecmascript/tests/fixtures/core_language_features.jac +195 -0
- jaclang/compiler/passes/ecmascript/tests/test_esast_gen_pass.py +167 -0
- jaclang/compiler/passes/ecmascript/tests/test_js_generation.py +239 -0
- jaclang/compiler/passes/main/__init__.py +0 -3
- jaclang/compiler/passes/main/annex_pass.py +23 -1
- jaclang/compiler/passes/main/pyast_gen_pass.py +324 -234
- jaclang/compiler/passes/main/pyast_load_pass.py +46 -11
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +2 -0
- jaclang/compiler/passes/main/sym_tab_build_pass.py +18 -1
- jaclang/compiler/passes/main/tests/fixtures/autoimpl.cl.jac +7 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_arity.jac +3 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_class_construct.jac +33 -0
- jaclang/compiler/passes/main/tests/fixtures/defuse_modpath.jac +7 -0
- jaclang/compiler/passes/main/tests/fixtures/member_access_type_resolve.jac +2 -1
- jaclang/compiler/passes/main/tests/test_checker_pass.py +31 -2
- jaclang/compiler/passes/main/tests/test_def_use_pass.py +12 -0
- jaclang/compiler/passes/main/tests/test_import_pass.py +23 -4
- jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +25 -0
- jaclang/compiler/passes/main/type_checker_pass.py +7 -0
- jaclang/compiler/passes/tool/doc_ir_gen_pass.py +115 -0
- jaclang/compiler/passes/tool/fuse_comments_pass.py +1 -10
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +4 -1
- jaclang/compiler/passes/transform.py +9 -1
- jaclang/compiler/passes/uni_pass.py +5 -7
- jaclang/compiler/program.py +22 -25
- jaclang/compiler/tests/test_client_codegen.py +113 -0
- jaclang/compiler/tests/test_importer.py +12 -10
- jaclang/compiler/tests/test_parser.py +249 -3
- jaclang/compiler/type_system/type_evaluator.jac +169 -50
- jaclang/compiler/type_system/type_utils.py +1 -1
- jaclang/compiler/type_system/types.py +6 -0
- jaclang/compiler/unitree.py +430 -84
- jaclang/langserve/engine.jac +224 -288
- jaclang/langserve/sem_manager.jac +12 -8
- jaclang/langserve/server.jac +48 -48
- jaclang/langserve/tests/fixtures/greet.py +17 -0
- jaclang/langserve/tests/fixtures/md_path.jac +22 -0
- jaclang/langserve/tests/fixtures/user.jac +15 -0
- jaclang/langserve/tests/test_server.py +66 -371
- jaclang/lib.py +1 -1
- jaclang/runtimelib/client_bundle.py +169 -0
- jaclang/runtimelib/client_runtime.jac +586 -0
- jaclang/runtimelib/constructs.py +2 -0
- jaclang/runtimelib/machine.py +259 -100
- jaclang/runtimelib/meta_importer.py +111 -22
- jaclang/runtimelib/mtp.py +15 -0
- jaclang/runtimelib/server.py +1089 -0
- jaclang/runtimelib/tests/fixtures/client_app.jac +18 -0
- jaclang/runtimelib/tests/fixtures/custom_access_validation.jac +1 -1
- jaclang/runtimelib/tests/fixtures/savable_object.jac +4 -5
- jaclang/runtimelib/tests/fixtures/serve_api.jac +75 -0
- jaclang/runtimelib/tests/test_client_bundle.py +55 -0
- jaclang/runtimelib/tests/test_client_render.py +63 -0
- jaclang/runtimelib/tests/test_serve.py +1069 -0
- jaclang/settings.py +0 -2
- jaclang/tests/fixtures/iife_functions.jac +142 -0
- jaclang/tests/fixtures/iife_functions_client.jac +143 -0
- jaclang/tests/fixtures/multistatement_lambda.jac +116 -0
- jaclang/tests/fixtures/multistatement_lambda_client.jac +113 -0
- jaclang/tests/fixtures/needs_import_dup.jac +6 -4
- jaclang/tests/fixtures/py_run.py +7 -5
- jaclang/tests/fixtures/pyfunc_fstr.py +2 -2
- jaclang/tests/fixtures/simple_lambda_test.jac +12 -0
- jaclang/tests/test_cli.py +1 -1
- jaclang/tests/test_language.py +10 -39
- jaclang/tests/test_reference.py +17 -2
- jaclang/utils/NonGPT.py +375 -0
- jaclang/utils/helpers.py +44 -16
- jaclang/utils/lang_tools.py +31 -4
- jaclang/utils/tests/test_lang_tools.py +1 -1
- jaclang/utils/treeprinter.py +8 -3
- {jaclang-0.8.9.dist-info → jaclang-0.8.10.dist-info}/METADATA +3 -3
- {jaclang-0.8.9.dist-info → jaclang-0.8.10.dist-info}/RECORD +96 -66
- jaclang/compiler/passes/main/binder_pass.py +0 -594
- jaclang/compiler/passes/main/tests/fixtures/sym_binder.jac +0 -47
- jaclang/compiler/passes/main/tests/test_binder_pass.py +0 -111
- jaclang/langserve/tests/session.jac +0 -294
- jaclang/langserve/tests/test_dev_server.py +0 -80
- jaclang/runtimelib/importer.py +0 -351
- jaclang/tests/test_typecheck.py +0 -542
- {jaclang-0.8.9.dist-info → jaclang-0.8.10.dist-info}/WHEEL +0 -0
- {jaclang-0.8.9.dist-info → jaclang-0.8.10.dist-info}/entry_points.txt +0 -0
jaclang/tests/test_typecheck.py
DELETED
|
@@ -1,542 +0,0 @@
|
|
|
1
|
-
"""Test Jac language generally."""
|
|
2
|
-
|
|
3
|
-
import io
|
|
4
|
-
import os
|
|
5
|
-
import sys
|
|
6
|
-
import unittest
|
|
7
|
-
import sysconfig
|
|
8
|
-
import tempfile
|
|
9
|
-
from unittest.mock import patch
|
|
10
|
-
|
|
11
|
-
from jaclang import JacMachineInterface as Jac, JacMachine
|
|
12
|
-
from jaclang.cli import cli
|
|
13
|
-
from jaclang.compiler.program import JacProgram
|
|
14
|
-
from jaclang.utils.lang_tools import AstTool
|
|
15
|
-
from jaclang.utils.test import TestCase
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@unittest.skip("Skipping typecheck tests")
|
|
19
|
-
class JacTypeCheckTests(TestCase):
|
|
20
|
-
"""Test pass module."""
|
|
21
|
-
|
|
22
|
-
def setUp(self) -> None:
|
|
23
|
-
"""Set up test."""
|
|
24
|
-
self.mach = JacMachine(self.fixture_abs_path("./"))
|
|
25
|
-
Jac.attach_program(
|
|
26
|
-
self.mach,
|
|
27
|
-
JacProgram(),
|
|
28
|
-
)
|
|
29
|
-
return super().setUp()
|
|
30
|
-
|
|
31
|
-
def tearDown(self) -> None:
|
|
32
|
-
"""Tear down test."""
|
|
33
|
-
return super().tearDown()
|
|
34
|
-
|
|
35
|
-
def test_multi_dim_arr_slice(self) -> None:
|
|
36
|
-
"""Parse micro jac file."""
|
|
37
|
-
captured_output = io.StringIO()
|
|
38
|
-
sys.stdout = captured_output
|
|
39
|
-
cli.tool(
|
|
40
|
-
"ir",
|
|
41
|
-
[
|
|
42
|
-
"ast",
|
|
43
|
-
self.fixture_abs_path("multi_dim_array_split.jac"),
|
|
44
|
-
],
|
|
45
|
-
)
|
|
46
|
-
sys.stdout = sys.__stdout__
|
|
47
|
-
stdout_value = captured_output.getvalue()
|
|
48
|
-
|
|
49
|
-
expected_outputs = [
|
|
50
|
-
"+-- AtomTrailer - Type: builtins.list[builtins.int]",
|
|
51
|
-
" +-- Name - arr - Type: builtins.list[builtins.list[builtins.int]], SymbolTable: list",
|
|
52
|
-
"+-- IndexSlice - [IndexSlice] - Type: builtins.list[builtins.list[builtins.int]], SymbolTable: None",
|
|
53
|
-
" +-- Token - [, ",
|
|
54
|
-
" +-- Int - 1 - Type: Literal[1]?, SymbolTable: None",
|
|
55
|
-
" +-- Token - :, ",
|
|
56
|
-
" +-- Int - 3 - Type: Literal[3]?, SymbolTable: None",
|
|
57
|
-
" +-- Token - ,, ",
|
|
58
|
-
" +-- Int - 1 - Type: Literal[1]?, SymbolTable: None",
|
|
59
|
-
" +-- Token - :, ",
|
|
60
|
-
" +-- Token - :, ",
|
|
61
|
-
" +-- Int - 2 - Type: Literal[2]?, SymbolTable: None",
|
|
62
|
-
" +-- Token - ], ",
|
|
63
|
-
]
|
|
64
|
-
|
|
65
|
-
for expected in expected_outputs:
|
|
66
|
-
self.assertIn(expected, stdout_value)
|
|
67
|
-
|
|
68
|
-
def test_needs_import_1(self) -> None:
|
|
69
|
-
"""Test py ast to Jac ast conversion output."""
|
|
70
|
-
file_name = self.fixture_abs_path("pyfunc_1.py")
|
|
71
|
-
|
|
72
|
-
from jaclang.compiler.passes.main.pyast_load_pass import PyastBuildPass
|
|
73
|
-
import ast as py_ast
|
|
74
|
-
import jaclang.compiler.unitree as uni
|
|
75
|
-
|
|
76
|
-
with open(file_name, "r") as f:
|
|
77
|
-
file_source = f.read()
|
|
78
|
-
parsed_ast = py_ast.parse(file_source)
|
|
79
|
-
try:
|
|
80
|
-
py_ast_build_pass = PyastBuildPass(
|
|
81
|
-
ir_in=uni.PythonModuleAst(
|
|
82
|
-
parsed_ast, orig_src=uni.Source(file_source, file_name)
|
|
83
|
-
),
|
|
84
|
-
prog=JacProgram(),
|
|
85
|
-
).ir_out
|
|
86
|
-
except Exception as e:
|
|
87
|
-
return f"Error While Jac to Py AST conversion: {e}"
|
|
88
|
-
|
|
89
|
-
(prog := JacProgram()).build(
|
|
90
|
-
use_str=py_ast_build_pass.unparse(),
|
|
91
|
-
file_path=file_name[:-3] + ".jac",
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
archetype_count = 0
|
|
95
|
-
for mod in prog.mod.hub.values():
|
|
96
|
-
if mod.name == "builtins":
|
|
97
|
-
continue
|
|
98
|
-
archetype_count += len(mod.get_all_sub_nodes(uni.Archetype))
|
|
99
|
-
|
|
100
|
-
self.assertEqual(archetype_count, 24)
|
|
101
|
-
captured_output = io.StringIO()
|
|
102
|
-
sys.stdout = captured_output
|
|
103
|
-
Jac.jac_import(
|
|
104
|
-
self.mach, "needs_import_1", base_path=self.fixture_abs_path("./")
|
|
105
|
-
)
|
|
106
|
-
sys.stdout = sys.__stdout__
|
|
107
|
-
stdout_value = captured_output.getvalue()
|
|
108
|
-
self.assertIn("pyfunc_1 imported", stdout_value)
|
|
109
|
-
|
|
110
|
-
def test_needs_import_2(self) -> None:
|
|
111
|
-
"""Test py ast to Jac ast conversion output."""
|
|
112
|
-
file_name = self.fixture_abs_path("pyfunc_2.py")
|
|
113
|
-
|
|
114
|
-
from jaclang.compiler.passes.main.pyast_load_pass import PyastBuildPass
|
|
115
|
-
import ast as py_ast
|
|
116
|
-
import jaclang.compiler.unitree as uni
|
|
117
|
-
|
|
118
|
-
with open(file_name, "r") as f:
|
|
119
|
-
file_source = f.read()
|
|
120
|
-
parsed_ast = py_ast.parse(file_source)
|
|
121
|
-
try:
|
|
122
|
-
py_ast_build_pass = PyastBuildPass(
|
|
123
|
-
ir_in=uni.PythonModuleAst(
|
|
124
|
-
parsed_ast,
|
|
125
|
-
orig_src=uni.Source(file_source, file_name),
|
|
126
|
-
),
|
|
127
|
-
prog=JacProgram(),
|
|
128
|
-
).ir_out
|
|
129
|
-
except Exception as e:
|
|
130
|
-
return f"Error While Jac to Py AST conversion: {e}"
|
|
131
|
-
|
|
132
|
-
(prog := JacProgram()).build(
|
|
133
|
-
use_str=py_ast_build_pass.unparse(),
|
|
134
|
-
file_path=file_name[:-3] + ".jac",
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
archetype_count = 0
|
|
138
|
-
for mod in prog.mod.hub.values():
|
|
139
|
-
if mod.name == "builtins":
|
|
140
|
-
continue
|
|
141
|
-
archetype_count += len(mod.get_all_sub_nodes(uni.Archetype))
|
|
142
|
-
|
|
143
|
-
self.assertEqual(archetype_count, 30) # Because of the Archetype from math
|
|
144
|
-
captured_output = io.StringIO()
|
|
145
|
-
sys.stdout = captured_output
|
|
146
|
-
Jac.jac_import(
|
|
147
|
-
self.mach, "needs_import_2", base_path=self.fixture_abs_path("./")
|
|
148
|
-
)
|
|
149
|
-
sys.stdout = sys.__stdout__
|
|
150
|
-
stdout_value = captured_output.getvalue()
|
|
151
|
-
self.assertIn("pyfunc_2 imported", stdout_value)
|
|
152
|
-
self.assertEqual(stdout_value.count("<class 'bytes'>"), 3)
|
|
153
|
-
|
|
154
|
-
def test_needs_import_3(
|
|
155
|
-
self,
|
|
156
|
-
) -> None: # TODO : Pyfunc_3 has a bug in conversion in matchmapping node
|
|
157
|
-
"""Test py ast to Jac ast conversion output."""
|
|
158
|
-
file_name = self.fixture_abs_path("pyfunc_3.py")
|
|
159
|
-
import jaclang.compiler.unitree as uni
|
|
160
|
-
|
|
161
|
-
with open(file_name, "r") as f:
|
|
162
|
-
file_source = f.read()
|
|
163
|
-
(prog := JacProgram()).build(use_str=file_source, file_path=file_name)
|
|
164
|
-
|
|
165
|
-
archetype_count = sum(
|
|
166
|
-
len(mod.get_all_sub_nodes(uni.Archetype))
|
|
167
|
-
for mod in prog.mod.hub.values()
|
|
168
|
-
if mod.name != "builtins"
|
|
169
|
-
)
|
|
170
|
-
self.assertEqual(
|
|
171
|
-
archetype_count, 58
|
|
172
|
-
) # Fixed duplication of 'case' module (previously included 3 times, added 20 extra Archetypes; 75 → 55)
|
|
173
|
-
builtin_mod = next(
|
|
174
|
-
(mod for name, mod in prog.mod.hub.items() if "builtins" in name),
|
|
175
|
-
None,
|
|
176
|
-
)
|
|
177
|
-
self.assertEqual(len(builtin_mod.get_all_sub_nodes(uni.Archetype)), 109)
|
|
178
|
-
captured_output = io.StringIO()
|
|
179
|
-
sys.stdout = captured_output
|
|
180
|
-
Jac.jac_import(
|
|
181
|
-
self.mach, "needs_import_3", base_path=self.fixture_abs_path("./")
|
|
182
|
-
)
|
|
183
|
-
sys.stdout = sys.__stdout__
|
|
184
|
-
stdout_value = captured_output.getvalue()
|
|
185
|
-
self.assertIn("pyfunc_3 imported", stdout_value)
|
|
186
|
-
|
|
187
|
-
def test_type_fuse_expr(self) -> None:
|
|
188
|
-
"""Basic test for pass."""
|
|
189
|
-
captured_output = io.StringIO()
|
|
190
|
-
sys.stdout = captured_output
|
|
191
|
-
cli.tool(
|
|
192
|
-
"ir",
|
|
193
|
-
[
|
|
194
|
-
"ast",
|
|
195
|
-
self.examples_abs_path("reference/collection_values.jac"),
|
|
196
|
-
],
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
sys.stdout = sys.__stdout__
|
|
200
|
-
stdout_value = captured_output.getvalue()
|
|
201
|
-
self.assertIn(
|
|
202
|
-
"builtins.dict[builtins.int, builtins.int]",
|
|
203
|
-
stdout_value,
|
|
204
|
-
)
|
|
205
|
-
self.assertIn(
|
|
206
|
-
"typing.Generator[builtins.int, None, None]",
|
|
207
|
-
stdout_value,
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
def test_random_check(self) -> None:
|
|
211
|
-
"""Test py ast to Jac ast conversion output."""
|
|
212
|
-
from jaclang.settings import settings
|
|
213
|
-
|
|
214
|
-
module_paths = ["random", "ast"]
|
|
215
|
-
for module_path in module_paths:
|
|
216
|
-
stdlib_dir = sysconfig.get_paths()["stdlib"]
|
|
217
|
-
file_path = os.path.join(
|
|
218
|
-
stdlib_dir,
|
|
219
|
-
module_path + ".py",
|
|
220
|
-
)
|
|
221
|
-
settings.print_py_raised_ast = True
|
|
222
|
-
with open(file_path) as f:
|
|
223
|
-
file_source = f.read()
|
|
224
|
-
ir = JacProgram().build(
|
|
225
|
-
use_str=file_source,
|
|
226
|
-
file_path=file_path,
|
|
227
|
-
)
|
|
228
|
-
gen_ast = ir.pp()
|
|
229
|
-
if module_path == "random":
|
|
230
|
-
self.assertIn("ModulePath - statistics -", gen_ast)
|
|
231
|
-
else:
|
|
232
|
-
self.assertIn("+-- Name - NodeTransformer - Type: No", gen_ast)
|
|
233
|
-
|
|
234
|
-
def test_deep_convert(self) -> None:
|
|
235
|
-
"""Test py ast to Jac ast conversion output."""
|
|
236
|
-
file_name = self.fixture_abs_path("pyfunc_1.py")
|
|
237
|
-
|
|
238
|
-
import jaclang.compiler.unitree as uni
|
|
239
|
-
from jaclang.settings import settings
|
|
240
|
-
|
|
241
|
-
settings.print_py_raised_ast = True
|
|
242
|
-
with open(file_name, "r") as f:
|
|
243
|
-
file_source = f.read()
|
|
244
|
-
ir = (prog := JacProgram()).build(use_str=file_source, file_path=file_name)
|
|
245
|
-
jac_ast = ir.pp()
|
|
246
|
-
self.assertIn(" | +-- String - 'Loop completed normally{}'", jac_ast)
|
|
247
|
-
sub_node_list_count = 0
|
|
248
|
-
for i in prog.mod.hub.values():
|
|
249
|
-
if i.name == "builtins":
|
|
250
|
-
continue
|
|
251
|
-
sub_node_list_count += len(i.get_all_sub_nodes(uni.SubNodeList))
|
|
252
|
-
self.assertEqual(sub_node_list_count, 623)
|
|
253
|
-
captured_output = io.StringIO()
|
|
254
|
-
sys.stdout = captured_output
|
|
255
|
-
Jac.jac_import(self.mach, "deep_convert", base_path=self.fixture_abs_path("./"))
|
|
256
|
-
sys.stdout = sys.__stdout__
|
|
257
|
-
stdout_value = captured_output.getvalue()
|
|
258
|
-
self.assertIn("Deep convo is imported", stdout_value)
|
|
259
|
-
|
|
260
|
-
def test_ds_type_check_pass(self) -> None:
|
|
261
|
-
"""Test conn assign on edges."""
|
|
262
|
-
(mypass := JacProgram()).build(
|
|
263
|
-
self.examples_abs_path("micro/simple_walk.jac"),
|
|
264
|
-
)
|
|
265
|
-
self.assertEqual(len(mypass.errors_had), 0)
|
|
266
|
-
self.assertEqual(len(mypass.warnings_had), 0)
|
|
267
|
-
|
|
268
|
-
def test_ds_type_check_pass2(self) -> None:
|
|
269
|
-
"""Test conn assign on edges."""
|
|
270
|
-
(mypass := JacProgram()).build(
|
|
271
|
-
self.examples_abs_path("guess_game/guess_game5.jac"),
|
|
272
|
-
)
|
|
273
|
-
self.assertEqual(len(mypass.errors_had), 0)
|
|
274
|
-
self.assertEqual(len(mypass.warnings_had), 0)
|
|
275
|
-
|
|
276
|
-
def test_circle_override1_type_check_pass(self) -> None:
|
|
277
|
-
"""Test conn assign on edges."""
|
|
278
|
-
(mypass := JacProgram()).build(
|
|
279
|
-
self.examples_abs_path("manual_code/circle.jac"),
|
|
280
|
-
)
|
|
281
|
-
self.assertEqual(len(mypass.errors_had), 0)
|
|
282
|
-
# FIXME: Figure out what to do with warning.
|
|
283
|
-
# self.assertEqual(len(mypass.warnings_had), 0)
|
|
284
|
-
|
|
285
|
-
def test_expr_types(self) -> None:
|
|
286
|
-
"""Testing for print AstTool."""
|
|
287
|
-
captured_output = io.StringIO()
|
|
288
|
-
sys.stdout = captured_output
|
|
289
|
-
|
|
290
|
-
cli.tool("ir", ["ast", f"{self.fixture_abs_path('expr_type.jac')}"])
|
|
291
|
-
|
|
292
|
-
sys.stdout = sys.__stdout__
|
|
293
|
-
stdout_value = captured_output.getvalue()
|
|
294
|
-
|
|
295
|
-
self.assertRegex(
|
|
296
|
-
stdout_value, r"4\:9 \- 4\:14.*BinaryExpr \- Type\: builtins.int"
|
|
297
|
-
)
|
|
298
|
-
self.assertRegex(
|
|
299
|
-
stdout_value, r"7\:9 \- 7\:17.*FuncCall \- Type\: builtins.float"
|
|
300
|
-
)
|
|
301
|
-
self.assertRegex(
|
|
302
|
-
stdout_value, r"9\:6 \- 9\:11.*CompareExpr \- Type\: builtins.bool"
|
|
303
|
-
)
|
|
304
|
-
self.assertRegex(
|
|
305
|
-
stdout_value, r"10\:6 - 10\:15.*BinaryExpr \- Type\: builtins.str"
|
|
306
|
-
)
|
|
307
|
-
self.assertRegex(
|
|
308
|
-
stdout_value, r"11\:5 \- 11\:13.*AtomTrailer \- Type\: builtins.int"
|
|
309
|
-
)
|
|
310
|
-
self.assertRegex(
|
|
311
|
-
stdout_value, r"12\:5 \- 12\:14.*UnaryExpr \- Type\: builtins.bool"
|
|
312
|
-
)
|
|
313
|
-
self.assertRegex(
|
|
314
|
-
stdout_value, r"13\:5 \- 13\:25.*IfElseExpr \- Type\: Literal\['a']\?"
|
|
315
|
-
)
|
|
316
|
-
self.assertRegex(
|
|
317
|
-
stdout_value,
|
|
318
|
-
r"14\:5 \- 14\:27.*ListCompr - \[ListCompr] \- Type\: builtins.list\[builtins.int]",
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
def test_type_check(self) -> None:
|
|
322
|
-
"""Testing for print AstTool."""
|
|
323
|
-
captured_output = io.StringIO()
|
|
324
|
-
sys.stdout = captured_output
|
|
325
|
-
cli.check(f"{self.fixture_abs_path('game1.jac')}")
|
|
326
|
-
sys.stdout = sys.__stdout__
|
|
327
|
-
stdout_value = captured_output.getvalue()
|
|
328
|
-
self.assertIn("Errors: 0, Warnings: 1", stdout_value)
|
|
329
|
-
|
|
330
|
-
def test_type_errors(self) -> None:
|
|
331
|
-
"""Basic test for pass."""
|
|
332
|
-
(type_checked := JacProgram()).build(
|
|
333
|
-
file_path=self.fixture_abs_path("func.jac"),
|
|
334
|
-
)
|
|
335
|
-
|
|
336
|
-
errs = "\n".join([i.msg for i in type_checked.warnings_had])
|
|
337
|
-
files = "\n".join([i.loc.mod_path for i in type_checked.warnings_had])
|
|
338
|
-
|
|
339
|
-
for i in [
|
|
340
|
-
"func2.jac",
|
|
341
|
-
"func.jac",
|
|
342
|
-
'(got "int", expected "str")',
|
|
343
|
-
'(got "str", expected "int")',
|
|
344
|
-
]:
|
|
345
|
-
self.assertIn(i, errs + files)
|
|
346
|
-
|
|
347
|
-
def test_imported_module_typecheck(self) -> None:
|
|
348
|
-
"""Basic test for pass."""
|
|
349
|
-
(type_checked := JacProgram()).build(
|
|
350
|
-
file_path=self.fixture_abs_path("game1.jac"),
|
|
351
|
-
)
|
|
352
|
-
|
|
353
|
-
errs = "\n".join([i.msg for i in type_checked.warnings_had])
|
|
354
|
-
files = "\n".join([i.loc.mod_path for i in type_checked.warnings_had])
|
|
355
|
-
|
|
356
|
-
for i in [
|
|
357
|
-
'Argument 2 to "is_pressed" of "Button" has incompatible type "int"; expected "str"',
|
|
358
|
-
]:
|
|
359
|
-
self.assertIn(i, errs + files)
|
|
360
|
-
|
|
361
|
-
def test_type_coverage(self) -> None:
|
|
362
|
-
"""Testing for type info coverage in sym_tab via ast."""
|
|
363
|
-
out = AstTool().ir(["ast", f"{self.fixture_abs_path('type_info.jac')}"])
|
|
364
|
-
lis = [
|
|
365
|
-
"introduce - Type: None",
|
|
366
|
-
"25:30 - 25:37\t | | | +-- Name - species - Type: None", # AtomTrailer
|
|
367
|
-
]
|
|
368
|
-
self.assertIn("HasVar - species - Type: builtins.str", out)
|
|
369
|
-
self.assertIn("myDog - Type: type_info.Dog", out)
|
|
370
|
-
self.assertIn("Body - Type: type_info.Dog.Body", out)
|
|
371
|
-
self.assertEqual(out.count("Type: builtins.str"), 35)
|
|
372
|
-
for i in lis:
|
|
373
|
-
self.assertNotIn(i, out)
|
|
374
|
-
|
|
375
|
-
def test_data_spatial_type_info(self) -> None:
|
|
376
|
-
"""Testing for type info for dataspatial constructs."""
|
|
377
|
-
out = AstTool().ir(
|
|
378
|
-
["ast", f"{self.fixture_abs_path('data_spatial_types.jac')}"]
|
|
379
|
-
)
|
|
380
|
-
self.assertRegex(
|
|
381
|
-
out,
|
|
382
|
-
r"129:22 - 129:26.*SpecialVarRef - root \- Type\: jaclang.runtimelib.archetype.Root",
|
|
383
|
-
)
|
|
384
|
-
self.assertRegex(out, r"129:11 - 129:27.*FuncCall \- Type\: builtins\.str")
|
|
385
|
-
self.assertRegex(
|
|
386
|
-
out,
|
|
387
|
-
r"129:13 - 129:21.*Name \- node_dot \- Type\: builtins.str",
|
|
388
|
-
)
|
|
389
|
-
|
|
390
|
-
self.assertRegex(
|
|
391
|
-
out,
|
|
392
|
-
r"128:5 - 128:25.*BinaryExpr \- Type\: "
|
|
393
|
-
+ r"Union\[jaclang.runtimelib.archetype.WalkerArchetype, concurrent.futures._base.Future\[Any\]\]",
|
|
394
|
-
)
|
|
395
|
-
|
|
396
|
-
self.assertRegex(
|
|
397
|
-
out,
|
|
398
|
-
r"48:11 - 48:28.*EdgeRefTrailer \- Type\: builtins.list\[jaclang.runtimelib.archetype.Archetype\]",
|
|
399
|
-
)
|
|
400
|
-
|
|
401
|
-
self.assertRegex(out, r"24:5 - 24:25.*BinaryExpr \- Type\: builtins.bool", out)
|
|
402
|
-
|
|
403
|
-
def test_type_info(self) -> None:
|
|
404
|
-
"""Testing for type info inside the ast tool."""
|
|
405
|
-
captured_output = io.StringIO()
|
|
406
|
-
sys.stdout = captured_output
|
|
407
|
-
cli.tool("ir", ["ast", f"{self.fixture_abs_path('type_info.jac')}"])
|
|
408
|
-
sys.stdout = sys.__stdout__
|
|
409
|
-
stdout_value = captured_output.getvalue()
|
|
410
|
-
self.assertEqual(stdout_value.count("type_info.ServerWrapper"), 5)
|
|
411
|
-
self.assertEqual(stdout_value.count("builtins.int"), 3)
|
|
412
|
-
self.assertEqual(stdout_value.count("builtins.str"), 10)
|
|
413
|
-
self.assertIn("Literal['test_server']", stdout_value)
|
|
414
|
-
self.assertIn("Literal['1']", stdout_value)
|
|
415
|
-
|
|
416
|
-
def test_base_class_complex_expr(self) -> None:
|
|
417
|
-
"""Testing for print AstTool."""
|
|
418
|
-
from jaclang.settings import settings
|
|
419
|
-
|
|
420
|
-
# settings.ast_symbol_info_detailed = True
|
|
421
|
-
captured_output = io.StringIO()
|
|
422
|
-
sys.stdout = captured_output
|
|
423
|
-
|
|
424
|
-
cli.tool(
|
|
425
|
-
"ir", ["ast", f"{self.fixture_abs_path('base_class_complex_expr.jac')}"]
|
|
426
|
-
)
|
|
427
|
-
|
|
428
|
-
sys.stdout = sys.__stdout__
|
|
429
|
-
stdout_value = captured_output.getvalue()
|
|
430
|
-
settings.ast_symbol_info_detailed = False
|
|
431
|
-
|
|
432
|
-
self.assertRegex(
|
|
433
|
-
stdout_value,
|
|
434
|
-
r"36\:9 \- 36\:13.*Name \- Kiwi \- Type\: base_class_complex_expr.Kiwi, SymbolTable\: Kiwi",
|
|
435
|
-
)
|
|
436
|
-
|
|
437
|
-
def test_import_all(self) -> None:
|
|
438
|
-
"""Testing for print AstTool."""
|
|
439
|
-
from jaclang.settings import settings
|
|
440
|
-
|
|
441
|
-
settings.ast_symbol_info_detailed = True
|
|
442
|
-
captured_output = io.StringIO()
|
|
443
|
-
sys.stdout = captured_output
|
|
444
|
-
|
|
445
|
-
cli.tool("ir", ["ast", f"{self.fixture_abs_path('import_all.jac')}"])
|
|
446
|
-
|
|
447
|
-
sys.stdout = sys.__stdout__
|
|
448
|
-
stdout_value = captured_output.getvalue()
|
|
449
|
-
settings.ast_symbol_info_detailed = False
|
|
450
|
-
|
|
451
|
-
self.assertRegex(
|
|
452
|
-
stdout_value,
|
|
453
|
-
r"6\:25 - 6\:30.*Name - floor -.*SymbolPath: math.floor",
|
|
454
|
-
)
|
|
455
|
-
self.assertRegex(
|
|
456
|
-
stdout_value,
|
|
457
|
-
r"5\:25 - 5\:27.*Name - pi -.*SymbolPath: math.pi",
|
|
458
|
-
)
|
|
459
|
-
|
|
460
|
-
def test_import_mod_abs_path(self) -> None:
|
|
461
|
-
"""Testing for print AstTool."""
|
|
462
|
-
captured_output = io.StringIO()
|
|
463
|
-
sys.stdout = captured_output
|
|
464
|
-
|
|
465
|
-
cli.tool("ir", ["ast", f"{self.fixture_abs_path('import.jac')}"])
|
|
466
|
-
|
|
467
|
-
sys.stdout = sys.__stdout__
|
|
468
|
-
stdout_value = captured_output.getvalue().replace("\\", "/")
|
|
469
|
-
self.assertRegex(
|
|
470
|
-
stdout_value,
|
|
471
|
-
r"1.*ModulePath - os - abs_path\:.*typeshed/stdlib/os/__init__.pyi",
|
|
472
|
-
)
|
|
473
|
-
self.assertRegex(
|
|
474
|
-
stdout_value,
|
|
475
|
-
r"2.*ModulePath - sys - abs_path\:.*typeshed/stdlib/sys/__init__.pyi",
|
|
476
|
-
)
|
|
477
|
-
self.assertRegex(
|
|
478
|
-
stdout_value,
|
|
479
|
-
r"3.*ModulePath - pyfunc - abs_path\:.*fixtures/pyfunc.py",
|
|
480
|
-
)
|
|
481
|
-
self.assertRegex(
|
|
482
|
-
stdout_value,
|
|
483
|
-
r"4.*ModulePath - pygame_mock - abs_path\:.*fixtures/pygame_mock/inner/__init__.py",
|
|
484
|
-
)
|
|
485
|
-
self.assertRegex(
|
|
486
|
-
stdout_value,
|
|
487
|
-
r"6.*ModulePath - math - abs_path\:.*typeshed/stdlib/math.pyi",
|
|
488
|
-
)
|
|
489
|
-
self.assertRegex(
|
|
490
|
-
stdout_value,
|
|
491
|
-
r"7.*ModulePath - argparse - abs_path\:.*typeshed/stdlib/argparse.pyi",
|
|
492
|
-
)
|
|
493
|
-
self.assertRegex(
|
|
494
|
-
stdout_value,
|
|
495
|
-
r"8.*ModulePath - pygame_mock - abs_path\:.*fixtures/pygame_mock/__init__.py",
|
|
496
|
-
)
|
|
497
|
-
self.assertRegex(
|
|
498
|
-
stdout_value,
|
|
499
|
-
r"8.*ModuleItem - color - abs_path\:.*fixtures/pygame_mock/color.py",
|
|
500
|
-
)
|
|
501
|
-
self.assertRegex(
|
|
502
|
-
stdout_value,
|
|
503
|
-
r"8.*ModuleItem - display - abs_path\:.*fixtures/pygame_mock/display.py",
|
|
504
|
-
)
|
|
505
|
-
|
|
506
|
-
def test_sub_class_symbol_table_fix_1(self) -> None:
|
|
507
|
-
"""Testing for print AstTool."""
|
|
508
|
-
from jaclang.settings import settings
|
|
509
|
-
|
|
510
|
-
settings.ast_symbol_info_detailed = True
|
|
511
|
-
captured_output = io.StringIO()
|
|
512
|
-
sys.stdout = captured_output
|
|
513
|
-
|
|
514
|
-
cli.tool("ir", ["ast", f"{self.fixture_abs_path('base_class1.jac')}"])
|
|
515
|
-
|
|
516
|
-
sys.stdout = sys.__stdout__
|
|
517
|
-
stdout_value = captured_output.getvalue()
|
|
518
|
-
settings.ast_symbol_info_detailed = False
|
|
519
|
-
|
|
520
|
-
self.assertRegex(
|
|
521
|
-
stdout_value,
|
|
522
|
-
r"10:7 - 10:12.*Name - start - Type.*SymbolPath: base_class1.B.start",
|
|
523
|
-
)
|
|
524
|
-
|
|
525
|
-
def test_sub_class_symbol_table_fix_2(self) -> None:
|
|
526
|
-
"""Testing for print AstTool."""
|
|
527
|
-
from jaclang.settings import settings
|
|
528
|
-
|
|
529
|
-
settings.ast_symbol_info_detailed = True
|
|
530
|
-
captured_output = io.StringIO()
|
|
531
|
-
sys.stdout = captured_output
|
|
532
|
-
|
|
533
|
-
cli.tool("ir", ["ast", f"{self.fixture_abs_path('base_class2.jac')}"])
|
|
534
|
-
|
|
535
|
-
sys.stdout = sys.__stdout__
|
|
536
|
-
stdout_value = captured_output.getvalue()
|
|
537
|
-
settings.ast_symbol_info_detailed = False
|
|
538
|
-
|
|
539
|
-
self.assertRegex(
|
|
540
|
-
stdout_value,
|
|
541
|
-
r"10:7 - 10:12.*Name - start - Type.*SymbolPath: base_class2.B.start",
|
|
542
|
-
)
|
|
File without changes
|
|
File without changes
|