Forgot to add unit_test.ml :(
authorkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Sun, 8 Mar 2009 08:13:40 +0000 (08:13 +0000)
committerkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Sun, 8 Mar 2009 08:13:40 +0000 (08:13 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/xpathcomp@219 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

unit_test.ml [new file with mode: 0644]

diff --git a/unit_test.ml b/unit_test.ml
new file mode 100644 (file)
index 0000000..e52c533
--- /dev/null
@@ -0,0 +1,46 @@
+(******************************************************************************)
+(*  SXSI : XPath evaluator                                                    *)
+(*  Kim Nguyen (Kim.Nguyen@nicta.com.au)                                      *)
+(*  Copyright NICTA 2008                                                      *)
+(*  Distributed under the terms of the LGPL (see LICENCE)                     *)
+(******************************************************************************)
+
+let collect_tags v =
+  let rec aux acc v = 
+    if Tree.Binary.is_node v 
+    then
+      let tag = Tree.Binary.tag v
+      in
+      let acc = aux (Ptset.add tag acc) (Tree.Binary.first_child v)
+      in
+       aux (Ptset.add tag acc) (Tree.Binary.next_sibling v)
+    else acc
+  in
+    aux Ptset.empty v
+;;
+
+
+if Array.length (Sys.argv) <> 2
+then
+  begin
+    Printf.printf "usage: %s file.xml\n" (Sys.argv.(0));
+    exit 1
+  end
+
+    
+let doc = 
+  try
+    Tree.Binary.parse_xml_uri Sys.argv.(1) 
+  with
+    | _ ->
+       Printf.printf "Error parsing document\n";
+       exit 2
+;;
+let _ = Tag.init (Tree.Binary.tag_pool doc)
+;;
+let tags = (Ptset.add (Tag.tag "foo") (collect_tags doc))
+;;
+
+let _ = Tree.Binary.test_xml_tree Format.std_formatter tags doc
+;;
+