OSDN Git Service

update abcIn
[happyabc/happyabc.git] / swflib / abcInTest.ml
1 open Base
2 open OUnit
3 open AbcType
4
5 let ok x y =
6   OUnit.assert_equal ~printer:Std.dump x y
7
8 module A = AbcIn.Make(struct
9                          type t = int
10                          let of_bytes _ =
11                            raise Stream.Failure
12                        end)
13
14 let example name =
15   let ch =
16     open_in_bin @@ Printf.sprintf "%s.abc" name in
17     A.of_bytes @@ BytesIn.of_channel ch
18
19 let abc =
20   example "hello"
21
22 let cpool =
23   abc.cpool
24
25 let _ =
26   ("asm module test" >::: [
27      "cpool" >::: [
28        "integer" >::
29          (fun () -> ok [] cpool.int);
30        "uinteger" >::
31          (fun () -> ok [] cpool.uint);
32        "double" >::
33          (fun () -> ok [] cpool.double);
34        "string" >::
35          (fun () -> ok [""; "Hello,world!!";"print"] cpool.string);
36 (* TODO *)
37 (*       "namespace" >::
38          (fun () ->
39             match cpool.namespace with
40                 [ns] ->
41                   ok (`Namespace 1l) ns
42               | _ ->
43                   assert_failure "list size is over");*)
44
45        "namespace set" >::
46          (fun () ->
47             ok [] cpool.namespace_set);
48        "multiname" >::
49          (fun () ->
50             assert_equal [QName (1,1);QName (1,3)]
51               cpool.multiname)
52      ];
53    "method signature" >::
54      (fun () ->
55         match abc.method_info with
56             [m] ->
57               ok [] m.params;
58               ok 0 m.return;
59               ok 1 m.method_name;
60               ok 0 m.method_flags;
61           | _   ->
62               assert_failure "over size");
63    "metadata test" >::
64      (fun () ->
65         ok [] abc.metadata);
66    "class and instance size has same size" >::
67      (fun () ->
68         ok (List.length abc.instances) (List.length abc.classes));
69    "instance" >::
70      (fun () ->
71         ok [] abc.instances);
72    "class" >::
73      (fun () ->
74         ok [] abc.classes);
75    "script" >::
76      (fun () ->
77         match abc.scripts with
78             [s] ->
79               ok 0 s.init;
80               ok [] s.script_traits
81           | _   ->
82               assert_failure "error");
83    "method body" >::
84      (fun () ->
85         match abc.method_bodies with
86             [m] ->
87               ok 0 m.method_sig;
88               ok [] m.exceptions;
89               ok 1 m.local_count;
90               ok 0 m.init_scope_depth;
91               ok 1 m.max_scope_depth;
92               ok 2 m.max_stack;
93               ok [] m.method_traits;
94               flip ok m.code [
95               ]
96           | _   ->
97               assert_failure "error");
98    ]) +> run_test_tt_main