printTest.ml 1.77 KB
Newer Older
Pietro Abate's avatar
Pietro Abate committed
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
open OUnit
open Types

let parse_typ s =
  let st = Stream.of_string s in
  let astpat = Parser.pat st in
  let nodepat = Typer.typ Builtin.env astpat in
  Types.descr nodepat
;;

let to_string pp t =
  Format.fprintf Format.str_formatter "%a@." pp t;
  Format.flush_str_formatter ()
;;

let print_tests = [
  "Int"; 
  "Empty";
  "(Int,Int)";
  "Int -> Int";
  "Bool -> Bool";
  "Int -> `$A";
  "[] -> []";
  "Int -> `$A";
  "(`$A -> Bool)";
  "(`$B -> `$B)";
  "(Int -> Bool)";
  "(Int -> Int) | (Bool -> Bool)";
  "(Int -> Int) | (Bool -> Bool)";
  "([0--*] & `true)";
  "(`$A | Int) & ((Any \\ `$A) | Bool)";
  "(`$A | (`$B , `$C))";
  "(Int , Int)";
  "(`$A -> `$B) -> [ `$A ] -> [ `$B ]";
  "((Int -> Bool) | ((`$A \\ Int) -> (`$B \\ Int))) -> `$Gamma";
  "((`$A , Int) & (`$B , Bool))";
  "(Int , (*Int & Bool*) Empty)";
  "((`$A , Int) | (`$B , Bool))";
  "(Int , (Int | Bool))";
  "((Int | Bool) -> Int)";
  "((Int | Bool) -> Int)";
  "(Int -> Int) | (Bool -> Bool)";
  "((Int,Int) , (Int | Bool))";
  "(`$A,Int) | ((`$B,Int),Bool)";
  "((`$A , Int) | (`$B , Bool))";
  "(Int , (Int | Bool))";
  "((`$A , Int) & (`$B , Bool))";
  "(Int , (Int & Bool))";
  "(`$A -> `$B) -> [`$A ] -> [`$B ]";
  "((Int -> Bool) & ((`$A \\ Int) -> (`$A \\ Int)))";
  "((Int -> Int) & (Bool -> Bool)) -> `$T";
]

let test_print = 
  "test print module" >:::
    List.map (fun s ->
      (Printf.sprintf " Printing %s " s) >:: (fun _ ->
          let t = parse_typ s in
          Format.printf "String : %s\n" s;
Julien Lopez's avatar
Julien Lopez committed
60
          Format.printf "Print : %a\n\n" Types.Print.pp_value t;
Pietro Abate's avatar
Pietro Abate committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
          (*
          Format.printf "Dump : %a\n\n" Types.dump t;
          *)
          assert_equal true true
      )
    ) print_tests
;;

let suite =
  "tests" >::: [
    test_print;
  ]

let main () =
  OUnit.run_test_tt_main suite
;;

main ()