From ff19e9475a90d44961b02717ca57c07f44b0003c Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sat, 29 May 2010 09:01:10 +0000 Subject: tests: Added more XPath tests git-svn-id: http://pugixml.googlecode.com/svn/trunk@458 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_xpath.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++ tests/test_xpath_operators.cpp | 2 + 2 files changed, 85 insertions(+) (limited to 'tests') diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index e2c5edb..6f7f756 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -127,4 +127,87 @@ TEST(xpath_long_numbers_stringize) #endif } +TEST_XML(xpath_rexml_1, "") +{ + CHECK_XPATH_NODESET(doc, STR("//*[local-name()='c' and @id='b']")) % 6; + CHECK_XPATH_NODESET(doc, STR("//*[ local-name()='c' and @id='b' ]")) % 6; + CHECK_XPATH_NODESET(doc, STR("/a/c[@id]")) % 6; + CHECK_XPATH_NODESET(doc, STR("/a/c[(@id)]")) % 6; + CHECK_XPATH_NODESET(doc, STR("/a/c[ @id ]")) % 6; + CHECK_XPATH_NODESET(doc, STR("/a/c[ (@id) ]")) % 6; + CHECK_XPATH_NODESET(doc, STR("/a/c[( @id )]")) % 6; + CHECK_XPATH_NODESET(doc, STR("/a/c[ ( @id ) ]")) % 6; + CHECK_XPATH_NODESET(doc, STR("/a/c [ ( @id ) ] ")) % 6; + CHECK_XPATH_NODESET(doc, STR(" / a / c [ ( @id ) ] ")) % 6; +} + +TEST_XML(xpath_rexml_2, "zzz") +{ + CHECK_XPATH_NODESET(doc, STR("a:x/a:y[@p='p' and @q='q']/a:z/text()")) % 8; +} + +TEST_XML(xpath_rexml_3, "
free flowing text.
free flowing text.
free flowing text.
") +{ + CHECK_XPATH_NODESET(doc, STR("//section[../self::section[@role=\"division\"]]")) % 10 % 15; + CHECK_XPATH_NODESET(doc, STR("//section[@role=\"subdivision\" and not(../self::section[@role=\"division\"])]")) % 3; + CHECK_XPATH_NODESET(doc, STR("//section[@role=\"subdivision\"][not(../self::section[@role=\"division\"])]")) % 3; +} + +TEST_XML_FLAGS(xpath_rexml_4, "TEXT1TEXT2", parse_default | parse_comments) +{ + CHECK_XPATH_NODESET(doc, STR("/descendant-or-self::node()[count(child::node()|following-sibling::node()|preceding-sibling::node())=0]")) % 6 % 17 % 20; +} + +TEST_XML(xpath_rexml_5, "") +{ + CHECK_XPATH_FAIL(STR(".//[@id]")); + CHECK_XPATH_NODESET(doc, STR(".//self::*[@id]")) % 4 % 6; + CHECK_XPATH_NODESET(doc, STR(".//node()[@id]")) % 4 % 6; +} + +TEST_XML(xpath_rexml_6, "
ab
") +{ + CHECK_XPATH_NODESET(doc, STR("//em|//strong")) % 4 % 6; + CHECK_XPATH_NODESET(doc, STR("//*[self::em | self::strong]")) % 4 % 6; + CHECK_XPATH_NODESET(doc, STR("//*[name()=\"em\" or name()=\"strong\"]")) % 4 % 6; + CHECK_XPATH_NODESET(doc, STR("//*[self::em or self::strong]")) % 4 % 6; +} + +TEST_XML(xpath_xsl_list_1, "whatevertextselectsomething") +{ + // if I'm not last, and the next input/type isn't select + CHECK_XPATH_NODESET(doc, STR("input[type[parent::input/following-sibling::input[1]/type != 'select']]")) % 2 % 8; + CHECK_XPATH_NODESET(doc, STR("input[type[../following-sibling::input[1]/type != 'select']]")) % 2 % 8; + + CHECK_XPATH_NODESET(doc, STR("input[position()+1]")); +} + +TEST_XML(xpath_xsl_list_2, "text1text2text3text4") +{ + CHECK_XPATH_FAIL(STR(".[not(.=ancestor::TR/TD[15]/node())]")); + + CHECK_XPATH_NODESET(doc.child("TR").find_child_by_attribute("TD", "id", "1").first_child(), STR("self::node()[not(.=ancestor::TR/TD[3]/node())]")) % 5; + CHECK_XPATH_NODESET(doc.child("TR").find_child_by_attribute("TD", "id", "2").first_child(), STR("self::node()[not(.=ancestor::TR/TD[3]/node())]")) % 8; + CHECK_XPATH_NODESET(doc.child("TR").find_child_by_attribute("TD", "id", "3").first_child(), STR("self::node()[not(.=ancestor::TR/TD[3]/node())]")); + CHECK_XPATH_NODESET(doc.child("TR").find_child_by_attribute("TD", "id", "4").first_child(), STR("self::node()[not(.=ancestor::TR/TD[3]/node())]")) % 14; + + CHECK_XPATH_NODESET(doc.child("TR").find_child_by_attribute("TD", "id", "1"), STR("node()[not(.=ancestor::TR/TD[3]/node())]")) % 5; + CHECK_XPATH_NODESET(doc.child("TR").find_child_by_attribute("TD", "id", "2"), STR("node()[not(.=ancestor::TR/TD[3]/node())]")) % 8; + CHECK_XPATH_NODESET(doc.child("TR").find_child_by_attribute("TD", "id", "3"), STR("node()[not(.=ancestor::TR/TD[3]/node())]")); + CHECK_XPATH_NODESET(doc.child("TR").find_child_by_attribute("TD", "id", "4"), STR("node()[not(.=ancestor::TR/TD[3]/node())]")) % 14; +} + +TEST_XML(xpath_star_token, "0.5
") +{ + CHECK_XPATH_NODESET(doc, STR("//*[/* * 4]")) % 6 % 9; + CHECK_XPATH_NODESET(doc, STR("//*[/**4]")) % 6 % 9; + CHECK_XPATH_FAIL(STR("//*[/***4]")); +} + +TEST(xpath_miscellaneous) +{ + CHECK_XPATH_FAIL("/root/child[a=3]/substring(child::text())"); + CHECK_XPATH_NODESET(xml_node(), "foo/@FOO/@bar"); +} + #endif diff --git a/tests/test_xpath_operators.cpp b/tests/test_xpath_operators.cpp index 3c1f69c..610e2b2 100644 --- a/tests/test_xpath_operators.cpp +++ b/tests/test_xpath_operators.cpp @@ -50,7 +50,9 @@ TEST_XML(xpath_operators_arithmetic, "102