#!/bin/csh

# CSC 468
# Winter 2009
# Project Stage 3

# test script for "unit-testing" your XPLite implementation

# note: not all features can be unit-tested.
# For example, implementations of built-in functions will
# 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



#
#  please edit the lines of the script to make sure that your program will run
#
#  e.g., replace java XpathPlus with  java -cp .:neustore.jar  


# list all repositories, make certain things are fine
java XpathPlus  LIST


# Test individual axes

# 1. get the root node
echo "document(\"coin\")/self::node()"
java XpathPlus RETURN document("coin")/self::node()

# 2. get all child nodes of the root
echo "document(\"coin\")/child::node()"
java XpathPlus RETURN document("coin")/child::node()

#3. get all grandchildren of the root
echo "document(\"coin\")/child::node()/child::node()"
java XpathPlus RETURN document("coin")/child::node()/child::node()

#4. check the parent axis. Should retrieve the same answer as query 2.
echo "document(\"coin\")/child::node()/child::node()/parent::node()"
java XpathPlus RETURN document("coin")/child::node()/child::node()/parent::node()

#5. Name Node Test. Retrieve amount information
echo "document(\"coin\")/child::amount"
java XpathPlus RETURN document("coin")/child::amount


#6. "*" wildcard Retrieve children of amount using the "*" wildcard
echo "document(\"coin\")/child::amount" 
java XpathPlus RETURN document("coin")/child::amount/child::*


#7. descendant axis.  Get the units out
echo "document(\"coin\")/descendant::unit" 
java XpathPlus RETURN document("coin")/descendant::unit

#8. find ancestors of the year element (mint, origin, currency)
echo "document(\"coin\")/descendant::year/ancestor::*" 
java XpathPlus RETURN document("coin")/descendant::year/ancestor::*

#9. one more ancestor test: returns just the origin element
echo "document(\"coin\")/descendant::year/ancestor::*" 
java XpathPlus RETURN document("coin")/descendant::year/ancestor::origin

#10. Preceding sibling. Should return city element.
echo "document(\"coin\")/descendant::year/preceding-sibling::node()" 
java XpathPlus RETURN document("coin")/descendant::year/preceding-sibling::node()


#11. Following sibling. Should return year element.
echo "document(\"coin\")/descendant::city/following-sibling::node()" 
java XpathPlus RETURN document("coin")/descendant::city/following-sibling::node()

#12. Preceding. Should return mint, form and coin.
echo "document(\"coin\")/descendant::mint/preceding::node()" 
java XpathPlus RETURN document("coin")/descendant::mint/preceding::node()

#13. Following. Should return  amount, denom, unit and valid.
echo "document(\"coin\")/descendant::year/following::node()" 
java XpathPlus RETURN document("coin")/descendant::year/following::node()

#14. text() node test. Returns coin, country, city, year, denom, unit and valid.
##   note, that coin is return (although it does not have text content.
##   this is because it IS a leaf node.
echo "document(\"coin\")/descendant::text()"
java XpathPlus RETURN document("coin")/descendant::text()

#15. Predicates. a simple XPath expression. Find all elements that have children.
echo "document(\"coin\")/descendant::node()[child::node()]"
java XpathPlus RETURN document("coin")/descendant::node()[child::node()]

#16. Predicates. XPath expression. Find a node that has year as a grandchild.
echo "document(\"coin\")/child::*[child::*/child::year]"
java XpathPlus RETURN document("coin")/child::*[child::*/child::year]

#17. Predicates. functions. position(). equality. First child of the root
echo "document(\"coin\")/child::*[position() = 1]"
java XpathPlus RETURN document("coin")/child::*[position()=1]

#18. Predicates. functions. position(). last(). equality. Last child of the root
echo "document(\"coin\")/child::*[position() = last()]"
java XpathPlus RETURN document("coin")/child::*[position() = last()]

#19. Predicates. functions. text(). equality. 
#    Find the element whose content is "Denver"
echo "document(\"coin\")/descendant::*[text() = \"Denver\"]"
java XpathPlus RETURN document("coin")/descendant::*[text() = "Denver"]

#20. Predicates. functions. count(). equality. Find elements with two children.
echo "document(\"coin\")/descendant::*[count(child::*) = 2]"
java XpathPlus RETURN document("coin")/descendant::*[count(child::*)= 2]










#
# AND WE ARE DONE!
#























