diff --git a/src/ligo/ast_simplified.ml b/src/ligo/ast_simplified.ml index 4fe0d0559..cc2e73993 100644 --- a/src/ligo/ast_simplified.ml +++ b/src/ligo/ast_simplified.ml @@ -513,7 +513,13 @@ end module Combinators = struct let annotated_expression ?type_annotation expression = {expression ; type_annotation} + let unit () : expression = Literal (Unit) let number n : expression = Literal (Number n) + let bool b : expression = Literal (Bool b) + let string s : expression = Literal (String s) + let bytes b : expression = Literal (Bytes (Bytes.of_string b)) + + let tuple (lst : ae list) : expression = Tuple lst let record (lst : (string * ae) list) : expression = let aux prev (k, v) = SMap.add k v prev in diff --git a/src/ligo/ligo-parser/.gitignore b/src/ligo/ligo-parser/.gitignore new file mode 100644 index 000000000..73be7197d --- /dev/null +++ b/src/ligo/ligo-parser/.gitignore @@ -0,0 +1 @@ +/Version.ml diff --git a/src/ligo/ligo-parser/Version.ml b/src/ligo/ligo-parser/Version.ml deleted file mode 100644 index d89964cb1..000000000 --- a/src/ligo/ligo-parser/Version.ml +++ /dev/null @@ -1 +0,0 @@ -let version = "UNKNOWN" diff --git a/src/ligo/test/typer_tests.ml b/src/ligo/test/typer_tests.ml index bbb40329b..b7feb5380 100644 --- a/src/ligo/test/typer_tests.ml +++ b/src/ligo/test/typer_tests.ml @@ -4,6 +4,7 @@ open Test_helpers module Typed = Ligo.AST_Typed module Typer = Ligo.Typer +module Simplified = Ligo.AST_Simplified let int () : unit result = let open Combinators in @@ -16,25 +17,55 @@ let int () : unit result = let%bind () = assert_type_value_eq (post.type_annotation, make_t_int) in ok () -let record () : unit result = - let open Combinators in - let pre = ae (record [ - ("foo", ae @@ number 32) ; - ("bar", ae @@ number 23) ; - ]) in - let open Typer in - let%bind post = type_annotated_expression Environment.empty pre in - let open Typed in - let open Combinators in - let result_type = make_t_ez_record [ - ("foo", make_t_int) ; - ("bar", make_t_int) ; - ] in - let%bind () = assert_type_value_eq (post.type_annotation, result_type) in - ok () +module TestExpressions = struct + let test_expression (expr : expression) (test_expected_ty : Typed.tv) = + let open Typer in + let open Typed in + let pre = ae @@ expr in + let e = Environment.empty in + let%bind post = type_annotated_expression e pre in + let%bind () = assert_type_value_eq (post.type_annotation, test_expected_ty) in + ok () + open Simplified.Combinators + open Typed.Combinators + + let unit () : unit result = test_expression (unit ()) (make_t_unit) + let int () : unit result = test_expression (number 32) (make_t_int) + let bool () : unit result = test_expression (bool true) (make_t_bool) + let string () : unit result = test_expression (string "s") (make_t_string) + let bytes () : unit result = test_expression (bytes "b") (make_t_bytes) + + let tuple () : unit result = + test_expression Simplified.Combinators.(tuple [ + ae @@ number 32 ; + ae @@ string "foo" ; + ]) + (make_t_tuple [ + make_t_int ; + make_t_string ; + ]) + + let record () : unit result = + test_expression Simplified.Combinators.(record [ + ("foo", ae @@ number 32) ; + ("bar", ae @@ string "foo") ; + ]) + (make_t_ez_record [ + ("foo", make_t_int) ; + ("bar", make_t_string) ; + ]) + +end +(* TODO: deep types (e.g. record of record) + TODO: negative tests (expected type error) *) let main = "Typer (from simplified AST)", [ test "int" int ; - test "record" record ; + test "unit" TestExpressions.unit ; + test "int2" TestExpressions.int ; + test "bool" TestExpressions.bool ; + test "string" TestExpressions.string ; + test "bytes" TestExpressions.bytes ; + test "record" TestExpressions.record ; ]