-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
247 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
open Core | ||
open Print_parsed_ast | ||
|
||
let%expect_test "Good if statement" = | ||
print_parsed_ast | ||
" | ||
{ | ||
let x = true; | ||
if x { | ||
0 | ||
} | ||
else { | ||
1 | ||
} | ||
} | ||
" ; | ||
[%expect | ||
{| | ||
Program | ||
└──Expr: Block | ||
└──Expr: Let var: x | ||
└──Expr: Bool:true | ||
└──Expr: If | ||
└──Expr: Variable: x | ||
└──Expr: Block | ||
└──Expr: Int:0 | ||
└──Expr: Block | ||
└──Expr: Int:1 |}] | ||
|
||
let%expect_test "Good if then statement" = | ||
print_parsed_ast " | ||
{ | ||
let x = true; | ||
if x then 0 else 1 | ||
} | ||
" ; | ||
[%expect | ||
{| | ||
Program | ||
└──Expr: Block | ||
└──Expr: Let var: x | ||
└──Expr: Bool:true | ||
└──Expr: If | ||
└──Expr: Variable: x | ||
└──Expr: Int:0 | ||
└──Expr: Int:1 |}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
open Core | ||
open Print_typed_ast | ||
|
||
let%expect_test "If statement with non-boolean condition" = | ||
print_typed_ast | ||
" | ||
{ | ||
if 1 { (* 1 is not a boolean value *) | ||
0 | ||
} | ||
else { | ||
1 | ||
} | ||
} | ||
" ; | ||
[%expect | ||
{| | ||
Line:3 Position:6 Type error - If statement condition expression should have boolean type but instead has type Int |}] | ||
|
||
let%expect_test "If statement then and else branches' types are different " = | ||
print_typed_ast | ||
" | ||
{ | ||
if true { | ||
0 | ||
} | ||
else { | ||
false | ||
} | ||
} | ||
" ; | ||
[%expect | ||
{| | ||
Line:3 Position:6 Type error - If statement branches' types' not consistent - then branch has type Int but else branch has type Bool |}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
open Core | ||
open Print_typed_ast | ||
|
||
let%expect_test "Good if statement" = | ||
print_typed_ast | ||
" | ||
{ | ||
let x = true; | ||
if x { | ||
0 | ||
} | ||
else { | ||
1 | ||
} | ||
} | ||
" ; | ||
[%expect | ||
{| | ||
Program | ||
└──Expr: Block | ||
└──Type expr: Int | ||
└──Expr: Let var: x | ||
└──Type expr: Bool | ||
└──Expr: Bool:true | ||
└──Expr: Finish_async | ||
└──Type expr: Int | ||
└──Expr: Variable: x | ||
└──Type expr: Bool | ||
└──Expr: Block | ||
└──Type expr: Int | ||
└──Expr: Int:0 | ||
└──Expr: Block | ||
└──Type expr: Int | ||
└──Expr: Int:1 |}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters