Forgot to add unit_test.ml :(
[SXSI/xpathcomp.git] / unit_test.ml
1 (******************************************************************************)
2 (*  SXSI : XPath evaluator                                                    *)
3 (*  Kim Nguyen (Kim.Nguyen@nicta.com.au)                                      *)
4 (*  Copyright NICTA 2008                                                      *)
5 (*  Distributed under the terms of the LGPL (see LICENCE)                     *)
6 (******************************************************************************)
7
8 let collect_tags v =
9   let rec aux acc v = 
10     if Tree.Binary.is_node v 
11     then
12       let tag = Tree.Binary.tag v
13       in
14       let acc = aux (Ptset.add tag acc) (Tree.Binary.first_child v)
15       in
16         aux (Ptset.add tag acc) (Tree.Binary.next_sibling v)
17     else acc
18   in
19     aux Ptset.empty v
20 ;;
21
22
23 if Array.length (Sys.argv) <> 2
24 then
25   begin
26     Printf.printf "usage: %s file.xml\n" (Sys.argv.(0));
27     exit 1
28   end
29
30     
31 let doc = 
32   try
33     Tree.Binary.parse_xml_uri Sys.argv.(1) 
34   with
35     | _ ->
36         Printf.printf "Error parsing document\n";
37         exit 2
38 ;;
39 let _ = Tag.init (Tree.Binary.tag_pool doc)
40 ;;
41 let tags = (Ptset.add (Tag.tag "foo") (collect_tags doc))
42 ;;
43
44 let _ = Tree.Binary.test_xml_tree Format.std_formatter tags doc
45 ;;
46