From: kim Date: Sun, 8 Mar 2009 08:13:40 +0000 (+0000) Subject: Forgot to add unit_test.ml :( X-Git-Url: http://git.nguyen.vg/gitweb/?a=commitdiff_plain;ds=sidebyside;h=5cc0fe57953445af433b00023e5f4b6c1d0fe549;hp=eda0e1062076c3343ab0cfdc10e4d19d6e23c570;p=SXSI%2Fxpathcomp.git Forgot to add unit_test.ml :( git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/xpathcomp@219 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- diff --git a/unit_test.ml b/unit_test.ml new file mode 100644 index 0000000..e52c533 --- /dev/null +++ b/unit_test.ml @@ -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 +;; +