From deb9e8bc74e67ec14a39dd977afbfe345d5586f6 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Wed, 4 Aug 2010 14:15:46 +0000 Subject: tests: Added more XPath tests git-svn-id: http://pugixml.googlecode.com/svn/trunk@628 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_xpath.cpp | 22 ++++++++++++++++++++++ tests/test_xpath_api.cpp | 26 ++++++++++++++++++++++++++ tests/test_xpath_functions.cpp | 5 +++-- 3 files changed, 51 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index 29e7244..bfa4fed 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -272,4 +272,26 @@ TEST(xpath_document_order) CHECK(xml_attribute().document_order() == 0); CHECK(xml_node().document_order() == 0); } + +TEST_XML(xpath_context_node, "5") +{ + CHECK_XPATH_NODESET(doc, STR("node")) % 2; + CHECK_XPATH_BOOLEAN(doc, STR("node"), true); + CHECK_XPATH_NUMBER(doc, STR("node"), 5); + CHECK_XPATH_STRING(doc, STR("node"), STR("5")); +} + +TEST_XML(xpath_context_position, "5") +{ + CHECK_XPATH_NODESET(doc, STR("id(position() + last())")); + CHECK_XPATH_BOOLEAN(doc, STR("position() + last() = 2"), true); + CHECK_XPATH_NUMBER(doc, STR("position() + last()"), 2); + CHECK_XPATH_STRING(doc, STR("position() + last()"), STR("2")); +} + +TEST(xpath_lexer_unknown_lexeme) +{ + CHECK_XPATH_FAIL(STR("(^3))")); + CHECK_XPATH_FAIL(STR("(!3))")); +} #endif diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp index bf35b62..ad05083 100644 --- a/tests/test_xpath_api.cpp +++ b/tests/test_xpath_api.cpp @@ -114,6 +114,32 @@ TEST_XML(xpath_api_nodeset_accessors, "") xpath_node_set nullcopy = null; } +TEST_XML(xpath_api_nodeset_copy, "") +{ + xpath_node_set set = doc.select_nodes(STR("node/foo")); + + xpath_node_set copy1 = set; + CHECK(copy1.size() == 2); + CHECK_STRING(copy1[0].node().name(), STR("foo")); + + xpath_node_set copy2; + copy2 = set; + CHECK(copy2.size() == 2); + CHECK_STRING(copy2[0].node().name(), STR("foo")); + + xpath_node_set copy3; + copy3 = set; + copy3 = copy3; + CHECK(copy3.size() == 2); + CHECK_STRING(copy3[0].node().name(), STR("foo")); + + xpath_node_set copy4; + copy4 = set; + copy4 = copy1; + CHECK(copy4.size() == 2); + CHECK_STRING(copy4[0].node().name(), STR("foo")); +} + TEST_XML(xpath_api_evaluate, "") { xpath_query q(STR("node/@attr")); diff --git a/tests/test_xpath_functions.cpp b/tests/test_xpath_functions.cpp index 3eb69c6..1d533b7 100644 --- a/tests/test_xpath_functions.cpp +++ b/tests/test_xpath_functions.cpp @@ -248,7 +248,7 @@ TEST_XML(xpath_boolean_lang, "123789100") +TEST_XML(xpath_string_string, "123789100") { xml_node c; xml_node n = doc.child(STR("node")); @@ -629,7 +629,7 @@ TEST_XML_FLAGS(xpath_nodeset_local_name, "text< CHECK_XPATH_FAIL(STR("local-name(c1, c2)")); } -TEST_XML_FLAGS(xpath_nodeset_namespace_uri, "text", parse_default | parse_pi) +TEST_XML_FLAGS(xpath_nodeset_namespace_uri, "text", parse_default | parse_pi) { xml_node c; xml_node n = doc.child(STR("node")); @@ -652,6 +652,7 @@ TEST_XML_FLAGS(xpath_nodeset_namespace_uri, "te CHECK_XPATH_STRING(n, STR("namespace-uri(c3/@attr)"), STR("")); // the namespace name for an unprefixed attribute name always has no value (Namespaces in XML 1.0) CHECK_XPATH_STRING(n, STR("namespace-uri(c3/child::node())"), STR("http://def")); CHECK_XPATH_STRING(n, STR("namespace-uri(c6/@bar:attr)"), STR("")); + CHECK_XPATH_STRING(n, STR("namespace-uri(c7/node/@foo:attr)"), STR("http://foo")); // namespace-uri with 2 arguments CHECK_XPATH_FAIL(STR("namespace-uri(c1, c2)")); -- cgit v1.2.3