OSDN Git Service

update swf header
[happyabc/happyabc.git] / swflib / cpoolTest.ml
1 open Base
2 open Cpool
3 open BytesOut
4 open OUnit
5 open AbcType
6
7 let empty_cpool =
8   { AbcType.int       = [];
9     uint          = [];
10     double        = [];
11     string        = [];
12     namespace     = [];
13     namespace_set = [];
14     multiname     = []}
15
16 let test_index value =
17   let cpool =
18     Cpool.add Cpool.empty value in
19     assert_equal 1 (Cpool.index cpool value)
20
21 let ok cpool value =
22   assert_equal cpool (to_abc @@ Cpool.add Cpool.empty value)
23
24 let _ =
25   ("cpool.ml" >::: [
26      "int" >::
27        (fun () ->
28           test_index (`Int 42);
29           test_index (`Int ~-42));
30      "uint" >::
31        (fun () ->
32           test_index (`UInt 42));
33      "string" >::
34        (fun () ->
35           test_index (`String "foobar"));
36      "multiname" >::
37        (fun () ->
38           test_index (`QName ((`Namespace "std"),"print"));
39           test_index (`Multiname ("print",[]));
40           test_index (`Multiname ("print",[`Namespace "std"])));
41      "literal cpool" >::
42        (fun () ->
43           ok {empty_cpool with string=["foobar"]} (`String "foobar");
44           ok {empty_cpool with int=[30]} (`Int 30);
45           ok {empty_cpool with int=[~-30]} (`Int ~-30);
46           ok {empty_cpool with uint=[42]} (`UInt 42));
47      "qname cpool" >::
48        (fun () ->
49           ok
50             {empty_cpool with
51                string = ["foobar"; "std"];
52                namespace  = [AbcType.Namespace 2];
53                multiname  = [QName (1,1)]}
54             (`QName (`Namespace "std","foobar")));
55      "multiname cpool" >::
56        (fun () ->
57           ok
58             {empty_cpool with
59                string   = ["std";"foobar"];
60                namespace    = [AbcType.Namespace 1];
61                namespace_set= [[1]];
62                multiname=[Multiname (2,1)]}
63             (`Multiname ("foobar",[`Namespace "std"])));
64      "cpool entry should be unique" >::
65        (fun () ->
66           let cpool =
67             Cpool.add_list empty
68               [`String "foo"; `String "bar"; `String "foo"] in
69             assert_equal 1 (Cpool.index cpool (`String "foo"));
70             assert_equal {empty_cpool with string=["foo";"bar"]} @@
71               to_abc cpool);
72      "index is not change" >::
73        (fun () ->
74           let cpool1 =
75             Cpool.add empty (`Int 42) in
76           let cpool2 =
77             Cpool.add  cpool1 (`Int 42) in
78             assert_equal
79               (Cpool.index cpool1 @@ `Int 42)
80               (Cpool.index cpool2 @@ `Int 42))
81    ]) +> run_test_tt_main