mirror of
https://github.com/zeux/pugixml.git
synced 2025-01-14 01:47:55 +08:00
tests: More coverage tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@225 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
c5d9752736
commit
0cac815b63
@ -1299,11 +1299,6 @@ namespace pugi
|
||||
return Cdouble()(lhs->eval_number(c), rhs->eval_number(c));
|
||||
else if (lhs->rettype() == ast_type_string || rhs->rettype() == ast_type_string)
|
||||
return Cstring()(lhs->eval_string(c), rhs->eval_string(c));
|
||||
else
|
||||
{
|
||||
assert(!"Wrong types");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (lhs->rettype() == ast_type_node_set && rhs->rettype() == ast_type_node_set)
|
||||
{
|
||||
@ -1349,11 +1344,6 @@ namespace pugi
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(!"Wrong types");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (lhs->rettype() == ast_type_node_set && rhs->rettype() != ast_type_node_set)
|
||||
{
|
||||
@ -1385,17 +1375,10 @@ namespace pugi
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(!"Wrong types");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(!"Wrong types");
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(!"Wrong types");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -38,4 +38,61 @@ TEST(xpath_allocator_large_page)
|
||||
CHECK_XPATH_NUMBER(xml_node(), ("string-length('" + query + "')").c_str(), 8192);
|
||||
}
|
||||
|
||||
TEST_XML(xpath_sort_complex, "<node><child1 attr1='value1' attr2='value2'/><child2 attr1='value1'>test</child2></node>")
|
||||
{
|
||||
// just some random union order, it should not matter probably?
|
||||
xpath_node_set ns = doc.child("node").select_nodes("child1 | child2 | child1/@* | . | child2/@* | child2/text()");
|
||||
|
||||
ns.sort(false);
|
||||
xpath_node_set sorted = ns;
|
||||
|
||||
ns.sort(true);
|
||||
xpath_node_set reverse_sorted = ns;
|
||||
|
||||
doc.precompute_document_order();
|
||||
|
||||
xpath_node_set_tester(sorted, "sorted order failed") % 2 % 3 % 4 % 5 % 6 % 7 % 8;
|
||||
xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 8 % 7 % 6 % 5 % 4 % 3 % 2;
|
||||
}
|
||||
|
||||
TEST_XML(xpath_sort_children, "<node><child><subchild id='1'/></child><child><subchild id='2'/></child></node>")
|
||||
{
|
||||
xpath_node_set ns = doc.child("node").select_nodes("child/subchild[@id=1] | child/subchild[@id=2]");
|
||||
|
||||
ns.sort(false);
|
||||
xpath_node_set sorted = ns;
|
||||
|
||||
ns.sort(true);
|
||||
xpath_node_set reverse_sorted = ns;
|
||||
|
||||
doc.precompute_document_order();
|
||||
|
||||
xpath_node_set_tester(sorted, "sorted order failed") % 4 % 7;
|
||||
xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 7 % 4;
|
||||
}
|
||||
|
||||
TEST_XML(xpath_sort_attributes, "<node/>")
|
||||
{
|
||||
xml_node n = doc.child("node");
|
||||
|
||||
// we need to insert attributes manually since unsorted node sets are (always?) sorted via pointers because of remove_duplicates,
|
||||
// so we need to have different document and pointer order to cover all comparator cases
|
||||
n.append_attribute("attr2");
|
||||
n.append_attribute("attr3");
|
||||
n.insert_attribute_before("attr1", n.attribute("attr2"));
|
||||
|
||||
xpath_node_set ns = n.select_nodes("@*");
|
||||
|
||||
ns.sort(true);
|
||||
xpath_node_set reverse_sorted = ns;
|
||||
|
||||
ns.sort(false);
|
||||
xpath_node_set sorted = ns;
|
||||
|
||||
doc.precompute_document_order();
|
||||
|
||||
xpath_node_set_tester(sorted, "sorted order failed") % 3 % 4 % 5;
|
||||
xpath_node_set_tester(reverse_sorted, "reverse sorted order failed") % 5 % 4 % 3;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -599,7 +599,7 @@ TEST_XML_FLAGS(xpath_nodeset_local_name, "<node xmlns:foo='http://foo'><c1>text<
|
||||
CHECK_XPATH_FAIL("local-name(c1, c2)");
|
||||
}
|
||||
|
||||
TEST_XML_FLAGS(xpath_nodeset_namespace_uri, "<node xmlns:foo='http://foo'><c1>text</c1><c2 xmlns:foo='http://foo2' foo:attr='value'><foo:child/></c2><c3 xmlns='http://def' attr='value'><child/></c3><c4><?target stuff?></c4><c5><foo:child/></c5></node>", parse_default | parse_pi)
|
||||
TEST_XML_FLAGS(xpath_nodeset_namespace_uri, "<node xmlns:foo='http://foo'><c1>text</c1><c2 xmlns:foo='http://foo2' foo:attr='value'><foo:child/></c2><c3 xmlns='http://def' attr='value'><child/></c3><c4><?target stuff?></c4><c5><foo:child/></c5><c6 bar:attr=''/></node>", parse_default | parse_pi)
|
||||
{
|
||||
xml_node c;
|
||||
xml_node n = doc.child("node");
|
||||
@ -621,6 +621,7 @@ TEST_XML_FLAGS(xpath_nodeset_namespace_uri, "<node xmlns:foo='http://foo'><c1>te
|
||||
CHECK_XPATH_STRING(n, "namespace-uri(c3)", "http://def");
|
||||
CHECK_XPATH_STRING(n, "namespace-uri(c3/@attr)", ""); // the namespace name for an unprefixed attribute name always has no value (Namespaces in XML 1.0)
|
||||
CHECK_XPATH_STRING(n, "namespace-uri(c3/child::node())", "http://def");
|
||||
CHECK_XPATH_STRING(n, "namespace-uri(c6/@bar:attr)", "");
|
||||
|
||||
// namespace-uri with 2 arguments
|
||||
CHECK_XPATH_FAIL("namespace-uri(c1, c2)");
|
||||
|
@ -44,4 +44,9 @@ TEST(xpath_empty_expression)
|
||||
CHECK_XPATH_FAIL("");
|
||||
}
|
||||
|
||||
TEST(xpath_lexer_error)
|
||||
{
|
||||
CHECK_XPATH_FAIL("!");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -463,4 +463,11 @@ TEST_XML(xpath_paths_descendant_double_slash_w3c, "<node><para><para/><para/><pa
|
||||
CHECK_XPATH_NODESET(doc, "/descendant::para[1]") % 3;
|
||||
}
|
||||
|
||||
TEST_XML(xpath_paths_needs_sorting, "<node><child/><child/><child><subchild/><subchild/></child></node>")
|
||||
{
|
||||
doc.precompute_document_order();
|
||||
|
||||
CHECK_XPATH_NODESET(doc, "(node/child/subchild)[2]") % 7;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user