summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_xpath_operators.cpp16
-rw-r--r--tests/test_xpath_parse.cpp5
-rw-r--r--tests/test_xpath_paths.cpp119
3 files changed, 140 insertions, 0 deletions
diff --git a/tests/test_xpath_operators.cpp b/tests/test_xpath_operators.cpp
index de18070..876e86a 100644
--- a/tests/test_xpath_operators.cpp
+++ b/tests/test_xpath_operators.cpp
@@ -402,4 +402,20 @@ TEST(xpath_operators_boolean_precedence)
CHECK_XPATH_BOOLEAN(c, "3 > (2 > 1)", true);
}
+TEST_XML(xpath_operators_union, "<node><employee/><employee secretary=''/><employee assistant=''/><employee secretary='' assistant=''/><employee assistant='' secretary=''/><tail/></node>")
+{
+ doc.precompute_document_order();
+
+ xml_node c;
+ xml_node n = doc.child("node");
+
+ CHECK_XPATH_NODESET(n, "employee | .") % 2 % 3 % 4 % 6 % 8 % 11;
+ CHECK_XPATH_NODESET(n, "employee[@secretary] | employee[@assistant]") % 4 % 6 % 8 % 11;
+ CHECK_XPATH_NODESET(n, "employee[@assistant] | employee[@secretary]") % 4 % 6 % 8 % 11;
+ CHECK_XPATH_NODESET(n, "employee[@secretary] | employee[@nobody]") % 4 % 8 % 11;
+ CHECK_XPATH_NODESET(n, "employee[@nobody] | employee[@secretary]") % 4 % 8 % 11;
+ CHECK_XPATH_NODESET(n, "tail/preceding-sibling::employee | .") % 2 % 3 % 4 % 6 % 8 % 11;
+ CHECK_XPATH_NODESET(n, ". | tail/preceding-sibling::employee | .") % 2 % 3 % 4 % 6 % 8 % 11;
+}
+
#endif
diff --git a/tests/test_xpath_parse.cpp b/tests/test_xpath_parse.cpp
index 5eb23b8..4595b3c 100644
--- a/tests/test_xpath_parse.cpp
+++ b/tests/test_xpath_parse.cpp
@@ -39,4 +39,9 @@ TEST(xpath_variables)
CHECK_XPATH_FAIL("$var"); // not implemented
}
+TEST(xpath_empty_expression)
+{
+ CHECK_XPATH_FAIL("");
+}
+
#endif
diff --git a/tests/test_xpath_paths.cpp b/tests/test_xpath_paths.cpp
index 5cc48c4..5b29309 100644
--- a/tests/test_xpath_paths.cpp
+++ b/tests/test_xpath_paths.cpp
@@ -302,6 +302,23 @@ TEST_XML_FLAGS(xpath_paths_nodetest_type, "<node attr='value'>pcdata<child/><?pi
CHECK_XPATH_FAIL("processing-instruction('', '')");
}
+TEST_XML(xpath_paths_absolute, "<node><foo><foo/><foo/></foo></node>")
+{
+ doc.precompute_document_order();
+
+ xml_node c;
+ xml_node n = doc.child("node");
+
+ CHECK_XPATH_NODESET(c, "/foo");
+ CHECK_XPATH_NODESET(n, "/foo");
+ CHECK_XPATH_NODESET(n, "/node/foo") % 3;
+ CHECK_XPATH_NODESET(n.child("foo"), "/node/foo") % 3;
+
+ CHECK_XPATH_NODESET(c, "/");
+ CHECK_XPATH_NODESET(n, "/") % 1;
+ CHECK_XPATH_NODESET(n.child("foo"), "/") % 1;
+}
+
TEST_XML(xpath_paths_step_abbrev, "<node><foo/></node>")
{
doc.precompute_document_order();
@@ -321,4 +338,106 @@ TEST_XML(xpath_paths_step_abbrev, "<node><foo/></node>")
CHECK_XPATH_FAIL("..node");
}
+TEST_XML(xpath_paths_relative_abbrev, "<node><foo><foo/><foo/></foo></node>")
+{
+ doc.precompute_document_order();
+
+ xml_node c;
+ xml_node n = doc.child("node");
+
+ CHECK_XPATH_NODESET(c, "foo//bar");
+
+ CHECK_XPATH_NODESET(n, "foo/foo") % 4 % 5;
+ CHECK_XPATH_NODESET(n, "foo//foo") % 4 % 5;
+ CHECK_XPATH_NODESET(n, ".//foo") % 3 % 4 % 5;
+}
+
+TEST_XML(xpath_paths_absolute_abbrev, "<node><foo><foo/><foo/></foo></node>")
+{
+ doc.precompute_document_order();
+
+ xml_node c;
+ xml_node n = doc.child("node");
+
+ CHECK_XPATH_NODESET(c, "//bar");
+
+ CHECK_XPATH_NODESET(n, "//foo") % 3 % 4 % 5;
+ CHECK_XPATH_NODESET(n.child("foo"), "//foo") % 3 % 4 % 5;
+ CHECK_XPATH_NODESET(doc, "//foo") % 3 % 4 % 5;
+}
+
+TEST_XML(xpath_paths_predicate_boolean, "<node><chapter/><chapter/><chapter/><chapter/><chapter/></node>")
+{
+ doc.precompute_document_order();
+
+ xml_node n = doc.child("node").child("chapter").next_sibling().next_sibling();
+
+ CHECK_XPATH_NODESET(n, "following-sibling::chapter[position()=1]") % 6;
+ CHECK_XPATH_NODESET(n, "following-sibling::chapter[position()=2]") % 7;
+ CHECK_XPATH_NODESET(n, "preceding-sibling::chapter[position()=1]") % 4;
+ CHECK_XPATH_NODESET(n, "preceding-sibling::chapter[position()=2]") % 3;
+}
+
+TEST_XML(xpath_paths_predicate_number, "<node><chapter/><chapter/><chapter/><chapter/><chapter/></node>")
+{
+ doc.precompute_document_order();
+
+ xml_node n = doc.child("node").child("chapter").next_sibling().next_sibling();
+
+ CHECK_XPATH_NODESET(n, "following-sibling::chapter[1]") % 6;
+ CHECK_XPATH_NODESET(n, "following-sibling::chapter[2]") % 7;
+ CHECK_XPATH_NODESET(n, "preceding-sibling::chapter[1]") % 4;
+ CHECK_XPATH_NODESET(n, "preceding-sibling::chapter[2]") % 3;
+}
+
+TEST_XML(xpath_paths_predicate_several, "<node><employee/><employee secretary=''/><employee assistant=''/><employee secretary='' assistant=''/><employee assistant='' secretary=''/></node>")
+{
+ doc.precompute_document_order();
+
+ xml_node n = doc.child("node");
+
+ CHECK_XPATH_NODESET(n, "employee") % 3 % 4 % 6 % 8 % 11;
+ CHECK_XPATH_NODESET(n, "employee[@secretary]") % 4 % 8 % 11;
+ CHECK_XPATH_NODESET(n, "employee[@assistant]") % 6 % 8 % 11;
+ CHECK_XPATH_NODESET(n, "employee[@secretary][@assistant]") % 8 % 11;
+ CHECK_XPATH_NODESET(n, "employee[@assistant][@secretary]") % 8 % 11;
+ CHECK_XPATH_NODESET(n, "employee[@secretary and @assistant]") % 8 % 11;
+}
+
+TEST_XML(xpath_paths_predicate_filter, "<node><chapter/><chapter/><chapter/><chapter/><chapter/></node>")
+{
+ doc.precompute_document_order();
+
+ xml_node n = doc.child("node").child("chapter").next_sibling().next_sibling();
+
+ CHECK_XPATH_NODESET(n, "(following-sibling::chapter)[1]") % 6;
+ CHECK_XPATH_NODESET(n, "(following-sibling::chapter)[2]") % 7;
+ CHECK_XPATH_NODESET(n, "(preceding-sibling::chapter)[1]") % 3;
+ CHECK_XPATH_NODESET(n, "(preceding-sibling::chapter)[2]") % 4;
+}
+
+TEST_XML(xpath_paths_step_compose, "<node><foo><foo/><foo/></foo><foo/></node>")
+{
+ doc.precompute_document_order();
+
+ xml_node n = doc.child("node");
+
+ CHECK_XPATH_NODESET(n, "(.)/foo") % 3 % 6;
+ CHECK_XPATH_NODESET(n, "(.)//foo") % 3 % 4 % 5 % 6;
+ CHECK_XPATH_NODESET(n, "(./..)//*") % 2 % 3 % 4 % 5 % 6;
+
+ CHECK_XPATH_FAIL("(1)/foo");
+ CHECK_XPATH_FAIL("(1)//foo");
+}
+
+TEST_XML(xpath_paths_descendant_double_slash_w3c, "<node><para><para/><para/><para><para/></para></para><para/></node>")
+{
+ doc.precompute_document_order();
+
+ CHECK_XPATH_NODESET(doc, "//para") % 3 % 4 % 5 % 6 % 7 % 8;
+ CHECK_XPATH_NODESET(doc, "/descendant::para") % 3 % 4 % 5 % 6 % 7 % 8;
+ CHECK_XPATH_NODESET(doc, "//para[1]") % 3 % 4 % 7;
+ CHECK_XPATH_NODESET(doc, "/descendant::para[1]") % 3;
+}
+
#endif