From 6948d1f171e02558a846e63aa58ffc06547eba87 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Wed, 4 Nov 2009 19:23:20 +0000 Subject: tests: Completed function library tests, added namespace axis and variable reference tests git-svn-id: http://pugixml.googlecode.com/svn/trunk@204 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_xpath_functions.cpp | 128 +++++++++++++++++++++++++++++++++++++++++ tests/test_xpath_parse.cpp | 6 +- tests/test_xpath_paths.cpp | 7 +++ 3 files changed, 140 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_xpath_functions.cpp b/tests/test_xpath_functions.cpp index e098813..e34fac1 100644 --- a/tests/test_xpath_functions.cpp +++ b/tests/test_xpath_functions.cpp @@ -498,6 +498,41 @@ TEST(xpath_string_translate) CHECK_XPATH_FAIL("translate('a', 'b', 'c', 'd')"); } +TEST_XML(xpath_nodeset_last, "") +{ + doc.precompute_document_order(); + + xml_node n = doc.child("node"); + + // last with 0 arguments + CHECK_XPATH_NUMBER(n, "last()", 1); + CHECK_XPATH_NODESET(n, "c1[last() = 1]"); + CHECK_XPATH_NODESET(n, "c1[last() = 2]") % 3 % 4; // c1, c1 + CHECK_XPATH_NODESET(n, "c2/preceding-sibling::node()[last() = 2]") % 4 % 3; // c1, c1 + + // last with 1 argument + CHECK_XPATH_FAIL("last(c)"); +} + +TEST_XML(xpath_nodeset_position, "") +{ + doc.precompute_document_order(); + + xml_node n = doc.child("node"); + + // position with 0 arguments + CHECK_XPATH_NUMBER(n, "position()", 1); + CHECK_XPATH_NODESET(n, "c1[position() = 0]"); + CHECK_XPATH_NODESET(n, "c1[position() = 1]") % 3; + CHECK_XPATH_NODESET(n, "c1[position() = 2]") % 4; + CHECK_XPATH_NODESET(n, "c1[position() = 3]"); + CHECK_XPATH_NODESET(n, "c2/preceding-sibling::node()[position() = 1]") % 4; + CHECK_XPATH_NODESET(n, "c2/preceding-sibling::node()[position() = 2]") % 3; + + // position with 1 argument + CHECK_XPATH_FAIL("position(c)"); +} + TEST_XML(xpath_nodeset_count, "") { xml_node c; @@ -537,6 +572,83 @@ TEST_XML(xpath_nodeset_id, "") CHECK_XPATH_FAIL("id(1, 2)"); } +TEST_XML_FLAGS(xpath_nodeset_local_name, "text", parse_default | parse_pi) +{ + xml_node c; + xml_node n = doc.child("node"); + + // local-name with 0 arguments + CHECK_XPATH_STRING(c, "local-name()", ""); + CHECK_XPATH_STRING(n, "local-name()", "node"); + + // local-name with 1 non-node-set argument + CHECK_XPATH_FAIL("local-name(1)"); + + // local-name with 1 node-set argument + CHECK_XPATH_STRING(n, "local-name(c1)", "c1"); + CHECK_XPATH_STRING(n, "local-name(c2/node())", "child"); + CHECK_XPATH_STRING(n, "local-name(c2/attribute::node())", "attr"); + CHECK_XPATH_STRING(n, "local-name(c1/node())", ""); + CHECK_XPATH_STRING(n, "local-name(c4/node())", "target"); + CHECK_XPATH_STRING(n, "local-name(c1/following-sibling::node())", "c2"); + CHECK_XPATH_STRING(n, "local-name(c4/preceding-sibling::node())", "c1"); + + // local-name with 2 arguments + CHECK_XPATH_FAIL("local-name(c1, c2)"); +} + +TEST_XML_FLAGS(xpath_nodeset_namespace_uri, "text", parse_default | parse_pi) +{ + xml_node c; + xml_node n = doc.child("node"); + + // namespace-uri with 0 arguments + CHECK_XPATH_STRING(c, "namespace-uri()", ""); + CHECK_XPATH_STRING(n.child("c2").child("foo:child"), "namespace-uri()", "http://foo2"); + + // namespace-uri with 1 non-node-set argument + CHECK_XPATH_FAIL("namespace-uri(1)"); + + // namespace-uri with 1 node-set argument + CHECK_XPATH_STRING(n, "namespace-uri(c1)", ""); + CHECK_XPATH_STRING(n, "namespace-uri(c5/child::node())", "http://foo"); + CHECK_XPATH_STRING(n, "namespace-uri(c2/attribute::node())", "http://foo2"); + CHECK_XPATH_STRING(n, "namespace-uri(c2/child::node())", "http://foo2"); + CHECK_XPATH_STRING(n, "namespace-uri(c1/child::node())", ""); + CHECK_XPATH_STRING(n, "namespace-uri(c4/child::node())", ""); + 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"); + + // namespace-uri with 2 arguments + CHECK_XPATH_FAIL("namespace-uri(c1, c2)"); +} + +TEST_XML_FLAGS(xpath_nodeset_name, "text", parse_default | parse_pi) +{ + xml_node c; + xml_node n = doc.child("node"); + + // name with 0 arguments + CHECK_XPATH_STRING(c, "name()", ""); + CHECK_XPATH_STRING(n, "name()", "node"); + + // name with 1 non-node-set argument + CHECK_XPATH_FAIL("name(1)"); + + // name with 1 node-set argument + CHECK_XPATH_STRING(n, "name(c1)", "c1"); + CHECK_XPATH_STRING(n, "name(c2/node())", "foo:child"); + CHECK_XPATH_STRING(n, "name(c2/attribute::node())", "foo:attr"); + CHECK_XPATH_STRING(n, "name(c1/node())", ""); + CHECK_XPATH_STRING(n, "name(c4/node())", "target"); + CHECK_XPATH_STRING(n, "name(c1/following-sibling::node())", "c2"); + CHECK_XPATH_STRING(n, "name(c4/preceding-sibling::node())", "c1"); + + // name with 2 arguments + CHECK_XPATH_FAIL("name(c1, c2)"); +} + TEST(xpath_function_arguments) { xml_node c; @@ -572,4 +684,20 @@ TEST(xpath_function_arguments) CHECK_XPATH_FAIL("substring(1 2)"); } +TEST_XML_FLAGS(xpath_string_value, "pcdata", parse_default | parse_pi | parse_comments) +{ + xml_node c; + xml_node n = doc.child("node"); + + CHECK_XPATH_STRING(c, "string()", ""); + CHECK_XPATH_STRING(doc, "string()", "pcdatacdata"); + CHECK_XPATH_STRING(n, "string()", "pcdatacdata"); + CHECK_XPATH_STRING(n, "string(c1/node())", "pcdata"); + CHECK_XPATH_STRING(n, "string(c2/node())", ""); + CHECK_XPATH_STRING(n, "string(c3/@attr)", "avalue"); + CHECK_XPATH_STRING(n, "string(c4/node())", "pivalue"); + CHECK_XPATH_STRING(n, "string(c5/node())", "comment"); + CHECK_XPATH_STRING(n, "string(c6/node())", "cdata"); +} + #endif diff --git a/tests/test_xpath_parse.cpp b/tests/test_xpath_parse.cpp index 6d9a4e7..5eb23b8 100644 --- a/tests/test_xpath_parse.cpp +++ b/tests/test_xpath_parse.cpp @@ -29,10 +29,14 @@ TEST(xpath_number_parse) TEST(xpath_number_error) { - xml_node c; CHECK_XPATH_FAIL("123a"); CHECK_XPATH_FAIL("123.a"); CHECK_XPATH_FAIL(".123a"); } +TEST(xpath_variables) +{ + CHECK_XPATH_FAIL("$var"); // not implemented +} + #endif diff --git a/tests/test_xpath_paths.cpp b/tests/test_xpath_paths.cpp index 31704df..e44045d 100644 --- a/tests/test_xpath_paths.cpp +++ b/tests/test_xpath_paths.cpp @@ -136,6 +136,13 @@ TEST_XML(xpath_paths_axes_attribute, "") +{ + xml_node n = doc.child("node"); + + CHECK_XPATH_NODESET(n, "namespace:: node()"); // namespace nodes are not supported +} + TEST_XML(xpath_paths_axes_self, "") { doc.precompute_document_order(); -- cgit v1.2.3