Merge branch 'master' of gitlab.com:gabriel.alfour/tezos
This commit is contained in:
commit
89a7821e87
@ -514,7 +514,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
|
||||
|
1
src/ligo/ligo-parser/.gitignore
vendored
Normal file
1
src/ligo/ligo-parser/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/Version.ml
|
@ -1 +0,0 @@
|
||||
let version = "UNKNOWN"
|
@ -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 ;
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user