printTest.ml 1.74 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
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";
22
  "Int -> 'A";
Pietro Abate's avatar
Pietro Abate committed
23
  "[] -> []";
24 25 26
  "Int -> 'A";
  "('A -> Bool)";
  "('B -> 'B)";
Pietro Abate's avatar
Pietro Abate committed
27 28 29 30
  "(Int -> Bool)";
  "(Int -> Int) | (Bool -> Bool)";
  "(Int -> Int) | (Bool -> Bool)";
  "([0--*] & `true)";
31 32
  "('A | Int) & ((Any \\ 'A) | Bool)";
  "('A | ('B , 'C))";
Pietro Abate's avatar
Pietro Abate committed
33
  "(Int , Int)";
34 35 36
  "('A -> 'B) -> [ 'A ] -> [ 'B ]";
  "((Int -> Bool) | (('A \\ Int) -> ('B \\ Int))) -> 'Gamma";
  "(('A , Int) & ('B , Bool))";
Pietro Abate's avatar
Pietro Abate committed
37
  "(Int , (*Int & Bool*) Empty)";
38
  "(('A , Int) | ('B , Bool))";
Pietro Abate's avatar
Pietro Abate committed
39 40 41 42 43
  "(Int , (Int | Bool))";
  "((Int | Bool) -> Int)";
  "((Int | Bool) -> Int)";
  "(Int -> Int) | (Bool -> Bool)";
  "((Int,Int) , (Int | Bool))";
44 45
  "('A,Int) | (('B,Int),Bool)";
  "(('A , Int) | ('B , Bool))";
Pietro Abate's avatar
Pietro Abate committed
46
  "(Int , (Int | Bool))";
47
  "(('A , Int) & ('B , Bool))";
Pietro Abate's avatar
Pietro Abate committed
48
  "(Int , (Int & Bool))";
49 50 51
  "('A -> 'B) -> ['A ] -> ['B ]";
  "((Int -> Bool) & (('A \\ Int) -> ('A \\ Int)))";
  "((Int -> Int) & (Bool -> Bool)) -> 'T";
Pietro Abate's avatar
Pietro Abate committed
52 53 54 55 56 57 58 59
]

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 ()