Skip to content

Commit

Permalink
Adding tests, Fixing issue in #1345
Browse files Browse the repository at this point in the history
  • Loading branch information
mgtm98 committed Dec 14, 2024
1 parent 8b0ba86 commit 0ede2a4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jac/jaclang/tests/fixtures/base_class1.jac
Original file line number Diff line number Diff line change
@@ -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();
}
11 changes: 11 additions & 0 deletions jac/jaclang/tests/fixtures/base_class2.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import:py from test_py { A }

class B :A: {}

with entry {
a = A();
b = B();

a.start();
b.start();
}
12 changes: 12 additions & 0 deletions jac/jaclang/tests/fixtures/test_py.py
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions jac/jaclang/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0ede2a4

Please sign in to comment.