summaryrefslogtreecommitdiff
path: root/tests/test_xpath_paths.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-05-30 07:52:18 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-05-30 07:52:18 +0000
commite91b5e305966f5d03fb1f8fc3fa5f2e4dac16041 (patch)
tree0f2e0bc71dbe805fe2a93e0c34b886b42f265679 /tests/test_xpath_paths.cpp
parent3bee04cd1145802784481cd13f4a951da83ff917 (diff)
tests: Added tests for principal node types with attributes for all axes that can return attributes
git-svn-id: http://pugixml.googlecode.com/svn/trunk@471 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_xpath_paths.cpp')
-rw-r--r--tests/test_xpath_paths.cpp42
1 files changed, 38 insertions, 4 deletions
diff --git a/tests/test_xpath_paths.cpp b/tests/test_xpath_paths.cpp
index 2d00c34..e58d7b1 100644
--- a/tests/test_xpath_paths.cpp
+++ b/tests/test_xpath_paths.cpp
@@ -286,10 +286,44 @@ TEST_XML_FLAGS(xpath_paths_nodetest_type, "<node attr='value'>pcdata<child/><?pi
CHECK_XPATH_FAIL(STR("processing-instruction('', '')"));
}
-TEST_XML_FLAGS(xpath_paths_nodetest_principal, "<node attr='value'>pcdata<child/><?pi1 value?><?pi2 value?><!--comment--><![CDATA[cdata]]></node>", parse_default | parse_pi | parse_comments)
-{
- // $$$ self::* should not select attribute nodes (?)
- // $$$ name, * and name:* should check type = elem (?)
+TEST_XML_FLAGS(xpath_paths_nodetest_principal, "<node attr='value'>pcdata<child/><?pi1 value?><?pi2 value?><!--comment--><![CDATA[cdata]]></node><abra:cadabra abra:arba=''/>", parse_default | parse_pi | parse_comments)
+{
+ // node() test is true for any node type
+ CHECK_XPATH_NODESET(doc, STR("//node()")) % 2 % 4 % 5 % 6 % 7 % 8 % 9 % 10;
+ CHECK_XPATH_NODESET(doc, STR("//attribute::node()")) % 3 % 11;
+ CHECK_XPATH_NODESET(doc, STR("//attribute::node()/ancestor-or-self::node()")) % 1 % 2 % 3 % 10 % 11;
+
+ // name test is true only for node with principal node type (depends on axis)
+ CHECK_XPATH_NODESET(doc, STR("node/child::child")) % 5;
+ CHECK_XPATH_NODESET(doc, STR("node/attribute::attr")) % 3;
+ CHECK_XPATH_NODESET(doc, STR("node/child::pi1"));
+ CHECK_XPATH_NODESET(doc, STR("node/child::attr"));
+ CHECK_XPATH_NODESET(doc, STR("node/child::child/self::child")) % 5;
+ CHECK_XPATH_NODESET(doc, STR("node/attribute::attr/self::attr")); // attribute is not of element type
+ CHECK_XPATH_NODESET(doc, STR("node/child::child/ancestor-or-self::child")) % 5;
+ CHECK_XPATH_NODESET(doc, STR("node/attribute::attr/ancestor-or-self::attr")); // attribute is not of element type
+ CHECK_XPATH_NODESET(doc, STR("node/child::child/descendant-or-self::child")) % 5;
+ CHECK_XPATH_NODESET(doc, STR("node/attribute::attr/descendant-or-self::attr")); // attribute is not of element type
+
+ // any name test is true only for node with principal node type (depends on axis)
+ CHECK_XPATH_NODESET(doc, STR("node/child::*")) % 5;
+ CHECK_XPATH_NODESET(doc, STR("node/attribute::*")) % 3;
+ CHECK_XPATH_NODESET(doc, STR("node/child::*/self::*")) % 5;
+ CHECK_XPATH_NODESET(doc, STR("node/attribute::*/self::*")); // attribute is not of element type
+ CHECK_XPATH_NODESET(doc, STR("node/child::*/ancestor-or-self::*")) % 5 % 2;
+ CHECK_XPATH_NODESET(doc, STR("node/attribute::*/ancestor-or-self::*")) % 2; // attribute is not of element type
+ CHECK_XPATH_NODESET(doc, STR("node/child::*/descendant-or-self::*")) % 5;
+ CHECK_XPATH_NODESET(doc, STR("node/attribute::*/descendant-or-self::*")); // attribute is not of element type
+
+ // namespace test is true only for node with principal node type (depends on axis)
+ CHECK_XPATH_NODESET(doc, STR("child::abra:*")) % 10;
+ CHECK_XPATH_NODESET(doc, STR("child::abra:*/attribute::abra:*")) % 11;
+ CHECK_XPATH_NODESET(doc, STR("child::abra:*/self::abra:*")) % 10;
+ CHECK_XPATH_NODESET(doc, STR("child::abra:*/attribute::abra:*/self::abra:*")); // attribute is not of element type
+ CHECK_XPATH_NODESET(doc, STR("child::abra:*/ancestor-or-self::abra:*")) % 10;
+ CHECK_XPATH_NODESET(doc, STR("child::abra:*/attribute::abra:*/ancestor-or-self::abra:*")) % 10; // attribute is not of element type
+ CHECK_XPATH_NODESET(doc, STR("child::abra:*/descendant-or-self::abra:*")) % 10;
+ CHECK_XPATH_NODESET(doc, STR("child::abra:*/attribute::abra:*/descendant-or-self::abra:*")); // attribute is not of element type
}
TEST_XML(xpath_paths_absolute, "<node><foo><foo/><foo/></foo></node>")