jaclang 0.8.0__py3-none-any.whl → 0.8.2__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/__init__.py +6 -0
- jaclang/cli/cli.py +23 -50
- jaclang/compiler/codeinfo.py +0 -1
- jaclang/compiler/jac.lark +14 -22
- jaclang/compiler/larkparse/jac_parser.py +2 -2
- jaclang/compiler/parser.py +378 -531
- jaclang/compiler/passes/main/__init__.py +0 -14
- jaclang/compiler/passes/main/annex_pass.py +2 -8
- jaclang/compiler/passes/main/cfg_build_pass.py +39 -13
- jaclang/compiler/passes/main/def_impl_match_pass.py +14 -13
- jaclang/compiler/passes/main/def_use_pass.py +4 -7
- jaclang/compiler/passes/main/import_pass.py +6 -14
- jaclang/compiler/passes/main/inheritance_pass.py +2 -2
- jaclang/compiler/passes/main/pyast_gen_pass.py +428 -799
- jaclang/compiler/passes/main/pyast_load_pass.py +115 -311
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +8 -7
- jaclang/compiler/passes/main/sym_tab_build_pass.py +3 -3
- jaclang/compiler/passes/main/sym_tab_link_pass.py +6 -9
- jaclang/compiler/passes/main/tests/fixtures/symtab_link_tests/action/actions.jac +1 -5
- jaclang/compiler/passes/main/tests/fixtures/symtab_link_tests/main.jac +1 -8
- jaclang/compiler/passes/main/tests/test_cfg_build_pass.py +5 -9
- jaclang/compiler/passes/main/tests/test_decl_impl_match_pass.py +7 -8
- jaclang/compiler/passes/main/tests/test_import_pass.py +5 -18
- jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +2 -6
- jaclang/compiler/passes/main/tests/test_sub_node_pass.py +1 -3
- jaclang/compiler/passes/main/tests/test_sym_tab_link_pass.py +20 -17
- jaclang/compiler/passes/tool/doc_ir_gen_pass.py +425 -216
- jaclang/compiler/passes/tool/jac_formatter_pass.py +2 -0
- jaclang/compiler/passes/tool/tests/fixtures/archetype_frmt.jac +14 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +5 -4
- jaclang/compiler/passes/tool/tests/fixtures/import_fmt.jac +6 -0
- jaclang/compiler/passes/tool/tests/fixtures/simple_walk_fmt.jac +3 -3
- jaclang/compiler/passes/tool/tests/fixtures/tagbreak.jac +9 -0
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +18 -3
- jaclang/compiler/passes/tool/tests/test_unparse_validate.py +2 -2
- jaclang/compiler/program.py +22 -66
- jaclang/compiler/tests/fixtures/fam.jac +2 -2
- jaclang/compiler/tests/fixtures/pkg_import_lib/__init__.jac +1 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib/sub/__init__.jac +1 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib/sub/helper.jac +3 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib/tools.jac +3 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/__init__.py +5 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/sub/__init__.py +3 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/sub/helper.jac +3 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/tools.jac +3 -0
- jaclang/compiler/tests/fixtures/pkg_import_main.jac +10 -0
- jaclang/compiler/tests/fixtures/pkg_import_main_py.jac +11 -0
- jaclang/compiler/tests/test_importer.py +30 -13
- jaclang/compiler/tests/test_parser.py +1 -0
- jaclang/compiler/unitree.py +488 -320
- jaclang/langserve/__init__.jac +1 -0
- jaclang/langserve/engine.jac +503 -0
- jaclang/langserve/sem_manager.jac +309 -0
- jaclang/langserve/server.jac +201 -0
- jaclang/langserve/tests/server_test/test_lang_serve.py +139 -48
- jaclang/langserve/tests/server_test/utils.py +35 -6
- jaclang/langserve/tests/session.jac +294 -0
- jaclang/langserve/tests/test_sem_tokens.py +2 -2
- jaclang/langserve/tests/test_server.py +8 -7
- jaclang/langserve/utils.jac +51 -30
- jaclang/runtimelib/archetype.py +128 -6
- jaclang/runtimelib/builtin.py +17 -14
- jaclang/runtimelib/importer.py +51 -76
- jaclang/runtimelib/machine.py +469 -305
- jaclang/runtimelib/meta_importer.py +86 -0
- jaclang/runtimelib/tests/fixtures/graph_purger.jac +24 -26
- jaclang/runtimelib/tests/fixtures/other_root_access.jac +25 -16
- jaclang/runtimelib/tests/fixtures/traversing_save.jac +7 -5
- jaclang/runtimelib/tests/test_jaseci.py +3 -1
- jaclang/runtimelib/utils.py +3 -3
- jaclang/tests/fixtures/arch_rel_import_creation.jac +23 -23
- jaclang/tests/fixtures/async_ability.jac +43 -10
- jaclang/tests/fixtures/async_function.jac +18 -0
- jaclang/tests/fixtures/async_walker.jac +17 -12
- jaclang/tests/fixtures/backward_edge_visit.jac +31 -0
- jaclang/tests/fixtures/builtin_printgraph.jac +85 -0
- jaclang/tests/fixtures/builtin_printgraph_json.jac +21 -0
- jaclang/tests/fixtures/builtin_printgraph_mermaid.jac +16 -0
- jaclang/tests/fixtures/chandra_bugs2.jac +20 -13
- jaclang/tests/fixtures/concurrency.jac +1 -1
- jaclang/tests/fixtures/create_dynamic_archetype.jac +25 -28
- jaclang/tests/fixtures/deep/deeper/deep_outer_import.jac +7 -4
- jaclang/tests/fixtures/deep/deeper/snd_lev.jac +2 -2
- jaclang/tests/fixtures/deep/deeper/snd_lev_dup.jac +6 -0
- jaclang/tests/fixtures/deep/one_lev.jac +2 -2
- jaclang/tests/fixtures/deep/one_lev_dup.jac +4 -3
- jaclang/tests/fixtures/dynamic_archetype.jac +19 -12
- jaclang/tests/fixtures/edge_ability.jac +49 -0
- jaclang/tests/fixtures/foo.jac +14 -22
- jaclang/tests/fixtures/guess_game.jac +1 -1
- jaclang/tests/fixtures/here_usage_error.jac +21 -0
- jaclang/tests/fixtures/here_visitor_usage.jac +21 -0
- jaclang/tests/fixtures/jac_from_py.py +1 -1
- jaclang/tests/fixtures/jp_importer.jac +6 -6
- jaclang/tests/fixtures/jp_importer_auto.jac +5 -3
- jaclang/tests/fixtures/node_del.jac +30 -36
- jaclang/tests/fixtures/unicode_strings.jac +24 -0
- jaclang/tests/fixtures/visit_traversal.jac +47 -0
- jaclang/tests/fixtures/walker_update.jac +5 -7
- jaclang/tests/test_cli.py +12 -7
- jaclang/tests/test_language.py +218 -145
- jaclang/tests/test_reference.py +9 -4
- jaclang/tests/test_typecheck.py +13 -26
- jaclang/utils/helpers.py +14 -6
- jaclang/utils/lang_tools.py +9 -8
- jaclang/utils/module_resolver.py +23 -0
- jaclang/utils/tests/test_lang_tools.py +2 -1
- jaclang/utils/treeprinter.py +3 -4
- {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/METADATA +4 -3
- {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/RECORD +112 -94
- {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/WHEEL +1 -1
- jaclang/compiler/passes/main/tests/fixtures/main_err.jac +0 -6
- jaclang/compiler/passes/main/tests/fixtures/second_err.jac +0 -4
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +0 -644
- jaclang/compiler/passes/tool/tests/test_doc_ir_gen_pass.py +0 -29
- jaclang/langserve/__init__.py +0 -1
- jaclang/langserve/engine.py +0 -553
- jaclang/langserve/sem_manager.py +0 -383
- jaclang/langserve/server.py +0 -167
- jaclang/langserve/tests/session.py +0 -255
- jaclang/tests/fixtures/builtin_dotgen.jac +0 -42
- jaclang/tests/fixtures/builtin_dotgen_json.jac +0 -21
- jaclang/tests/fixtures/deep/deeper/__init__.jac +0 -1
- {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/entry_points.txt +0 -0
jaclang/tests/test_language.py
CHANGED
|
@@ -5,11 +5,12 @@ import os
|
|
|
5
5
|
import sys
|
|
6
6
|
import sysconfig
|
|
7
7
|
import tempfile
|
|
8
|
+
import subprocess
|
|
9
|
+
from pathlib import Path
|
|
8
10
|
from unittest.mock import patch
|
|
9
11
|
|
|
10
|
-
from jaclang import
|
|
12
|
+
from jaclang import JacMachine as Jac
|
|
11
13
|
from jaclang.cli import cli
|
|
12
|
-
from jaclang.compiler.passes.main import CompilerMode as CMode
|
|
13
14
|
from jaclang.compiler.program import JacProgram
|
|
14
15
|
from jaclang.utils.test import TestCase
|
|
15
16
|
|
|
@@ -19,15 +20,16 @@ class JacLanguageTests(TestCase):
|
|
|
19
20
|
|
|
20
21
|
def setUp(self) -> None:
|
|
21
22
|
"""Set up test."""
|
|
22
|
-
|
|
23
|
+
Jac.reset_machine()
|
|
24
|
+
Jac.set_base_path(self.fixture_abs_path("./"))
|
|
23
25
|
Jac.attach_program(
|
|
24
|
-
self.mach,
|
|
25
26
|
JacProgram(),
|
|
26
27
|
)
|
|
27
28
|
return super().setUp()
|
|
28
29
|
|
|
29
30
|
def tearDown(self) -> None:
|
|
30
31
|
"""Tear down test."""
|
|
32
|
+
Jac.reset_machine()
|
|
31
33
|
return super().tearDown()
|
|
32
34
|
|
|
33
35
|
def test_sub_abilities(self) -> None:
|
|
@@ -69,7 +71,6 @@ class JacLanguageTests(TestCase):
|
|
|
69
71
|
captured_output = io.StringIO()
|
|
70
72
|
sys.stdout = captured_output
|
|
71
73
|
Jac.jac_import(
|
|
72
|
-
self.mach,
|
|
73
74
|
"micro.simple_walk",
|
|
74
75
|
base_path=self.examples_abs_path(""),
|
|
75
76
|
override_name="__main__",
|
|
@@ -87,7 +88,7 @@ class JacLanguageTests(TestCase):
|
|
|
87
88
|
captured_output = io.StringIO()
|
|
88
89
|
sys.stdout = captured_output
|
|
89
90
|
Jac.jac_import(
|
|
90
|
-
|
|
91
|
+
"micro.simple_walk_by_edge", base_path=self.examples_abs_path("")
|
|
91
92
|
)
|
|
92
93
|
sys.stdout = sys.__stdout__
|
|
93
94
|
stdout_value = captured_output.getvalue()
|
|
@@ -100,7 +101,7 @@ class JacLanguageTests(TestCase):
|
|
|
100
101
|
"""Parse micro jac file."""
|
|
101
102
|
captured_output = io.StringIO()
|
|
102
103
|
sys.stdout = captured_output
|
|
103
|
-
Jac.jac_import(
|
|
104
|
+
Jac.jac_import("guess_game", base_path=self.fixture_abs_path("./"))
|
|
104
105
|
sys.stdout = sys.__stdout__
|
|
105
106
|
stdout_value = captured_output.getvalue()
|
|
106
107
|
self.assertEqual(
|
|
@@ -108,15 +109,13 @@ class JacLanguageTests(TestCase):
|
|
|
108
109
|
"Too high!\nToo low!\nToo high!\nCongratulations! You guessed correctly.\n",
|
|
109
110
|
)
|
|
110
111
|
|
|
111
|
-
def
|
|
112
|
+
def test_printgraph(self) -> None:
|
|
112
113
|
"""Test the dot gen of builtin function."""
|
|
113
114
|
import json
|
|
114
115
|
|
|
115
116
|
captured_output = io.StringIO()
|
|
116
117
|
sys.stdout = captured_output
|
|
117
|
-
Jac.jac_import(
|
|
118
|
-
self.mach, "builtin_dotgen_json", base_path=self.fixture_abs_path("./")
|
|
119
|
-
)
|
|
118
|
+
Jac.jac_import("builtin_printgraph_json", base_path=self.fixture_abs_path("./"))
|
|
120
119
|
sys.stdout = sys.__stdout__
|
|
121
120
|
stdout_value = captured_output.getvalue()
|
|
122
121
|
data = json.loads(stdout_value)
|
|
@@ -130,11 +129,23 @@ class JacLanguageTests(TestCase):
|
|
|
130
129
|
edges = data["edges"]
|
|
131
130
|
self.assertEqual(len(edges), 6)
|
|
132
131
|
|
|
132
|
+
def test_printgraph_mermaid(self) -> None:
|
|
133
|
+
"""Test the mermaid gen of builtin function."""
|
|
134
|
+
captured_output = io.StringIO()
|
|
135
|
+
sys.stdout = captured_output
|
|
136
|
+
Jac.jac_import(
|
|
137
|
+
"builtin_printgraph_mermaid",
|
|
138
|
+
base_path=self.fixture_abs_path("./"),
|
|
139
|
+
)
|
|
140
|
+
sys.stdout = sys.__stdout__
|
|
141
|
+
stdout_value = captured_output.getvalue()
|
|
142
|
+
self.assertIn("flowchart LR", stdout_value)
|
|
143
|
+
|
|
133
144
|
def test_chandra_bugs(self) -> None:
|
|
134
145
|
"""Parse micro jac file."""
|
|
135
146
|
captured_output = io.StringIO()
|
|
136
147
|
sys.stdout = captured_output
|
|
137
|
-
Jac.jac_import(
|
|
148
|
+
Jac.jac_import("chandra_bugs", base_path=self.fixture_abs_path("./"))
|
|
138
149
|
sys.stdout = sys.__stdout__
|
|
139
150
|
stdout_value = captured_output.getvalue()
|
|
140
151
|
self.assertEqual(
|
|
@@ -146,16 +157,14 @@ class JacLanguageTests(TestCase):
|
|
|
146
157
|
"""Parse micro jac file."""
|
|
147
158
|
captured_output = io.StringIO()
|
|
148
159
|
sys.stdout = captured_output
|
|
149
|
-
Jac.jac_import(
|
|
150
|
-
self.mach, "chandra_bugs2", base_path=self.fixture_abs_path("./")
|
|
151
|
-
)
|
|
160
|
+
Jac.jac_import("chandra_bugs2", base_path=self.fixture_abs_path("./"))
|
|
152
161
|
sys.stdout = sys.__stdout__
|
|
153
162
|
stdout_value = captured_output.getvalue()
|
|
154
163
|
self.assertEqual(
|
|
155
164
|
stdout_value,
|
|
156
165
|
"{'apple': None, 'pineapple': None}\n"
|
|
157
166
|
"This is a long\n"
|
|
158
|
-
"
|
|
167
|
+
" line of code.\n"
|
|
159
168
|
"{'a': 'apple', 'b': 'ball', 'c': 'cat', 'd': 'dog', 'e': 'elephant'}\n",
|
|
160
169
|
)
|
|
161
170
|
|
|
@@ -163,7 +172,7 @@ class JacLanguageTests(TestCase):
|
|
|
163
172
|
"""Parse micro jac file."""
|
|
164
173
|
captured_output = io.StringIO()
|
|
165
174
|
sys.stdout = captured_output
|
|
166
|
-
Jac.jac_import(
|
|
175
|
+
Jac.jac_import("ignore_dup", base_path=self.fixture_abs_path("./"))
|
|
167
176
|
sys.stdout = sys.__stdout__
|
|
168
177
|
stdout_value = captured_output.getvalue()
|
|
169
178
|
self.assertEqual(stdout_value.split("\n")[0].count("here"), 10)
|
|
@@ -173,16 +182,16 @@ class JacLanguageTests(TestCase):
|
|
|
173
182
|
"""Parse micro jac file."""
|
|
174
183
|
captured_output = io.StringIO()
|
|
175
184
|
sys.stdout = captured_output
|
|
176
|
-
Jac.jac_import(
|
|
177
|
-
self.mach, "hashcheck_dup", base_path=self.fixture_abs_path("./")
|
|
178
|
-
)
|
|
185
|
+
Jac.jac_import("hashcheck_dup", base_path=self.fixture_abs_path("./"))
|
|
179
186
|
sys.stdout = sys.__stdout__
|
|
180
187
|
stdout_value = captured_output.getvalue()
|
|
181
188
|
self.assertEqual(stdout_value.count("check"), 2)
|
|
182
189
|
|
|
183
190
|
def test_arith_precedence(self) -> None:
|
|
184
191
|
"""Basic precedence test."""
|
|
185
|
-
prog = JacProgram().
|
|
192
|
+
prog = JacProgram().compile(
|
|
193
|
+
use_str="with entry {print(4-5-4);}", file_path="test.jac"
|
|
194
|
+
)
|
|
186
195
|
captured_output = io.StringIO()
|
|
187
196
|
sys.stdout = captured_output
|
|
188
197
|
exec(compile(prog.gen.py_ast[0], "test.py", "exec"))
|
|
@@ -194,7 +203,7 @@ class JacLanguageTests(TestCase):
|
|
|
194
203
|
"""Test importing python."""
|
|
195
204
|
captured_output = io.StringIO()
|
|
196
205
|
sys.stdout = captured_output
|
|
197
|
-
Jac.jac_import(
|
|
206
|
+
Jac.jac_import("needs_import", base_path=self.fixture_abs_path("./"))
|
|
198
207
|
sys.stdout = sys.__stdout__
|
|
199
208
|
stdout_value = captured_output.getvalue()
|
|
200
209
|
self.assertIn("<module 'pyfunc' from", stdout_value)
|
|
@@ -204,7 +213,6 @@ class JacLanguageTests(TestCase):
|
|
|
204
213
|
captured_output = io.StringIO()
|
|
205
214
|
sys.stdout = captured_output
|
|
206
215
|
Jac.jac_import(
|
|
207
|
-
self.mach,
|
|
208
216
|
"reference.special_comprehensions",
|
|
209
217
|
base_path=self.examples_abs_path(""),
|
|
210
218
|
)
|
|
@@ -216,9 +224,7 @@ class JacLanguageTests(TestCase):
|
|
|
216
224
|
"""Test the dot gen of nodes and edges of bubblesort."""
|
|
217
225
|
captured_output = io.StringIO()
|
|
218
226
|
sys.stdout = captured_output
|
|
219
|
-
Jac.jac_import(
|
|
220
|
-
self.mach, "gendot_bubble_sort", base_path=self.fixture_abs_path("./")
|
|
221
|
-
)
|
|
227
|
+
Jac.jac_import("gendot_bubble_sort", base_path=self.fixture_abs_path("./"))
|
|
222
228
|
sys.stdout = sys.__stdout__
|
|
223
229
|
stdout_value = captured_output.getvalue()
|
|
224
230
|
self.assertIn(
|
|
@@ -230,9 +236,7 @@ class JacLanguageTests(TestCase):
|
|
|
230
236
|
"""Test assign_compr."""
|
|
231
237
|
captured_output = io.StringIO()
|
|
232
238
|
sys.stdout = captured_output
|
|
233
|
-
Jac.jac_import(
|
|
234
|
-
self.mach, "assign_compr_dup", base_path=self.fixture_abs_path("./")
|
|
235
|
-
)
|
|
239
|
+
Jac.jac_import("assign_compr_dup", base_path=self.fixture_abs_path("./"))
|
|
236
240
|
sys.stdout = sys.__stdout__
|
|
237
241
|
stdout_value = captured_output.getvalue()
|
|
238
242
|
self.assertEqual(
|
|
@@ -244,9 +248,7 @@ class JacLanguageTests(TestCase):
|
|
|
244
248
|
"""Test raw string and byte string."""
|
|
245
249
|
captured_output = io.StringIO()
|
|
246
250
|
sys.stdout = captured_output
|
|
247
|
-
Jac.jac_import(
|
|
248
|
-
self.mach, "raw_byte_string", base_path=self.fixture_abs_path("./")
|
|
249
|
-
)
|
|
251
|
+
Jac.jac_import("raw_byte_string", base_path=self.fixture_abs_path("./"))
|
|
250
252
|
sys.stdout = sys.__stdout__
|
|
251
253
|
stdout_value = captured_output.getvalue()
|
|
252
254
|
self.assertEqual(stdout_value.count(r"\\\\"), 2)
|
|
@@ -257,7 +259,6 @@ class JacLanguageTests(TestCase):
|
|
|
257
259
|
captured_output = io.StringIO()
|
|
258
260
|
sys.stdout = captured_output
|
|
259
261
|
Jac.jac_import(
|
|
260
|
-
self.mach,
|
|
261
262
|
"compiler/passes/main/tests/fixtures/fstrings",
|
|
262
263
|
base_path=self.fixture_abs_path("../../"),
|
|
263
264
|
)
|
|
@@ -273,37 +274,30 @@ class JacLanguageTests(TestCase):
|
|
|
273
274
|
captured_output = io.StringIO()
|
|
274
275
|
sys.stdout = captured_output
|
|
275
276
|
|
|
276
|
-
Jac.jac_import(
|
|
277
|
+
Jac.jac_import("deep_import", base_path=self.fixture_abs_path("./"))
|
|
277
278
|
sys.stdout = sys.__stdout__
|
|
278
279
|
stdout_value = captured_output.getvalue()
|
|
279
|
-
print(self.mach.loaded_modules.keys())
|
|
280
280
|
self.assertEqual(stdout_value.split("\n")[0], "one level deeperslHello World!")
|
|
281
281
|
|
|
282
282
|
def test_deep_imports_interp_mode(self) -> None:
|
|
283
283
|
"""Parse micro jac file."""
|
|
284
|
-
|
|
284
|
+
Jac.set_base_path(self.fixture_abs_path("./"))
|
|
285
285
|
Jac.attach_program(
|
|
286
|
-
mach,
|
|
287
286
|
JacProgram(),
|
|
288
287
|
)
|
|
289
|
-
Jac.jac_import(
|
|
290
|
-
|
|
291
|
-
)
|
|
292
|
-
print(mach.jac_program.mod.hub.keys())
|
|
293
|
-
self.assertEqual(len(mach.jac_program.mod.hub.keys()), 1)
|
|
294
|
-
mach = JacMachine(self.fixture_abs_path("./"), interp_mode=False)
|
|
288
|
+
Jac.jac_import("deep_import_interp", base_path=self.fixture_abs_path("./"))
|
|
289
|
+
self.assertEqual(len(Jac.program.mod.hub.keys()), 1)
|
|
290
|
+
Jac.set_base_path(self.fixture_abs_path("./"))
|
|
295
291
|
Jac.attach_program(
|
|
296
|
-
|
|
297
|
-
JacProgram(),
|
|
292
|
+
(prog := JacProgram()),
|
|
298
293
|
)
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
)
|
|
302
|
-
print(mach.jac_program.mod.hub.keys())
|
|
303
|
-
self.assertEqual(len(mach.jac_program.mod.hub.keys()), 5)
|
|
294
|
+
prog.build(self.fixture_abs_path("./deep_import_interp.jac"))
|
|
295
|
+
Jac.jac_import("deep_import_interp", base_path=self.fixture_abs_path("./"))
|
|
296
|
+
self.assertEqual(len(Jac.program.mod.hub.keys()), 5)
|
|
304
297
|
|
|
305
298
|
def test_deep_imports_mods(self) -> None:
|
|
306
299
|
"""Parse micro jac file."""
|
|
300
|
+
Jac.reset_machine()
|
|
307
301
|
targets = [
|
|
308
302
|
"deep",
|
|
309
303
|
"deep.deeper",
|
|
@@ -314,20 +308,19 @@ class JacLanguageTests(TestCase):
|
|
|
314
308
|
for i in targets:
|
|
315
309
|
if i in sys.modules:
|
|
316
310
|
del sys.modules[i]
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
)
|
|
320
|
-
|
|
311
|
+
captured_output = io.StringIO()
|
|
312
|
+
sys.stdout = captured_output
|
|
313
|
+
Jac.jac_import("deep_import_mods", base_path=self.fixture_abs_path("./"))
|
|
314
|
+
sys.stdout = sys.__stdout__
|
|
315
|
+
stdout_value = eval(captured_output.getvalue())
|
|
321
316
|
for i in targets:
|
|
322
|
-
self.assertIn(i,
|
|
323
|
-
self.assertEqual(len([i for i in mods if i.startswith("deep")]), 6)
|
|
317
|
+
self.assertIn(i, stdout_value)
|
|
324
318
|
|
|
325
319
|
def test_deep_outer_imports_one(self) -> None:
|
|
326
320
|
"""Parse micro jac file."""
|
|
327
321
|
captured_output = io.StringIO()
|
|
328
322
|
sys.stdout = captured_output
|
|
329
323
|
Jac.jac_import(
|
|
330
|
-
self.mach,
|
|
331
324
|
"deep.deeper.deep_outer_import",
|
|
332
325
|
base_path=self.fixture_abs_path("./"),
|
|
333
326
|
)
|
|
@@ -351,7 +344,7 @@ class JacLanguageTests(TestCase):
|
|
|
351
344
|
"""Test has lambda_goodness."""
|
|
352
345
|
captured_output = io.StringIO()
|
|
353
346
|
sys.stdout = captured_output
|
|
354
|
-
Jac.jac_import(
|
|
347
|
+
Jac.jac_import("has_goodness", base_path=self.fixture_abs_path("./"))
|
|
355
348
|
sys.stdout = sys.__stdout__
|
|
356
349
|
stdout_value = captured_output.getvalue()
|
|
357
350
|
self.assertEqual(stdout_value.split("\n")[0], "mylist: [1, 2, 3]")
|
|
@@ -361,7 +354,7 @@ class JacLanguageTests(TestCase):
|
|
|
361
354
|
"""Test conn assign on edges."""
|
|
362
355
|
captured_output = io.StringIO()
|
|
363
356
|
sys.stdout = captured_output
|
|
364
|
-
Jac.jac_import(
|
|
357
|
+
Jac.jac_import("edge_ops", base_path=self.fixture_abs_path("./"))
|
|
365
358
|
sys.stdout = sys.__stdout__
|
|
366
359
|
stdout_value = captured_output.getvalue()
|
|
367
360
|
self.assertIn("[(3, 5), (14, 1), (5, 1)]", stdout_value)
|
|
@@ -372,7 +365,7 @@ class JacLanguageTests(TestCase):
|
|
|
372
365
|
"""Test conn assign on edges."""
|
|
373
366
|
captured_output = io.StringIO()
|
|
374
367
|
sys.stdout = captured_output
|
|
375
|
-
Jac.jac_import(
|
|
368
|
+
Jac.jac_import("disconn", base_path=self.fixture_abs_path("./"))
|
|
376
369
|
sys.stdout = sys.__stdout__
|
|
377
370
|
stdout_value = captured_output.getvalue().split("\n")
|
|
378
371
|
self.assertIn("c(cc=0)", stdout_value[0])
|
|
@@ -389,7 +382,7 @@ class JacLanguageTests(TestCase):
|
|
|
389
382
|
"""Test conn assign on edges."""
|
|
390
383
|
captured_output = io.StringIO()
|
|
391
384
|
sys.stdout = captured_output
|
|
392
|
-
Jac.jac_import(
|
|
385
|
+
Jac.jac_import("simple_archs", base_path=self.fixture_abs_path("./"))
|
|
393
386
|
sys.stdout = sys.__stdout__
|
|
394
387
|
stdout_value = captured_output.getvalue()
|
|
395
388
|
self.assertEqual(stdout_value.split("\n")[0], "1 2 0")
|
|
@@ -399,7 +392,7 @@ class JacLanguageTests(TestCase):
|
|
|
399
392
|
"""Test walking through edges."""
|
|
400
393
|
captured_output = io.StringIO()
|
|
401
394
|
sys.stdout = captured_output
|
|
402
|
-
Jac.jac_import(
|
|
395
|
+
Jac.jac_import("edges_walk", base_path=self.fixture_abs_path("./"))
|
|
403
396
|
sys.stdout = sys.__stdout__
|
|
404
397
|
stdout_value = captured_output.getvalue()
|
|
405
398
|
self.assertIn("creator()\n", stdout_value)
|
|
@@ -412,7 +405,7 @@ class JacLanguageTests(TestCase):
|
|
|
412
405
|
"""Test walking through edges."""
|
|
413
406
|
captured_output = io.StringIO()
|
|
414
407
|
sys.stdout = captured_output
|
|
415
|
-
Jac.jac_import(
|
|
408
|
+
Jac.jac_import("tuplytuples", base_path=self.fixture_abs_path("./"))
|
|
416
409
|
sys.stdout = sys.__stdout__
|
|
417
410
|
stdout_value = captured_output.getvalue()
|
|
418
411
|
self.assertIn(
|
|
@@ -424,9 +417,7 @@ class JacLanguageTests(TestCase):
|
|
|
424
417
|
"""Test walking through edges."""
|
|
425
418
|
captured_output = io.StringIO()
|
|
426
419
|
sys.stdout = captured_output
|
|
427
|
-
Jac.jac_import(
|
|
428
|
-
self.mach, "deferred_field", base_path=self.fixture_abs_path("./")
|
|
429
|
-
)
|
|
420
|
+
Jac.jac_import("deferred_field", base_path=self.fixture_abs_path("./"))
|
|
430
421
|
sys.stdout = sys.__stdout__
|
|
431
422
|
stdout_value = captured_output.getvalue()
|
|
432
423
|
self.assertIn(
|
|
@@ -438,9 +429,7 @@ class JacLanguageTests(TestCase):
|
|
|
438
429
|
"""Test the dot gen of nodes and edges as a builtin."""
|
|
439
430
|
captured_output = io.StringIO()
|
|
440
431
|
sys.stdout = captured_output
|
|
441
|
-
Jac.jac_import(
|
|
442
|
-
self.mach, "builtin_dotgen", base_path=self.fixture_abs_path("./")
|
|
443
|
-
)
|
|
432
|
+
Jac.jac_import("builtin_printgraph", base_path=self.fixture_abs_path("./"))
|
|
444
433
|
sys.stdout = sys.__stdout__
|
|
445
434
|
stdout_value = captured_output.getvalue()
|
|
446
435
|
self.assertEqual(stdout_value.count("True"), 16)
|
|
@@ -449,7 +438,7 @@ class JacLanguageTests(TestCase):
|
|
|
449
438
|
"""Test walking through edges."""
|
|
450
439
|
captured_output = io.StringIO()
|
|
451
440
|
sys.stdout = captured_output
|
|
452
|
-
Jac.jac_import(
|
|
441
|
+
Jac.jac_import("with_context", base_path=self.fixture_abs_path("./"))
|
|
453
442
|
sys.stdout = sys.__stdout__
|
|
454
443
|
stdout_value = captured_output.getvalue()
|
|
455
444
|
self.assertIn("im in", stdout_value)
|
|
@@ -464,9 +453,7 @@ class JacLanguageTests(TestCase):
|
|
|
464
453
|
"""Parse micro jac file."""
|
|
465
454
|
captured_output = io.StringIO()
|
|
466
455
|
sys.stdout = captured_output
|
|
467
|
-
Jac.jac_import(
|
|
468
|
-
self.mach, "micro.typed_filter_compr", base_path=self.examples_abs_path("")
|
|
469
|
-
)
|
|
456
|
+
Jac.jac_import("micro.typed_filter_compr", base_path=self.examples_abs_path(""))
|
|
470
457
|
sys.stdout = sys.__stdout__
|
|
471
458
|
stdout_value = captured_output.getvalue()
|
|
472
459
|
self.assertIn(
|
|
@@ -480,9 +467,7 @@ class JacLanguageTests(TestCase):
|
|
|
480
467
|
"""Test walking through edges and nodes."""
|
|
481
468
|
captured_output = io.StringIO()
|
|
482
469
|
sys.stdout = captured_output
|
|
483
|
-
Jac.jac_import(
|
|
484
|
-
self.mach, "edge_node_walk", base_path=self.fixture_abs_path("./")
|
|
485
|
-
)
|
|
470
|
+
Jac.jac_import("edge_node_walk", base_path=self.fixture_abs_path("./"))
|
|
486
471
|
sys.stdout = sys.__stdout__
|
|
487
472
|
stdout_value = captured_output.getvalue()
|
|
488
473
|
self.assertIn("creator()\n", stdout_value)
|
|
@@ -501,9 +486,7 @@ class JacLanguageTests(TestCase):
|
|
|
501
486
|
"""Test Enum as member stmt."""
|
|
502
487
|
captured_output = io.StringIO()
|
|
503
488
|
sys.stdout = captured_output
|
|
504
|
-
Jac.jac_import(
|
|
505
|
-
self.mach, "enum_inside_archtype", base_path=self.fixture_abs_path("./")
|
|
506
|
-
)
|
|
489
|
+
Jac.jac_import("enum_inside_archtype", base_path=self.fixture_abs_path("./"))
|
|
507
490
|
sys.stdout = sys.__stdout__
|
|
508
491
|
stdout_value = captured_output.getvalue()
|
|
509
492
|
self.assertIn("2 Accessing privileged Data", stdout_value)
|
|
@@ -524,7 +507,6 @@ class JacLanguageTests(TestCase):
|
|
|
524
507
|
),
|
|
525
508
|
prog=JacProgram(),
|
|
526
509
|
).ir_out.unparse()
|
|
527
|
-
print(output)
|
|
528
510
|
self.assertIn("def greet2(**kwargs: Any)", output)
|
|
529
511
|
self.assertEqual(output.count("with entry {"), 14)
|
|
530
512
|
self.assertIn("assert (x == 5) , 'x should be equal to 5' ;", output)
|
|
@@ -553,8 +535,10 @@ class JacLanguageTests(TestCase):
|
|
|
553
535
|
).ir_out.unparse()
|
|
554
536
|
self.assertIn("class X {\n with entry {\n a_b = 67;", output)
|
|
555
537
|
self.assertIn("br = b'Hello\\\\\\\\nWorld'", output)
|
|
556
|
-
self.assertIn(
|
|
557
|
-
|
|
538
|
+
self.assertIn(
|
|
539
|
+
"class Circle {\n def init(self: Circle, radius: float", output
|
|
540
|
+
)
|
|
541
|
+
self.assertIn("<>node = 90;\n print(<>node);\n", output)
|
|
558
542
|
|
|
559
543
|
def test_pyfunc_3(self) -> None:
|
|
560
544
|
"""Test py ast to Jac ast conversion."""
|
|
@@ -574,7 +558,7 @@ class JacLanguageTests(TestCase):
|
|
|
574
558
|
).ir_out.unparse()
|
|
575
559
|
self.assertIn("if (0 <= x <= 5) {", output)
|
|
576
560
|
self.assertIn(" case _:\n", output)
|
|
577
|
-
self.assertIn(" case Point
|
|
561
|
+
self.assertIn(" case Point(x = int(a), y = 0):\n", output)
|
|
578
562
|
self.assertIn("class Sample {\n def init", output)
|
|
579
563
|
|
|
580
564
|
def test_py2jac(self) -> None:
|
|
@@ -593,16 +577,16 @@ class JacLanguageTests(TestCase):
|
|
|
593
577
|
),
|
|
594
578
|
prog=None,
|
|
595
579
|
).ir_out.unparse()
|
|
596
|
-
self.assertIn("match Container(inner=Inner(x=a, y=b)) {
|
|
597
|
-
self.assertIn("case Container
|
|
598
|
-
self.assertIn("case Container
|
|
580
|
+
self.assertIn("match Container(inner=Inner(x=a, y=b)) {\n", output)
|
|
581
|
+
self.assertIn("case Container(inner = Inner(x = a, y = 0)):\n", output)
|
|
582
|
+
self.assertIn("case Container(inner = Inner(x = a, y = b)):\n", output)
|
|
599
583
|
self.assertIn("case _:\n", output)
|
|
600
584
|
|
|
601
585
|
def test_refs_target(self) -> None:
|
|
602
586
|
"""Test py ast to Jac ast conversion output."""
|
|
603
587
|
captured_output = io.StringIO()
|
|
604
588
|
sys.stdout = captured_output
|
|
605
|
-
Jac.jac_import(
|
|
589
|
+
Jac.jac_import("refs_target", base_path=self.fixture_abs_path("./"))
|
|
606
590
|
sys.stdout = sys.__stdout__
|
|
607
591
|
stdout_value = captured_output.getvalue()
|
|
608
592
|
self.assertIn("[c(val=0), c(val=1), c(val=2)]", stdout_value)
|
|
@@ -610,14 +594,14 @@ class JacLanguageTests(TestCase):
|
|
|
610
594
|
|
|
611
595
|
def test_py_kw_as_name_disallowed(self) -> None:
|
|
612
596
|
"""Basic precedence test."""
|
|
613
|
-
(prog := JacProgram()).
|
|
614
|
-
"with entry {print.is.not.True(4-5-4);}", "test.jac"
|
|
597
|
+
(prog := JacProgram()).compile(
|
|
598
|
+
use_str="with entry {print.is.not.True(4-5-4);}", file_path="test.jac"
|
|
615
599
|
)
|
|
616
600
|
self.assertIn("Python keyword is used as name", str(prog.errors_had[0].msg))
|
|
617
601
|
|
|
618
602
|
def test_double_format_issue(self) -> None:
|
|
619
603
|
"""Basic precedence test."""
|
|
620
|
-
prog = JacProgram().
|
|
604
|
+
prog = JacProgram().compile("with entry {print(hello);}", "test.jac")
|
|
621
605
|
prog.unparse()
|
|
622
606
|
before = prog.format()
|
|
623
607
|
prog.format()
|
|
@@ -629,9 +613,7 @@ class JacLanguageTests(TestCase):
|
|
|
629
613
|
"""Test py ast to Jac ast conversion output."""
|
|
630
614
|
captured_output = io.StringIO()
|
|
631
615
|
sys.stdout = captured_output
|
|
632
|
-
Jac.jac_import(
|
|
633
|
-
self.mach, "inherit_check", base_path=self.fixture_abs_path("./")
|
|
634
|
-
)
|
|
616
|
+
Jac.jac_import("inherit_check", base_path=self.fixture_abs_path("./"))
|
|
635
617
|
sys.stdout = sys.__stdout__
|
|
636
618
|
stdout_value = captured_output.getvalue()
|
|
637
619
|
self.assertEqual("I am in b\nI am in b\nwww is also in b\n", stdout_value)
|
|
@@ -640,7 +622,7 @@ class JacLanguageTests(TestCase):
|
|
|
640
622
|
"""Test tuple unpack."""
|
|
641
623
|
captured_output = io.StringIO()
|
|
642
624
|
sys.stdout = captured_output
|
|
643
|
-
Jac.jac_import(
|
|
625
|
+
Jac.jac_import("tupleunpack", base_path=self.fixture_abs_path("./"))
|
|
644
626
|
sys.stdout = sys.__stdout__
|
|
645
627
|
stdout_value = captured_output.getvalue().split("\n")
|
|
646
628
|
self.assertIn("1", stdout_value[0])
|
|
@@ -650,9 +632,7 @@ class JacLanguageTests(TestCase):
|
|
|
650
632
|
"""Test trailing comma."""
|
|
651
633
|
captured_output = io.StringIO()
|
|
652
634
|
sys.stdout = captured_output
|
|
653
|
-
Jac.jac_import(
|
|
654
|
-
self.mach, "trailing_comma", base_path=self.fixture_abs_path("./")
|
|
655
|
-
)
|
|
635
|
+
Jac.jac_import("trailing_comma", base_path=self.fixture_abs_path("./"))
|
|
656
636
|
sys.stdout = sys.__stdout__
|
|
657
637
|
stdout_value = captured_output.getvalue()
|
|
658
638
|
self.assertIn("Code compiled and ran successfully!", stdout_value)
|
|
@@ -661,7 +641,7 @@ class JacLanguageTests(TestCase):
|
|
|
661
641
|
"""Test try finally."""
|
|
662
642
|
captured_output = io.StringIO()
|
|
663
643
|
sys.stdout = captured_output
|
|
664
|
-
Jac.jac_import(
|
|
644
|
+
Jac.jac_import("try_finally", base_path=self.fixture_abs_path("./"))
|
|
665
645
|
sys.stdout = sys.__stdout__
|
|
666
646
|
stdout_value = captured_output.getvalue().split("\n")
|
|
667
647
|
self.assertIn("try block", stdout_value[0])
|
|
@@ -674,9 +654,7 @@ class JacLanguageTests(TestCase):
|
|
|
674
654
|
"""Test arithmetic bug."""
|
|
675
655
|
captured_output = io.StringIO()
|
|
676
656
|
sys.stdout = captured_output
|
|
677
|
-
Jac.jac_import(
|
|
678
|
-
self.mach, "arithmetic_bug", base_path=self.fixture_abs_path("./")
|
|
679
|
-
)
|
|
657
|
+
Jac.jac_import("arithmetic_bug", base_path=self.fixture_abs_path("./"))
|
|
680
658
|
sys.stdout = sys.__stdout__
|
|
681
659
|
stdout_value = captured_output.getvalue().split("\n")
|
|
682
660
|
self.assertEqual("0.0625", stdout_value[0])
|
|
@@ -689,7 +667,7 @@ class JacLanguageTests(TestCase):
|
|
|
689
667
|
"""Test lambda expr."""
|
|
690
668
|
captured_output = io.StringIO()
|
|
691
669
|
sys.stdout = captured_output
|
|
692
|
-
Jac.jac_import(
|
|
670
|
+
Jac.jac_import("lambda", base_path=self.fixture_abs_path("./"))
|
|
693
671
|
sys.stdout = sys.__stdout__
|
|
694
672
|
stdout_value = captured_output.getvalue().split("\n")
|
|
695
673
|
self.assertEqual("9", stdout_value[0])
|
|
@@ -699,9 +677,7 @@ class JacLanguageTests(TestCase):
|
|
|
699
677
|
"""Test py ast to Jac ast conversion output."""
|
|
700
678
|
captured_output = io.StringIO()
|
|
701
679
|
sys.stdout = captured_output
|
|
702
|
-
Jac.jac_import(
|
|
703
|
-
self.mach, "walker_override", base_path=self.fixture_abs_path("./")
|
|
704
|
-
)
|
|
680
|
+
Jac.jac_import("walker_override", base_path=self.fixture_abs_path("./"))
|
|
705
681
|
sys.stdout = sys.__stdout__
|
|
706
682
|
stdout_value = captured_output.getvalue()
|
|
707
683
|
self.assertEqual("baz\nbar\n", stdout_value)
|
|
@@ -710,7 +686,7 @@ class JacLanguageTests(TestCase):
|
|
|
710
686
|
"""Test py ast to Jac ast conversion output."""
|
|
711
687
|
captured_output = io.StringIO()
|
|
712
688
|
sys.stdout = captured_output
|
|
713
|
-
Jac.jac_import(
|
|
689
|
+
Jac.jac_import("nosigself", base_path=self.fixture_abs_path("./"))
|
|
714
690
|
sys.stdout = sys.__stdout__
|
|
715
691
|
stdout_value = captured_output.getvalue()
|
|
716
692
|
self.assertEqual(stdout_value.count("5"), 2)
|
|
@@ -719,9 +695,7 @@ class JacLanguageTests(TestCase):
|
|
|
719
695
|
"""Test py ast to Jac ast conversion output."""
|
|
720
696
|
captured_output = io.StringIO()
|
|
721
697
|
sys.stdout = captured_output
|
|
722
|
-
Jac.jac_import(
|
|
723
|
-
self.mach, "hash_init_check", base_path=self.fixture_abs_path("./")
|
|
724
|
-
)
|
|
698
|
+
Jac.jac_import("hash_init_check", base_path=self.fixture_abs_path("./"))
|
|
725
699
|
sys.stdout = sys.__stdout__
|
|
726
700
|
stdout_value = captured_output.getvalue()
|
|
727
701
|
self.assertIn("Test Passed", stdout_value)
|
|
@@ -751,9 +725,7 @@ class JacLanguageTests(TestCase):
|
|
|
751
725
|
"""Test importing python."""
|
|
752
726
|
captured_output = io.StringIO()
|
|
753
727
|
sys.stdout = captured_output
|
|
754
|
-
Jac.jac_import(
|
|
755
|
-
self.mach, "edgetypeissue", base_path=self.fixture_abs_path("./")
|
|
756
|
-
)
|
|
728
|
+
Jac.jac_import("edgetypeissue", base_path=self.fixture_abs_path("./"))
|
|
757
729
|
sys.stdout = sys.__stdout__
|
|
758
730
|
stdout_value = captured_output.getvalue()
|
|
759
731
|
self.assertIn("[x()]", stdout_value)
|
|
@@ -762,9 +734,7 @@ class JacLanguageTests(TestCase):
|
|
|
762
734
|
"""Test importing python."""
|
|
763
735
|
captured_output = io.StringIO()
|
|
764
736
|
sys.stdout = captured_output
|
|
765
|
-
Jac.jac_import(
|
|
766
|
-
self.mach, "blankwithentry", base_path=self.fixture_abs_path("./")
|
|
767
|
-
)
|
|
737
|
+
Jac.jac_import("blankwithentry", base_path=self.fixture_abs_path("./"))
|
|
768
738
|
sys.stdout = sys.__stdout__
|
|
769
739
|
stdout_value = captured_output.getvalue()
|
|
770
740
|
self.assertIn("i work", stdout_value)
|
|
@@ -773,7 +743,7 @@ class JacLanguageTests(TestCase):
|
|
|
773
743
|
"""Test importing python."""
|
|
774
744
|
captured_output = io.StringIO()
|
|
775
745
|
sys.stdout = captured_output
|
|
776
|
-
Jac.jac_import(
|
|
746
|
+
Jac.jac_import("dblhello", base_path=self.fixture_abs_path("./"))
|
|
777
747
|
sys.stdout = sys.__stdout__
|
|
778
748
|
stdout_value = captured_output.getvalue()
|
|
779
749
|
self.assertEqual(stdout_value.count("Hello World!"), 1)
|
|
@@ -783,7 +753,7 @@ class JacLanguageTests(TestCase):
|
|
|
783
753
|
"""Test class method output."""
|
|
784
754
|
captured_output = io.StringIO()
|
|
785
755
|
sys.stdout = captured_output
|
|
786
|
-
Jac.jac_import(
|
|
756
|
+
Jac.jac_import("cls_method", base_path=self.fixture_abs_path("./"))
|
|
787
757
|
sys.stdout = sys.__stdout__
|
|
788
758
|
stdout_value = captured_output.getvalue().split("\n")
|
|
789
759
|
self.assertEqual("MyClass", stdout_value[0])
|
|
@@ -792,10 +762,14 @@ class JacLanguageTests(TestCase):
|
|
|
792
762
|
|
|
793
763
|
def test_list_methods(self) -> None:
|
|
794
764
|
"""Test list_modules, list_walkers, list_nodes, and list_edges."""
|
|
765
|
+
Jac.reset_machine()
|
|
766
|
+
Jac.set_base_path(self.fixture_abs_path("."))
|
|
767
|
+
sys.modules.pop("foo", None)
|
|
768
|
+
sys.modules.pop("bar", None)
|
|
795
769
|
captured_output = io.StringIO()
|
|
796
770
|
sys.stdout = captured_output
|
|
797
771
|
|
|
798
|
-
Jac.jac_import(
|
|
772
|
+
Jac.jac_import("foo", base_path=self.fixture_abs_path("."))
|
|
799
773
|
|
|
800
774
|
sys.stdout = sys.__stdout__
|
|
801
775
|
stdout_value = captured_output.getvalue()
|
|
@@ -819,6 +793,9 @@ class JacLanguageTests(TestCase):
|
|
|
819
793
|
|
|
820
794
|
def test_walker_dynamic_update(self) -> None:
|
|
821
795
|
"""Test dynamic update of a walker during runtime."""
|
|
796
|
+
Jac.reset_machine()
|
|
797
|
+
Jac.set_base_path(self.fixture_abs_path("."))
|
|
798
|
+
sys.modules.pop("bar", None)
|
|
822
799
|
session = self.fixture_abs_path("bar_walk.session")
|
|
823
800
|
bar_file_path = self.fixture_abs_path("bar.jac")
|
|
824
801
|
update_file_path = self.fixture_abs_path("walker_update.jac")
|
|
@@ -832,6 +809,7 @@ class JacLanguageTests(TestCase):
|
|
|
832
809
|
)
|
|
833
810
|
sys.stdout = sys.__stdout__
|
|
834
811
|
stdout_value = captured_output.getvalue()
|
|
812
|
+
os.remove(session) if os.path.exists(session) else None
|
|
835
813
|
expected_output = "Created 5 items."
|
|
836
814
|
self.assertIn(expected_output, stdout_value.split("\n"))
|
|
837
815
|
# Define the new behavior to be added
|
|
@@ -961,9 +939,7 @@ class JacLanguageTests(TestCase):
|
|
|
961
939
|
"""Test match case with multiple expressions."""
|
|
962
940
|
captured_output = io.StringIO()
|
|
963
941
|
sys.stdout = captured_output
|
|
964
|
-
Jac.jac_import(
|
|
965
|
-
self.mach, "match_multi_ex", base_path=self.fixture_abs_path("./")
|
|
966
|
-
)
|
|
942
|
+
Jac.jac_import("match_multi_ex", base_path=self.fixture_abs_path("./"))
|
|
967
943
|
sys.stdout = sys.__stdout__
|
|
968
944
|
stdout_value = captured_output.getvalue().split("\n")
|
|
969
945
|
self.assertEqual("Ten", stdout_value[0])
|
|
@@ -973,7 +949,7 @@ class JacLanguageTests(TestCase):
|
|
|
973
949
|
"""Test entry and exit behavior of walker."""
|
|
974
950
|
captured_output = io.StringIO()
|
|
975
951
|
sys.stdout = captured_output
|
|
976
|
-
Jac.jac_import(
|
|
952
|
+
Jac.jac_import("entry_exit", base_path=self.fixture_abs_path("./"))
|
|
977
953
|
sys.stdout = sys.__stdout__
|
|
978
954
|
stdout_value = captured_output.getvalue().split("\n")
|
|
979
955
|
self.assertIn("Entering at the beginning of walker: Root()", stdout_value[0])
|
|
@@ -986,7 +962,7 @@ class JacLanguageTests(TestCase):
|
|
|
986
962
|
"""Test entry and exit behavior of walker."""
|
|
987
963
|
captured_output = io.StringIO()
|
|
988
964
|
sys.stdout = captured_output
|
|
989
|
-
Jac.jac_import(
|
|
965
|
+
Jac.jac_import("visit_order", base_path=self.fixture_abs_path("./"))
|
|
990
966
|
sys.stdout = sys.__stdout__
|
|
991
967
|
stdout_value = captured_output.getvalue()
|
|
992
968
|
self.assertEqual("[MyNode(Name='End'), MyNode(Name='Middle')]\n", stdout_value)
|
|
@@ -995,9 +971,7 @@ class JacLanguageTests(TestCase):
|
|
|
995
971
|
"""Test supporting multiple global variable in a statement."""
|
|
996
972
|
captured_output = io.StringIO()
|
|
997
973
|
sys.stdout = captured_output
|
|
998
|
-
Jac.jac_import(
|
|
999
|
-
self.mach, "glob_multivar_statement", base_path=self.fixture_abs_path("./")
|
|
1000
|
-
)
|
|
974
|
+
Jac.jac_import("glob_multivar_statement", base_path=self.fixture_abs_path("./"))
|
|
1001
975
|
sys.stdout = sys.__stdout__
|
|
1002
976
|
stdout_value = captured_output.getvalue().split("\n")
|
|
1003
977
|
self.assertIn("Hello World !", stdout_value[0])
|
|
@@ -1007,9 +981,7 @@ class JacLanguageTests(TestCase):
|
|
|
1007
981
|
"""Test archetype definition bug."""
|
|
1008
982
|
captured_output = io.StringIO()
|
|
1009
983
|
sys.stdout = captured_output
|
|
1010
|
-
Jac.jac_import(
|
|
1011
|
-
self.mach, "archetype_def_bug", base_path=self.fixture_abs_path("./")
|
|
1012
|
-
)
|
|
984
|
+
Jac.jac_import("archetype_def_bug", base_path=self.fixture_abs_path("./"))
|
|
1013
985
|
sys.stdout = sys.__stdout__
|
|
1014
986
|
stdout_value = captured_output.getvalue().split("\n")
|
|
1015
987
|
self.assertIn("MyWalker", stdout_value[0])
|
|
@@ -1019,9 +991,7 @@ class JacLanguageTests(TestCase):
|
|
|
1019
991
|
"""Test conn assign on edges."""
|
|
1020
992
|
captured_output = io.StringIO()
|
|
1021
993
|
sys.stdout = captured_output
|
|
1022
|
-
Jac.jac_import(
|
|
1023
|
-
self.mach, "visit_sequence", base_path=self.fixture_abs_path("./")
|
|
1024
|
-
)
|
|
994
|
+
Jac.jac_import("visit_sequence", base_path=self.fixture_abs_path("./"))
|
|
1025
995
|
sys.stdout = sys.__stdout__
|
|
1026
996
|
self.assertEqual(
|
|
1027
997
|
"walker entry\nwalker enter to root\n"
|
|
@@ -1036,9 +1006,7 @@ class JacLanguageTests(TestCase):
|
|
|
1036
1006
|
"""Test connect traverse syntax."""
|
|
1037
1007
|
captured_output = io.StringIO()
|
|
1038
1008
|
sys.stdout = captured_output
|
|
1039
|
-
Jac.jac_import(
|
|
1040
|
-
self.mach, "connect_traverse_syntax", base_path=self.fixture_abs_path("./")
|
|
1041
|
-
)
|
|
1009
|
+
Jac.jac_import("connect_traverse_syntax", base_path=self.fixture_abs_path("./"))
|
|
1042
1010
|
sys.stdout = sys.__stdout__
|
|
1043
1011
|
stdout_value = captured_output.getvalue().split("\n")
|
|
1044
1012
|
self.assertIn("A(val=5), A(val=10)", stdout_value[0])
|
|
@@ -1054,7 +1022,7 @@ class JacLanguageTests(TestCase):
|
|
|
1054
1022
|
"""Test complex nested impls."""
|
|
1055
1023
|
captured_output = io.StringIO()
|
|
1056
1024
|
sys.stdout = captured_output
|
|
1057
|
-
Jac.jac_import(
|
|
1025
|
+
Jac.jac_import("node_del", base_path=self.fixture_abs_path("./"))
|
|
1058
1026
|
sys.stdout = sys.__stdout__
|
|
1059
1027
|
stdout_value = captured_output.getvalue().split("\n")
|
|
1060
1028
|
self.assertIn("0 : [2, 3, 4, 5, 6, 7, 8, 9, 10]", stdout_value[0])
|
|
@@ -1094,7 +1062,7 @@ class JacLanguageTests(TestCase):
|
|
|
1094
1062
|
sys.stdout = captured_output
|
|
1095
1063
|
original_cwd = os.getcwd()
|
|
1096
1064
|
try:
|
|
1097
|
-
Jac.jac_import(
|
|
1065
|
+
Jac.jac_import("importer_site", base_path=tmpdir)
|
|
1098
1066
|
finally:
|
|
1099
1067
|
os.chdir(original_cwd)
|
|
1100
1068
|
sys.stdout = sys.__stdout__
|
|
@@ -1183,19 +1151,18 @@ class JacLanguageTests(TestCase):
|
|
|
1183
1151
|
"""Test async walker."""
|
|
1184
1152
|
captured_output = io.StringIO()
|
|
1185
1153
|
sys.stdout = captured_output
|
|
1186
|
-
Jac.jac_import(
|
|
1154
|
+
Jac.jac_import("async_walker", base_path=self.fixture_abs_path("./"))
|
|
1187
1155
|
sys.stdout = sys.__stdout__
|
|
1188
1156
|
stdout_value = captured_output.getvalue().split("\n")
|
|
1189
|
-
self.
|
|
1190
|
-
self.assertIn("
|
|
1157
|
+
self.assertIn("Let's start the task", stdout_value[0])
|
|
1158
|
+
self.assertIn("It is Coroutine task True", stdout_value[1])
|
|
1159
|
+
self.assertIn("Coroutine task is completed", stdout_value[6])
|
|
1191
1160
|
|
|
1192
|
-
def
|
|
1161
|
+
def test_async_function(self) -> None:
|
|
1193
1162
|
"""Test async ability."""
|
|
1194
1163
|
captured_output = io.StringIO()
|
|
1195
1164
|
sys.stdout = captured_output
|
|
1196
|
-
Jac.jac_import(
|
|
1197
|
-
self.mach, "async_ability", base_path=self.fixture_abs_path("./")
|
|
1198
|
-
)
|
|
1165
|
+
Jac.jac_import("async_function", base_path=self.fixture_abs_path("./"))
|
|
1199
1166
|
sys.stdout = sys.__stdout__
|
|
1200
1167
|
stdout_value = captured_output.getvalue().split("\n")
|
|
1201
1168
|
self.assertIn("Hello", stdout_value[0])
|
|
@@ -1206,7 +1173,7 @@ class JacLanguageTests(TestCase):
|
|
|
1206
1173
|
"""Test concurrency in jaclang."""
|
|
1207
1174
|
captured_output = io.StringIO()
|
|
1208
1175
|
sys.stdout = captured_output
|
|
1209
|
-
Jac.jac_import(
|
|
1176
|
+
Jac.jac_import("concurrency", base_path=self.fixture_abs_path("./"))
|
|
1210
1177
|
sys.stdout = sys.__stdout__
|
|
1211
1178
|
stdout_value = captured_output.getvalue().split("\n")
|
|
1212
1179
|
self.assertIn("Started", stdout_value[0])
|
|
@@ -1267,3 +1234,109 @@ class JacLanguageTests(TestCase):
|
|
|
1267
1234
|
self.assertIn("(tok[ 0 ] > change_end_line)", output)
|
|
1268
1235
|
self.assertIn("(tok[ 0 ] == change_end_line)", output)
|
|
1269
1236
|
self.assertIn("(tok[ 1 ] > change_end_char)", output)
|
|
1237
|
+
|
|
1238
|
+
def test_here_visitor_usage(self) -> None:
|
|
1239
|
+
"""Test visitor, here keyword usage in jaclang."""
|
|
1240
|
+
captured_output = io.StringIO()
|
|
1241
|
+
sys.stdout = captured_output
|
|
1242
|
+
Jac.jac_import("here_visitor_usage", base_path=self.fixture_abs_path("./"))
|
|
1243
|
+
sys.stdout = sys.__stdout__
|
|
1244
|
+
stdout_value = captured_output.getvalue().split("\n")
|
|
1245
|
+
self.assertIn("Here value is 10", stdout_value[0])
|
|
1246
|
+
self.assertIn("Visitor name is Walker 1", stdout_value[1])
|
|
1247
|
+
|
|
1248
|
+
def test_here_visitor_error(self) -> None:
|
|
1249
|
+
"""Test visitor, here keyword usage in jaclang."""
|
|
1250
|
+
captured_output = io.StringIO()
|
|
1251
|
+
sys.stdout = captured_output
|
|
1252
|
+
sys.stderr = captured_output
|
|
1253
|
+
cli.run(self.fixture_abs_path("here_usage_error.jac"))
|
|
1254
|
+
sys.stdout = sys.__stdout__
|
|
1255
|
+
sys.stderr = sys.__stderr__
|
|
1256
|
+
stdout_value = captured_output.getvalue()
|
|
1257
|
+
self.assertIn("'here' is not defined", stdout_value)
|
|
1258
|
+
|
|
1259
|
+
def test_edge_ability(self) -> None:
|
|
1260
|
+
"""Test visitor, here keyword usage in jaclang."""
|
|
1261
|
+
captured_output = io.StringIO()
|
|
1262
|
+
sys.stdout = captured_output
|
|
1263
|
+
cli.run(self.fixture_abs_path("edge_ability.jac"))
|
|
1264
|
+
sys.stdout = sys.__stdout__
|
|
1265
|
+
stdout_value = captured_output.getvalue().split("\n")
|
|
1266
|
+
self.assertIn("MyEdge from walker MyEdge(path=1)", stdout_value[0])
|
|
1267
|
+
self.assertIn("MyWalker from edge MyWalker()", stdout_value[1])
|
|
1268
|
+
self.assertIn("MyWalker from node MyWalker()", stdout_value[6])
|
|
1269
|
+
self.assertIn("MyEdge from walker MyEdge(path=2)", stdout_value[16])
|
|
1270
|
+
|
|
1271
|
+
def test_backward_edge_visit(self) -> None:
|
|
1272
|
+
"""Test backward edge visit in jaclang."""
|
|
1273
|
+
captured_output = io.StringIO()
|
|
1274
|
+
sys.stdout = captured_output
|
|
1275
|
+
cli.run(self.fixture_abs_path("backward_edge_visit.jac"))
|
|
1276
|
+
sys.stdout = sys.__stdout__
|
|
1277
|
+
stdout_value = captured_output.getvalue().split("\n")
|
|
1278
|
+
self.assertIn("MyWalker() from node MyNode(val=0)", stdout_value[0])
|
|
1279
|
+
self.assertIn("MyWalker() from edge MyEdge(path=0)", stdout_value[1])
|
|
1280
|
+
self.assertIn("MyWalker() from edge MyEdge(path=3)", stdout_value[6])
|
|
1281
|
+
self.assertIn("MyWalker() from node MyNode(val=40)", stdout_value[9])
|
|
1282
|
+
|
|
1283
|
+
def test_visit_traversal(self) -> None:
|
|
1284
|
+
"""Test visit traversal semantic in jaclang."""
|
|
1285
|
+
captured_output = io.StringIO()
|
|
1286
|
+
sys.stdout = captured_output
|
|
1287
|
+
cli.run(self.fixture_abs_path("visit_traversal.jac"))
|
|
1288
|
+
sys.stdout = sys.__stdout__
|
|
1289
|
+
stdout_value = captured_output.getvalue().split("\n")
|
|
1290
|
+
self.assertIn("MyWalker() from node MyNode(val=0)", stdout_value[0])
|
|
1291
|
+
self.assertIn("MyWalker() from node MyNode(val=20)", stdout_value[2])
|
|
1292
|
+
self.assertIn("MyWalker() from node MyNode(val=60)", stdout_value[4])
|
|
1293
|
+
self.assertIn("MyWalker() from node MyNode(val=40)", stdout_value[6])
|
|
1294
|
+
self.assertIn("MyWalker() from node MyNode(val=90)", stdout_value[7])
|
|
1295
|
+
self.assertIn("MyWalker() from node MyNode(val=70)", stdout_value[9])
|
|
1296
|
+
|
|
1297
|
+
def test_async_ability(self) -> None:
|
|
1298
|
+
"""Test async ability."""
|
|
1299
|
+
captured_output = io.StringIO()
|
|
1300
|
+
sys.stdout = captured_output
|
|
1301
|
+
Jac.jac_import("async_ability", base_path=self.fixture_abs_path("./"))
|
|
1302
|
+
sys.stdout = sys.__stdout__
|
|
1303
|
+
stdout_value = captured_output.getvalue().split("\n")
|
|
1304
|
+
self.assertIn("Let's start the task", stdout_value[0])
|
|
1305
|
+
self.assertIn("It is Coroutine task True", stdout_value[1])
|
|
1306
|
+
self.assertIn("I am here man MyNode(val=5)", stdout_value[2])
|
|
1307
|
+
self.assertIn("Async function", stdout_value[3])
|
|
1308
|
+
self.assertIn("foo3", stdout_value[4])
|
|
1309
|
+
self.assertIn("foo1", stdout_value[5])
|
|
1310
|
+
self.assertIn("foo2", stdout_value[6])
|
|
1311
|
+
self.assertIn("Coroutine task is completed", stdout_value[17])
|
|
1312
|
+
|
|
1313
|
+
def test_unicode_string_literals(self) -> None:
|
|
1314
|
+
"""Test unicode characters in string literals are preserved correctly."""
|
|
1315
|
+
captured_output = io.StringIO()
|
|
1316
|
+
sys.stdout = captured_output
|
|
1317
|
+
Jac.jac_import("unicode_strings", base_path=self.fixture_abs_path("./"))
|
|
1318
|
+
sys.stdout = sys.__stdout__
|
|
1319
|
+
stdout_value = captured_output.getvalue().split("\n")
|
|
1320
|
+
self.assertIn("1. ✓ 1st (due: True)", stdout_value[0])
|
|
1321
|
+
self.assertIn("🌟 Star", stdout_value[2])
|
|
1322
|
+
self.assertIn("Multi-line with ✓ unicode and ○ symbols", stdout_value[3])
|
|
1323
|
+
self.assertIn("Raw string with ✓ and ○", stdout_value[4])
|
|
1324
|
+
self.assertIn("Tab ✓", stdout_value[5])
|
|
1325
|
+
self.assertIn("Newline ○", stdout_value[6])
|
|
1326
|
+
|
|
1327
|
+
def test_sitecustomize_meta_importer(self) -> None:
|
|
1328
|
+
"""Verify Jac modules importable without importing jaclang."""
|
|
1329
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
1330
|
+
Path(tmpdir, "mymod.jac").write_text('with entry {print("via meta");}')
|
|
1331
|
+
env = os.environ.copy()
|
|
1332
|
+
project_root = Path(__file__).resolve().parents[2]
|
|
1333
|
+
env["PYTHONPATH"] = os.pathsep.join([str(project_root), tmpdir])
|
|
1334
|
+
proc = subprocess.run(
|
|
1335
|
+
[sys.executable, "-c", "import mymod"],
|
|
1336
|
+
capture_output=True,
|
|
1337
|
+
text=True,
|
|
1338
|
+
cwd=tmpdir,
|
|
1339
|
+
env=env,
|
|
1340
|
+
)
|
|
1341
|
+
self.assertEqual(proc.returncode, 0, proc.stderr)
|
|
1342
|
+
self.assertEqual(proc.stdout.strip(), "via meta")
|