about summary refs log tree commit diff
path: root/users/wpcarro/scratch/compiler/tests.ml
blob: 828cbd16f090ec397bb322ef93e6bc6ff09b2a21 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
open Expr_parser
open Type_parser
open Inference

type test = { input : string; expect : string; }
(* type sub_test = { s1 : string; s2 : string; s3 : string } *)

let ( let* ) = Option.bind

let tests = [
    { input = "((fn x x) 10)"; expect = "Integer"; };
    { input = "(let f (fn x x) f)"; expect = "a -> a"; };
]

(* let sub_tests = [ *)
(*     { *)
(*       s1 = "{b |-> b -> Int}"; *)
(*       s2 = "{a: Bool, b: Int, c: Bool}"; *)
(*       s3 = "{a: Bool, b: Int -> Int, c: Bool}"; *)
(*     } *)
(* ] *)

exception FailedAssertion
exception TestError

let main =
  tests
  |> List.iter (fun { input; expect } ->
         Printf.sprintf ":t %s == %s\n" input expect |> print_string;
         match (parse_language input, parse_input expect) with
         | Some ast, Some expected ->
            (match do_infer ast with
             | Some actual ->
                if actual != expected then
                  begin
                    print_type actual;
                    raise FailedAssertion
                  end
                else
                  print_string "Test passed.\n"
             | _ -> raise TestError)
         | _ -> raise TestError);
  print_string "All tests pass!"