main.ml 20.1 KB
Newer Older
1
open OUnit2
Pietro Abate's avatar
Pietro Abate committed
2
3
4
open Camlp4.PreCast 

(* Typed -> Lamda *)
5
let run_test_compile msg expected totest =
Pietro Abate's avatar
Pietro Abate committed
6
7
8
9
10
11
12
13
14
  let aux str =
    try
      let expr = Parse.ExprParser.of_string_no_file str in
      let env, texpr = Compute.to_typed expr in
      let lambdaexpr = Compile.compile env texpr in
      Printer.lambda_to_string lambdaexpr
    with
      | Compute.Error -> exit 3
      | Loc.Exc_located (loc, exn) ->
15
16
17
18
19
	let l = Loc.start_line loc in
	let cbegin = Loc.start_off loc - Loc.start_bol loc in
	let cend = Loc.stop_off loc - Loc.start_bol loc in
	Printf.eprintf "File %s, line %d, characters %d-%d:\n" (Loc.file_name loc) l
	  cbegin cend; raise exn
Pietro Abate's avatar
Pietro Abate committed
20
21
      | e -> Printf.eprintf "Runtime error.\n"; raise e
  in
22
  fun _ -> assert_equal ~msg:msg ~printer:(fun x -> x) expected (aux totest)
Pietro Abate's avatar
Pietro Abate committed
23
24

let tests_poly_abstr = [
25
26
27
  "Test CDuce.lambda.const_abstr failed",
  "Abstraction(Dummy,,,,Sel(,(Int -> Int),{}))",
  "fun f x : Int : Int -> 2";
Pietro Abate's avatar
Pietro Abate committed
28

29
  "Test CDuce.lambda.poly.identity failed",
30
  "Abstraction(Dummy,,,,Sel(,([ Char* ] | Int -> [ Char* ] | Int),Comp({},{ { (`$A/
31
32
[ Char* ]) } ,{ (`$A/Int) } })))",
  "(fun f x : 'A{A/Int;A/String} : 'A{A/Int;A/String} -> x) {A/Int;A/String}";
Pietro Abate's avatar
Pietro Abate committed
33
34

  "Test CDuce.runtime.poly.tail failed",
35
36
37
38
39
40
41
42
  "Abstraction(Dummy,,,,Sel(,([ (`$A & Int | Char | Atom | (Any,Any) |
                             <(Any) (Any)>Any | Arrow)* ] -> [ (`$A & Int |
                                                               Char | 
                                                               Atom |
                                                               (Any,Any) |
                                                               <(Any) (Any)>Any |
                                                               Arrow)* ]),{}))",
  "fun tail x : ['A{}] : ['A{}] -> match x : ['A{}] with | (el : 'A{}) :: (rest : ['A{}]) -> rest";
Pietro Abate's avatar
Pietro Abate committed
43

44
  "Test CDuce.runtime.poly.pair failed", "",
45
  "fun pair x : ('A{} * 'B{}) : 'A{} -> match x : ('A{} * 'B{}) with | (x : 'A{}, y : 'B{}) -> x";
46

47
48
  "Test CDuce.runtime.poly.match_abstr failed", "",
  "(match (fun f x : 'A{} : 'A{} -> x) : ('A{} -> 'A{}) with | y : ('A{} -> 'A{}) -> y{A/Int}).3";
49
50
51



Pietro Abate's avatar
Pietro Abate committed
52
53
]

54
55
let tests_compile = "CDuce compile tests (Typed -> Lambda )" >:::
  List.map (fun (m,e,f) -> f >:: run_test_compile m e f) tests_poly_abstr
56

57
58
59
60
61
62
63
64
65
66
67
68
69
(* Typed -> Lambda -> Value *)
let run_test_eval str =
  try
    let expr = Parse.ExprParser.of_string_no_file str in
    let env, texpr = Compute.to_typed expr in
    let evalexpr = Compile.compile_eval_expr env texpr in
    Printer.value_to_string evalexpr
  with
    | Compute.Error -> exit 3
    | Loc.Exc_located (loc, exn) ->
      let l = Loc.start_line loc in
      let cbegin = Loc.start_off loc - Loc.start_bol loc in
      let cend = Loc.stop_off loc - Loc.start_bol loc in
70
71
      Printf.eprintf "File %s, line %d, characters %d-%d:\n" (Loc.file_name loc)
	l cbegin cend; raise exn
72
    | e -> Printf.eprintf "Runtime error.\n"; raise e
73

74
let tests_eval = "CDuce runtime tests (Typed -> Lambda -> Value)" >:::
75
76
  [
    "abstr" >:: ( fun test_ctxt ->
77
78
79
      assert_equal ~msg:"Test CDuce.runtime.abstr.let_simple failed"
	~printer:(fun x -> x) "3"
	(run_test_eval "let x : Int = 3 in x : Int");
80
81
82
83
84
85
86
87
88
89
90
91
92
93
      assert_equal ~msg:"Test CDuce.runtime.abstr.let_medium failed"
	~printer:(fun x -> x) "2"
	(run_test_eval "let f : (Int -> Int) = (fun (Int -> Int) | x : Int -> x)
                        in (f.f.2) : Int");
      assert_equal ~msg:"Test CDuce.runtime.abstr.let_nested_simple failed"
	~printer:(fun x -> x) "3"
	(run_test_eval "let f : (Int -> Int) = (fun (Int -> Int) | x : Int -> x + 1)
                        in (let x : Int = f.2
                            in x : Int) : Int");
      assert_equal ~msg:"Test CDuce.runtime.abstr.let_nested_medium failed"
	~printer:(fun x -> x) "4"
	(run_test_eval "let f : (Int -> Int) = (fun (Int -> Int) | x : Int -> x + 1)
                        in (let x : Int = f.2
                            in f.x : Int) : Int");
94
      assert_equal ~msg:"Test CDuce.runtime.abstr.simple failed"
95
	~printer:(fun x -> x) "Abstraction((Int, Int),{})"
96
	(run_test_eval "fun f x : Int : Int -> 2");
97
      assert_equal ~msg:"Test CDuce.runtime.abstr.medium failed"
98
	~printer:(fun x -> x)
99
	"Abstraction((Int, [ Char* ] -> [ Int Char* ]),{})"
100
	(run_test_eval "fun f x : Int y : String : (Int*String) -> x,y");
101
102
103
104
    );

    "apply" >:: ( fun test_ctxt ->
      assert_equal ~msg:"Test CDuce.runtime.apply.simple failed"
105
	~printer:(fun x -> x) "2"
106
	(run_test_eval "(fun f x : Int : Int -> x).2");
107
      assert_equal ~msg:"Test CDuce.runtime.apply.simple_pair failed"
108
	~printer:(fun x -> x) "(3, 2, {})"
109
	(run_test_eval "(fun f x : (Int*Int) : (Int*Int) -> x).(3,2)");
110
      assert_equal ~msg:"Test CDuce.runtime.apply.medium failed"
111
	~printer:(fun x -> x) "(2, 3, {})"
112
	(run_test_eval "((fun f x : Int y : Int : (Int*Int) -> x,y).2).3");
113
114
115
    );

    "misc" >:: ( fun test_ctxt ->
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
      assert_equal ~msg:"Test CDuce.runtime.misc.even failed"
	~printer:(fun x -> x)
	"Abstraction((Int, Bool) ,(Any \\ (Int), Any \\ (Int)),{})"
	(run_test_eval "fun ((Int -> Bool) & ((!Int) -> (!Int)))
                          | x : Int -> (match (x % 2) : Int with
                                          | 0 -> `true
                                          | 1 -> `false)
                          | x : (!Int) -> x");
      assert_equal ~msg:"Test CDuce.runtime.misc.even_applied1 failed"
	~printer:(fun x -> x)
	"Atom(false)"
	(run_test_eval "(fun ((Int -> Bool) & ((!Int) -> (!Int)))
                          | x : Int -> (match (x % 2) : Int with
                                          | 0 -> `true
                                          | 1 -> `false)
                          | x : (!Int) -> x).5");
      assert_equal ~msg:"Test CDuce.runtime.misc.even_applied2 failed"
	~printer:(fun x -> x)
	"Atom(true)"
	(run_test_eval "(fun ((Int -> Bool) & ((!Int) -> (!Int)))
                          | x : Int -> (match (x % 2) : Int with
                                          | 0 -> `true
                                          | 1 -> `false)
                          | x : (!Int) -> x).8");
      assert_equal ~msg:"Test CDuce.runtime.misc.even_applied3 failed"
	~printer:(fun x -> x)
142
	"(2, (3, Atom(nil), {}), {})"
143
144
145
146
147
	(run_test_eval "(fun ((Int -> Bool) & ((!Int) -> (!Int)))
                          | x : Int -> (match (x % 2) : Int with
                                          | 0 -> `true
                                          | 1 -> `false)
                          | x : (!Int) -> x).[2; 3]");
148
      assert_equal ~msg:"Test CDuce.runtime.misc.is_int failed"
149
	~printer:(fun x -> x)
150
151
	"Abstraction((Int, Bool) ,(Bool, Bool) ,(Any \\ (Int | Bool), Any \\ (Int | Bool)),{})"
	(run_test_eval "fun ((Int -> Bool) & (Bool -> Bool) & ((!(Int|Bool)) -> (!(Int|Bool))))
152
                          | x : Int -> `true
153
154
                          | x : Bool -> `false
                          | x : (!(Int|Bool)) -> x");
155
156
157
      assert_equal ~msg:"Test CDuce.runtime.misc.is_int_applied1 failed"
	~printer:(fun x -> x)
	"Atom(true)"
158
	(run_test_eval "(fun ((Int -> Bool) & (Bool -> Bool) & ((!(Int|Bool)) -> (!(Int|Bool))))
159
                           | x : Int -> `true
160
161
                           | x : Bool -> `false
                           | x : (!(Int|Bool)) -> x).2");
162
163
164
      assert_equal ~msg:"Test CDuce.runtime.misc.is_int_applied2 failed"
	~printer:(fun x -> x)
	"Atom(false)"
165
	(run_test_eval "(fun ((Int -> Bool) & (Bool -> Bool) & ((!(Int|Bool)) -> (!(Int|Bool))))
166
                           | x : Int -> `true
167
168
                           | x : Bool -> `false
                           | x : (!(Int|Bool)) -> x).`true");
169
170
      assert_equal ~msg:"Test CDuce.runtime.misc.is_int_applied3 failed"
	~printer:(fun x -> x)
171
	"(2, (3, Atom(nil), {}), {})"
172
	(run_test_eval "(fun ((Int -> Bool) & (Bool -> Bool) & ((!(Int|Bool)) -> (!(Int|Bool))))
173
                           | x : Int -> `true
174
175
                           | x : Bool -> `false
                           | x : (!(Int|Bool)) -> x).[2; 3]");
176
      assert_equal ~msg:"Test CDuce.runtime.misc.map failed"
177
	~printer:(fun x -> x)
178
179
180
181
182
183
184
185
	"Abstraction(((`$A & Int | Char | Atom | (Any,Any) | <(Any) (Any)>Any | Arrow) -> 
             (`$B & Int | Char | Atom | (Any,Any) | <(Any) (Any)>Any | 
             Arrow), [ (`$A & Int | Char | Atom | (Any,Any) |
                       <(Any) (Any)>Any | Arrow)* ] -> [ (`$B & Int | 
                                                         Char | Atom |
                                                         (Any,Any) |
                                                         <(Any) (Any)>Any |
                                                         Arrow)* ]),{})"
186
187
	(run_test_eval "fun map f : ('A{}->'B{}) x : ['A{}] : ['B{}] ->
                          match x : ['A{}] with
188
189
                            | (el : 'A{}) :: [] -> f.el
                            | (el : 'A{}) :: (rest : ['A{}]) -> ((f.el), ((map.f).rest))");
190
191
      assert_equal ~msg:"Test CDuce.runtime.misc.map_even_simple failed"
	~printer:(fun x -> x)
192
193
194
195
196
	"(\"hey\", Atom(false), {A/Int;A/Bool})"
	(run_test_eval "(fun map f : ('A{A/Int;A/Bool}->'B{A/Int;A/Bool}) x : ['A{A/Int;A/Bool}] : ['B{A/Int;A/Bool}] ->
                          match x : ['A{A/Int;A/Bool}] with
                            | (el : 'A{A/Int;A/Bool}) :: [] -> f.el
                            | (el : 'A{A/Int;A/Bool}) :: (rest : ['A{A/Int;A/Bool}]) -> ((f.el), ((map.f).rest))).(fun ((Int -> Bool) & ((!Int) -> (!Int)))
197
198
199
200
201
202
                          | x : Int -> (match (x % 2) : Int with
                                          | 0 -> `true
                                          | 1 -> `false)
                          | x : (!Int) -> x).[\"hey\"; 3]");
      assert_equal ~msg:"Test CDuce.runtime.misc.map_even_medium failed"
	~printer:(fun x -> x)
203
204
205
206
207
	"(\"hey\", Atom(false), Atom(true), {A/Int;A/Bool})"
	(run_test_eval "(fun map f : ('A{A/Int;A/Bool}->'B{A/Int;A/Bool}) x : ['A{A/Int;A/Bool}] : ['B{A/Int;A/Bool}] ->
                          match x : ['A{A/Int;A/Bool}] with
                            | (el : 'A{A/Int;A/Bool}) :: [] -> f.el
                            | (el : 'A{A/Int;A/Bool}) :: (rest : ['A{A/Int;A/Bool}]) -> ((f.el), ((map.f).rest))).(fun ((Int -> Bool) & ((!Int) -> (!Int)))
208
209
210
211
                          | x : Int -> (match (x % 2) : Int with
                                          | 0 -> `true
                                          | 1 -> `false)
                          | x : (!Int) -> x).[\"hey\"; 3; 2]");
212
213
      assert_equal ~msg:"Test CDuce.runtime.misc.map_is_int_simple failed"
	~printer:(fun x -> x)
214
215
216
217
218
	"(Atom(false), Atom(true), {A/Int;A/Bool})"
	(run_test_eval "(fun map f : ('A{A/Int;A/Bool}->'B{A/Int;A/Bool}) x : ['A{A/Int;A/Bool}] : ['B{A/Int;A/Bool}] ->
                          match x : ['A{A/Int;A/Bool}] with
                            | (el : 'A{A/Int;A/Bool}) :: [] -> f.el
                            | (el : 'A{A/Int;A/Bool}) :: (rest : ['A{A/Int;A/Bool}]) -> ((f.el), ((map.f).rest))).(fun ((Int -> Bool) & (Bool -> Bool) & ((!(Int|Bool)) -> (!(Int|Bool))))
219
220
221
222
223
                          | x : Int -> `true
                          | x : Bool -> `false
                          | x : (!(Int|Bool)) -> x).[`true; 3]");
      assert_equal ~msg:"Test CDuce.runtime.misc.map_is_int_medium failed"
	~printer:(fun x -> x)
224
225
226
227
228
	"(Atom(false), Atom(true), Atom(false), {A/Int;A/Bool})"
	(run_test_eval "(fun map f : ('A{A/Int;A/Bool}->'B{A/Int;A/Bool}) x : ['A{A/Int;A/Bool}] : ['B{A/Int;A/Bool}] ->
                          match x : ['A{A/Int;A/Bool}] with
                            | (el : 'A{A/Int;A/Bool}) :: [] -> f.el
                            | (el : 'A{A/Int;A/Bool}) :: (rest : ['A{A/Int;A/Bool}]) -> ((f.el), ((map.f).rest))).(fun ((Int -> Bool) & (Bool -> Bool) & ((!(Int|Bool)) -> (!(Int|Bool))))
229
230
231
                          | x : Int -> `true
                          | x : Bool -> `false
                          | x : (!(Int|Bool)) -> x).[`true; 3; `true]");
232
      assert_equal ~msg:"Test CDuce.runtime.misc.firsts failed"
233
	~printer:(fun x -> x)
234
	"Abstraction(((Int,Int), X1 -> X1 where X1 = (Int,Int)),{})"
235
	(run_test_eval "fun firsts x : (Int*Int) y : (Int*Int) : (Int*Int) ->
236
237
238
                     match x,y : ((Int*Int)*(Int*Int)) with
                       | (a : Int,_ : Int),(b : Int,_ : Int) -> a,b");
      assert_equal ~msg:"Test CDuce.runtime.misc.firsts_applied failed"
239
	~printer:(fun x -> x) "(5, 1, {})"
240
	(run_test_eval "((fun firsts x : (Int*Int) y : (Int*Int) : (Int*Int) ->
241
242
243
                       match x,y : ((Int*Int)*(Int*Int)) with
                         | (a : Int,_ : Int),(b : Int,_ : Int) -> a,b)
                   .(5, 3)).(1, 4)");
Julien Lopez's avatar
Julien Lopez committed
244
      assert_equal ~msg:"Test CDuce.runtime.misc.applier failed"
245
	~printer:(fun x -> x) "Abstraction((Int, Int -> Int -> Int),{})"
246
	(run_test_eval "fun applier x : Int f : (Int->Int) : Int -> f.x");
Julien Lopez's avatar
Julien Lopez committed
247
      assert_equal ~msg:"Test CDuce.runtime.misc.applier_applied failed"
248
	~printer:(fun x -> x) "2"
249
	(run_test_eval "((fun applier x : Int f : (Int->Int) : Int ->
Julien Lopez's avatar
Julien Lopez committed
250
                       f.x).2).(fun g x : Int : Int -> x)");
251
252
    );

253
254
255
256
257
258
259
260
261
    "arith" >:: ( fun test_ctxt ->
      assert_equal ~msg:"Test CDuce.runtime.arith.simple failed"
	~printer:(fun x -> x) "5"
	(run_test_eval "2+3");
      assert_equal ~msg:"Test CDuce.runtime.arith.complete failed"
	~printer:(fun x -> x) "1"
	(run_test_eval "2+5*7%2-8/4");
    );

262
263
    "match" >:: ( fun test_ctxt ->
      assert_equal ~msg:"Test CDuce.runtime.match.simple failed"
264
	~printer:(fun x -> x) "1"
265
	(run_test_eval "match 1 : Int with | 1 -> 1 | \"true\" -> \"true\"");
266
      assert_equal ~msg:"Test CDuce.runtime.match.unused_branches failed"
267
	~printer:(fun x -> x) "1"
268
	(run_test_eval "match 1 : Int with
269
270
                     | s : String -> s | b : Bool -> b | i : Int -> i");
      assert_equal ~msg:"Test CDuce.runtime.match.simple_var failed"
271
	~printer:(fun x -> x) "2"
272
	(run_test_eval "(fun f x : Int : Int ->
273
274
                      match x : Int with | y : Int -> x).2");
      assert_equal ~msg:"Test CDuce.runtime.match.medium failed"
275
	~printer:(fun x -> x) "2"
276
	(run_test_eval "(fun f x : Int : Int ->
277
                      match x : Int with | 1 -> 3 | x : Int -> x).2");
278
      assert_equal ~msg:"Test CDuce.runtime.match.rec failed"
279
	~printer:(fun x -> x) "3"
280
	(run_test_eval "(fun f x : Int : Int ->
281
                      match x : Int with | 1 -> 3 | x : Int -> f.1).2");
282
283
284
285
    );

    "string" >:: ( fun test_ctxt ->
      assert_equal ~msg:"Test CDuce.runtime.string.simple failed"
286
	~printer:(fun x -> x) "\"The cake is a lie\""
287
	(run_test_eval "\"The cake is a lie\"");
288
289
    );

Julien Lopez's avatar
Julien Lopez committed
290
291
292
    "list" >:: ( fun test_ctxt ->
      assert_equal ~msg:"Test CDuce.runtime.list.simple failed"
	~printer:(fun x -> x) "1"
293
	(run_test_eval "match [1; 2] : [Int] with
Julien Lopez's avatar
Julien Lopez committed
294
295
296
297
                     | (el : Int) :: (rest : [Int]) -> el
                     | x : Int -> 3");
      assert_equal ~msg:"Test CDuce.runtime.list.simple2 failed"
	~printer:(fun x -> x) "3"
298
	(run_test_eval "match 2 : Int with
Julien Lopez's avatar
Julien Lopez committed
299
300
301
                     | (el : Int) :: (rest : [Int]) -> el
                     | x : Int -> 3");
      assert_equal ~msg:"Test CDuce.runtime.list.tail failed"
302
	~printer:(fun x -> x) "Abstraction(([ Int* ], [ Int* ]),{})"
303
	(run_test_eval "fun tail x : [Int] : [Int] -> match x : [Int] with
304
305
                     | (el : Int) :: (rest : [Int]) -> rest");
      assert_equal ~msg:"Test CDuce.runtime.list.tail.eval failed"
306
	~printer:(fun x -> x) "(2, (5, Atom(nil), {}), {})"
307
	(run_test_eval "(fun tail x : [Int] : [Int] -> match x : [Int] with
Julien Lopez's avatar
Julien Lopez committed
308
                     | (el : Int) :: (rest : [Int]) -> rest).[1; 2; 5]");
309
      assert_equal ~msg:"Test CDuce.runtime.list.last failed"
310
	~printer:(fun x -> x) "7"
311
	(run_test_eval "(fun f x : [Int] : [Int] -> match x : [Int] with
312
313
                     | (el : Int) :: [] -> el
                     | (el : Int) :: (rest : [Int]) -> f.rest).[1; 2; 5; 4; 8; 7]");
314
315
316
      assert_equal ~msg:"Test CDuce.runtime.list.plusone failed"
	~printer:(fun x -> x) "(2, (3, (6, (5, (9, 8, {}), {}), {}), {}), {})"
	(run_test_eval "(fun f x : [Int] : [Int] -> match x : [Int] with
317
318
                     | (el : Int) :: [] -> el+1
                     | (el : Int) :: (rest : [Int]) -> ((el+1), (f.rest))).[1; 2; 5; 4; 8; 7]");
Julien Lopez's avatar
Julien Lopez committed
319
320
    );

321
322
    "union" >:: ( fun test_ctxt ->
      assert_equal ~msg:"Test CDuce.runtime.union.identity failed"
323
	~printer:(fun x -> x) "Abstraction(([ Char* ] | Int, [ Char* ] | Int),{})"
324
	(run_test_eval "fun f x : (Int | String) : (Int | String) -> x");
325
      assert_equal ~msg:"Test CDuce.runtime.union.match failed"
326
	~printer:(fun x -> x) "Abstraction(([ Char* ] | Int, [ Char* ] | Int),{})"
327
	(run_test_eval "fun f x : (Int | String) : (Int | String) ->
328
329
330
331
332
                     match x : (Int | String) with
                       | x : Int -> 2
                       | x : String -> \"Piece of cake\"");
      assert_equal ~msg:"Test CDuce.runtime.union.match_applied failed"
	~printer:(fun x -> x) "2"
333
	(run_test_eval "(fun f x : (Int | String) : (Int | String) ->
334
335
336
337
338
                      match x : (Int | String) with
                        | x : Int -> 2
                        | x : String -> \"Piece of cake\").5");
      assert_equal ~msg:"Test CDuce.runtime.union.match_applied2 failed"
	~printer:(fun x -> x) "\"Piece of cake\""
339
	(run_test_eval "(fun f x : (Int | String) : (Int | String) ->
340
341
342
343
344
                      match x : (Int | String) with
                        | x : Int -> 2
                        | x : String -> \"Piece of cake\").\"test\"");
    );

345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
    "union_precise" >:: ( fun test_ctxt ->
      assert_equal ~msg:"Test CDuce.runtime.union_precise.identity failed"
	~printer:(fun x -> x) "Abstraction((Int, Int) ,([ Char* ], [ Char* ]),{})"
	(run_test_eval "fun ((Int -> Int) & (String -> String))
                          | x : (Int | String) -> x");
      assert_equal ~msg:"Test CDuce.runtime.union_precise.match failed"
	~printer:(fun x -> x) "Abstraction((Int, Int) ,([ Char* ], [ Char* ]),{})"
	(run_test_eval "fun ((Int -> Int) & (String -> String))
                          | x : Int -> 2
                          | x : String -> \"Piece of cake\"");
      assert_equal ~msg:"Test CDuce.runtime.union_precise.match_applied failed"
	~printer:(fun x -> x) "2"
	(run_test_eval "(fun ((Int -> Int) & (String -> String))
                           | x : Int -> 2
                           | x : String -> \"Piece of cake\").5");
      assert_equal ~msg:"Test CDuce.runtime.union_precise.match_applied2 failed"
	~printer:(fun x -> x) "\"Piece of cake\""
	(run_test_eval "(fun ((Int -> Int) & (String -> String))
                           | x : Int -> 2
                           | x : String -> \"Piece of cake\").\"test\"");
    );

367
    "poly" >:: ( fun test_ctxt ->
Julien Lopez's avatar
Julien Lopez committed
368
369
      assert_equal ~msg:"Test CDuce.runtime.poly.identity_pure failed"
	~printer:(fun x -> x)
370
371
	"Abstraction((`$A & Int | Char | Atom | (Any,Any) | <(Any) (Any)>Any | Arrow, 
`$A & Int | Char | Atom | (Any,Any) | <(Any) (Any)>Any | Arrow),{})"
372
	(run_test_eval "fun f x : 'A{} : 'A{} -> x");
373
      assert_equal ~msg:"Test CDuce.runtime.poly.identity failed"
374
	~printer:(fun x -> x)
375
	"Abstraction(([ Char* ] | Int, [ Char* ] | Int),{})"
376
	(run_test_eval "(fun f x : 'A{A/Int;A/String} : 'A{A/Int;A/String} -> x)
Julien Lopez's avatar
Julien Lopez committed
377
                   {A/Int;A/String}");
378
379
      assert_equal ~msg:"Test CDuce.runtime.poly.identity_applied failed"
	~printer:(fun x -> x) "2"
380
	(run_test_eval "((fun f x : 'A{A/Int;A/String} : 'A{A/Int;A/String} -> x)
Julien Lopez's avatar
Julien Lopez committed
381
                   {A/Int;A/String}).2");
382
383
      assert_equal ~msg:"Test CDuce.runtime.poly.identity_applied2 failed"
	~printer:(fun x -> x) "2"
384
	(run_test_eval "((fun f x : 'A{A/String} : 'A{A/String} -> x){A/String}).2");
Julien Lopez's avatar
Julien Lopez committed
385
386
      assert_equal ~msg:"Test CDuce.runtime.poly.tail failed"
	~printer:(fun x -> x)
387
388
389
	"Abstraction(([ (`$A & Int | Char | Atom | (Any,Any) | <(Any) (Any)>Any |
               Arrow)* ], [ (`$A & Int | Char | Atom | (Any,Any) |
                            <(Any) (Any)>Any | Arrow)* ]),{})"
390
	(run_test_eval "fun tail x : ['A{}] : ['A{}] -> match x : ['A{}] with
Julien Lopez's avatar
Julien Lopez committed
391
392
                     | (el : 'A{}) :: (rest : ['A{}]) -> rest");
      assert_equal ~msg:"Test CDuce.runtime.poly.tail_applied failed"
393
	~printer:(fun x -> x) "(7, (8, (5, Atom(nil), {}), {}), {})"
394
	(run_test_eval "(fun tail x : ['A{}] : ['A{}] -> match x : ['A{}] with
Julien Lopez's avatar
Julien Lopez committed
395
                     | (el : 'A{}) :: (rest : ['A{}]) -> rest).[3; 7; 8; 5]");
396

397
398
    );

399
400
  ]

Pietro Abate's avatar
Pietro Abate committed
401
402
403
404
let _ =
  run_test_tt_main (
    test_list
      [ tests_compile;
405
        tests_eval
Pietro Abate's avatar
Pietro Abate committed
406
407
408
409
      ]
  )
;;