diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_xpath.cpp | 22 | ||||
-rw-r--r-- | tests/test_xpath_api.cpp | 26 | ||||
-rw-r--r-- | tests/test_xpath_functions.cpp | 5 |
3 files changed, 51 insertions, 2 deletions
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, "<node>5</node>") +{ + 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, "<node>5</node>") +{ + 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, "<node><foo/><foo/></node>") xpath_node_set nullcopy = null; } +TEST_XML(xpath_api_nodeset_copy, "<node><foo/><foo/></node>") +{ + 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, "<node attr='3'/>") { 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, "<node xml:lang='en'><child xml:lang='ru-UK'><subch CHECK_XPATH_FAIL(STR("lang(1, 2)")); } -TEST_XML(xpath_string_string, "<node>123<child id='1'>789</child><child><![CDATA[200]]></child>100</node>") +TEST_XML(xpath_string_string, "<node>123<child id='1'>789</child><child><subchild><![CDATA[200]]></subchild></child>100</node>") { xml_node c; xml_node n = doc.child(STR("node")); @@ -629,7 +629,7 @@ TEST_XML_FLAGS(xpath_nodeset_local_name, "<node xmlns:foo='http://foo'><c1>text< CHECK_XPATH_FAIL(STR("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><c6 bar:attr=''/></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=''/><c7><node foo:attr=''/></c7></node>", 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, "<node xmlns:foo='http://foo'><c1>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)")); |