Skip to content

Commit

Permalink
Merge branch 'thakee-expr-typeinfo-2' of https://github.com/Jaseci-La…
Browse files Browse the repository at this point in the history
…bs/jaseci into thakee-expr-typeinfo-2
  • Loading branch information
ThakeeNathees committed Oct 7, 2024
2 parents 40ecbcf + a363718 commit 46579e9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@

with entry {
a = 4;
b = 7;
c = a + b; # OpExpr.
d = a + b + c;

(1 < 2); # ComparisonExpr.
('a' + 'b').upper(); # CallExpr.
[1,2][0]; # IndexExpr.
1 + 2; # OpExpr.
not False; # UnaryExpr.
h = float(a); # CallExpr.

(1 < 2); # ComparisonExpr.
('a' + 'b').upper(); # CallExpr.
[1,2][0]; # IndexExpr.
not False; # UnaryExpr.
"a" if True else "b"; # ConditionalExpr.
[i for i in range(10)]; # ListComprehension.
}

# Remaining expressions to test:
Expand All @@ -16,7 +21,6 @@ with entry {
# BytesExpr,
# CastExpr,
# ComplexExpr,
# ConditionalExpr,
# DictionaryComprehension,
# DictExpr,
# EllipsisExpr,
Expand All @@ -26,7 +30,6 @@ with entry {
# GeneratorExpr,
# IntExpr,
# LambdaExpr,
# ListComprehension,
# ListExpr,
# MemberExpr,
# NamedTupleExpr,
Expand All @@ -47,6 +50,5 @@ with entry {
# TypedDictExpr,
# TypeVarExpr,
# TypeVarTupleExpr,
# UnaryExpr,
# YieldExpr,
# YieldFromExpr,
# YieldFromExpr,
Empty file.
2 changes: 2 additions & 0 deletions jac/jaclang/tests/main.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import foo;

33 changes: 17 additions & 16 deletions jac/jaclang/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,39 +217,40 @@ def test_builtins_loading(self) -> None:
r"13\:12 \- 13\:18.*Name - append - .*SymbolPath: builtins_test.builtins.list.append",
)

def test_expr_type_info(self) -> None:
"""Testing for expression type infomation."""
from jaclang.settings import settings

settings.ast_symbol_info_detailed = True
def test_expr_types(self) -> None:
"""Testing for print AstTool."""
captured_output = io.StringIO()
sys.stdout = captured_output

cli.tool("ir", ["ast", f"{self.fixture_abs_path('expr_type_info.jac')}"])
cli.tool("ir", ["ast", f"{self.fixture_abs_path('expr_type.jac')}"])

sys.stdout = sys.__stdout__
stdout_value = captured_output.getvalue()
settings.ast_symbol_info_detailed = False

self.assertRegex(
stdout_value,
r"4:4 - 4:9.*CompareExpr - Type: builtins.bool",
stdout_value, r"4\:9 \- 4\:14.*BinaryExpr \- Type\: builtins.int"
)
self.assertRegex(
stdout_value,
r"5:3 - 5:22.*FuncCall - Type: builtins.str",
stdout_value, r"7\:9 \- 7\:17.*FuncCall \- Type\: builtins.float"
)
self.assertRegex(
stdout_value,
r"6:3 - 6:11.*AtomTrailer - Type: builtins.int",
stdout_value, r"9\:6 \- 9\:11.*CompareExpr \- Type\: builtins.bool"
)
self.assertRegex(
stdout_value,
r"7:3 - 7:8.*BinaryExpr - Type: builtins.int",
stdout_value, r"10\:6 - 10\:15.*BinaryExpr \- Type\: builtins.str"
)
self.assertRegex(
stdout_value, r"11\:5 \- 11\:13.*AtomTrailer \- Type\: builtins.int"
)
self.assertRegex(
stdout_value, r"12\:5 \- 12\:14.*UnaryExpr \- Type\: builtins.bool"
)
self.assertRegex(
stdout_value, r"13\:5 \- 13\:25.*IfElseExpr \- Type\: Literal\['a']\?"
)
self.assertRegex(
stdout_value,
r"8:3 - 8:12.*UnaryExpr - Type: builtins.bool",
r"14\:5 \- 14\:27.*ListCompr - \[ListCompr] \- Type\: builtins.list\[builtins.int]",
)

def test_ast_dotgen(self) -> None:
Expand Down

0 comments on commit 46579e9

Please sign in to comment.