diff --git a/jac/jaclang/tests/fixtures/base_class1.jac b/jac/jaclang/tests/fixtures/base_class1.jac new file mode 100644 index 000000000..288f57e8c --- /dev/null +++ b/jac/jaclang/tests/fixtures/base_class1.jac @@ -0,0 +1,11 @@ +import:py test_py; + +class B :test_py.A: {} + +with entry { + a = test_py.A(); + b = B(); + + a.start(); + b.start(); +} diff --git a/jac/jaclang/tests/fixtures/base_class2.jac b/jac/jaclang/tests/fixtures/base_class2.jac new file mode 100644 index 000000000..110d82290 --- /dev/null +++ b/jac/jaclang/tests/fixtures/base_class2.jac @@ -0,0 +1,11 @@ +import:py from test_py { A } + +class B :A: {} + +with entry { + a = A(); + b = B(); + + a.start(); + b.start(); +} diff --git a/jac/jaclang/tests/fixtures/test_py.py b/jac/jaclang/tests/fixtures/test_py.py new file mode 100644 index 000000000..ba3e4f804 --- /dev/null +++ b/jac/jaclang/tests/fixtures/test_py.py @@ -0,0 +1,12 @@ +"""Test file for subclass issue.""" + +p = 5 +g = 6 + + +class A: + """Dummy class to test the base class issue.""" + + def start(self) -> int: + """Return 0.""" + return 0 diff --git a/jac/jaclang/tests/test_cli.py b/jac/jaclang/tests/test_cli.py index cf9b1cd18..285ce8b37 100644 --- a/jac/jaclang/tests/test_cli.py +++ b/jac/jaclang/tests/test_cli.py @@ -233,6 +233,44 @@ def test_builtins_loading(self) -> None: r"13\:12 \- 13\:18.*Name - append - .*SymbolPath: builtins_test.builtins.list.append", ) + def test_sub_class_symbol_table_fix_1(self) -> None: + """Testing for print AstTool.""" + from jaclang.settings import settings + + settings.ast_symbol_info_detailed = True + captured_output = io.StringIO() + sys.stdout = captured_output + + cli.tool("ir", ["ast", f"{self.fixture_abs_path('base_class1.jac')}"]) + + sys.stdout = sys.__stdout__ + stdout_value = captured_output.getvalue() + settings.ast_symbol_info_detailed = False + + self.assertRegex( + stdout_value, + r"10:7 - 10:12.*Name - start - Type.*SymbolPath: base_class1.B.start", + ) + + def test_sub_class_symbol_table_fix_2(self) -> None: + """Testing for print AstTool.""" + from jaclang.settings import settings + + settings.ast_symbol_info_detailed = True + captured_output = io.StringIO() + sys.stdout = captured_output + + cli.tool("ir", ["ast", f"{self.fixture_abs_path('base_class2.jac')}"]) + + sys.stdout = sys.__stdout__ + stdout_value = captured_output.getvalue() + settings.ast_symbol_info_detailed = False + + self.assertRegex( + stdout_value, + r"10:7 - 10:12.*Name - start - Type.*SymbolPath: base_class2.B.start", + ) + def test_expr_types(self) -> None: """Testing for print AstTool.""" captured_output = io.StringIO()