(: CSC 468 :) (: Fall 2013 :) (: Project Stage 3 :) (: test queries for "unit-testing" your XPLite implementation (: note: not all features can be unit-tested. (: For example, implementations of built-in functions (: can be unit-tested only if we validate at least one non-trivial (: axis (: So, really, this is a test script for differential testing of your XPLite (: implementation (: This set of XPLite queries is to be performed on an XML repository constructed in one of the (: following ways: (: 1. moneyrepository.xml file (: 2. moneyrepository1.xml file (: 3. moneyrepository1.xml and moneyrepository2.xml files (: 4. moneyrepository1.xml, moneyrepsoitory2.xml and moneyrepository-duplicates.xml files (: Note: this set of tests does not test attribute axes and attribute node tests. (: Test individual axes (: 1. get the root node /self::node() (: 1.b variant /self::* (: 2. Get the root node, test the name node test /self::repository (:3. get all child nodes of the root: returns 16 nodes /child::node() (:3.b /child::* (:3.c /child::currency (:4. get all grandchildren of the root: returns 16
, 16 , 16 and 16 nodes /child::node()/child::node() (:5. get only the specified grandchildren of the root /child::node()/child::amount (:5.b variant /child::currency/child::amount (:6. check the parent axis. Should retrieve the same answer as query 3. /child::node()/child::node()/parent::node() (:6.a variant /child:currency/child::amount/parent::currency (:6.b variant /child:currency/child::node()/parent::currency (:7. descendant axis (+ name node test) /descendant::unit (:8. find ancestors of the year element (mint, origin, currency) /descendant::year/ancestor::* (:9. one more ancestor test: returns just the origin element /descendant::year/ancestor::origin (:10 Longer chain of location steps /self::repository/child::currency/child::origin/child::mint/ancestor::currency/descendant::unit (:11 One more chain of location steps without predicates /descendant::year/parent::mint/parent::origin/parent::*/child::*/descendant::denom (:12. text() node test. Returns paper, coin, country, city, year, denom, unit and valid. (:(: note, that coin is returned (although it does not have text content. (:(: this is because it IS a leaf node. /descendant::text() (:13 text() node test in the middle of a query. Returns elements that are leaves (all of them) /descendant::text()/self::unit/parent::*/child::denom/self::text() (:14. Predicates. a simple XPath expression. Find all elements that have children. /self::repository/descendant::node()[child::node()] (:15. Predicates. XPath expression. Find a node that has year as a grandchild. /self::repository/descendant::*[child::*/child::year] (:16. Predicates. functions. position(). equality. First child of the root /self::repository/child::currency[position()=1] (:16.a. variant /child::*[position()=1] (:17. Predicates. functions. position(). last(). equality. Last child of the root /self::repository/child::currency[position()=last()] (:17.a. variant /child::*[position() = last()] (:18. Predicates. functions. position(). Middle of the pack /self::repository/child::currency[position()=8] (:18.a. variant /child::*[position() = 8] (:19. Predicates. functions. string() with no parameter. equality. (: Find the element whose content is "Franc" /descendant::*[string() = "Franc"] (:20 Predicatees. Functions. string() with no parameter. equality. (: Find all money from Belgium /descendant::currency/child::origin/child::country[string()="Belgium"]/ancestor::currency (: 21. Predicates. Nested predicates. string() with no parameter. equality. (: Same query as 20. /descendant::currency[child::/origin/child::country[string()="Belgium"]] (: 22. Predicates. string() with with parameter. equality. (: Same query as 20. /descendant::currency[string(child::origin/child::country)="Belgium"] (: 23. Predicates. string() with with parameter. equality. (: Find the denominations of all invalid money /self::repository/child::currency[string(child::valid)="No"]/child::amount/child::denom (: 23.a. variant /descendant::currency[string(child::valid)="No"]/descendant::denom (:24. Predicates. functions. count(). equality. Find elements with two children. (: , elements /descendant::*[count(child::*)= 2] (:24. predicates, functions, not() (: finds all XML nodes with no children /descendant::node()[not(child::*)] (:24.a variant: this is equivalent to the text() node test /descendant::text() (:25. predicates, functions, not(), true(), boolean equality (: finds all XML nodes with no children /descendant::node[not(child::*) = true()] (:26. predicates, functions, not(), false(), boolean equality (: all the nodes that DO have children /descendant::node[not(child::*) = false()] (:27. predicates, functions, position, operations, equality /descendant::currency[position() = 3] (:28. predicates, functions, position, operations, inequality /descendant::currency[position() <> 3] (:29. predicates, functions, position, operations, less than /descendant::currencu[position() < 3] (:30. predicates, functions, position, operations, less than or equal to /descendant::currency[position() <= 3] (:31. predicates, functions, position, operations, greater than /descendant::currency[position() > 12] (:32. predicates, functions, position, operations, greater than or equal to /descendant::currency[position() >= 12]/child::amount (: 33. predicates. functions. contains() (: find all money denominations that contian "00" /descendant::denom[contains(self::text(),"00")]/ancestor::currency (:34. predicates, multiple predicates /descendant::currency[position()<= 5][position() >= 3] (:35. predicates, multiple predicates /descendant::currency[position()<= 5][position() >= 3][child::country[string() <> "Canada"]] (:36. predicates, multiple predicates /descendant::currency[position()<= 10][position() >= 3][string(descendant::year) > 1995][child::form/child::paper] (:37. predicates, multiple predicates, multiple location steps /descendant::currency[position()<= 10][position() >= 3]/child::form[child::paper]/parent::*/child::*[position()<3][string()<>"France"] (: (: AND WE ARE DONE! (: