summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-05-14 08:01:03 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2015-05-14 08:04:06 -0700
commitf828eae3eaca02c9659d63cbcab65c9dd8e13869 (patch)
tree71347971f8e7c857f49f2f7a2d4ecaef390e939f /tests
parent01f627a4d75ae25850bc29df74112696da571326 (diff)
Implement xml_node::attribute with a hint
Extra argument 'hint' is used to start the attribute lookup; if the attribute is not found the lookup is restarted from the beginning of the attriubte list. This allows to optimize attribute lookups if you need to get many attributes from the node and can make assumptions about the likely ordering. The code is correct regardless of the order, but it is faster than using vanilla lookups if the order matches the calling order. Fixes #30.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_dom_traverse.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp
index e4b8c44..8f96d93 100644
--- a/tests/test_dom_traverse.cpp
+++ b/tests/test_dom_traverse.cpp
@@ -1130,3 +1130,24 @@ TEST_XML(dom_ranged_for, "<node attr1='1' attr2='2'><test>3</test><fake>5</fake>
CHECK(index == 5);
}
#endif
+
+TEST_XML(dom_node_attribute_hinted, "<node attr1='1' attr2='2' attr3='3' />")
+{
+ xml_node node = doc.first_child();
+ xml_attribute attr1 = node.attribute(STR("attr1"));
+ xml_attribute attr2 = node.attribute(STR("attr2"));
+ xml_attribute attr3 = node.attribute(STR("attr3"));
+
+ xml_attribute hint;
+ CHECK(!xml_node().attribute(STR("test"), hint) && !hint);
+
+ CHECK(node.attribute(STR("attr2"), hint) == attr2 && hint == attr3);
+ CHECK(node.attribute(STR("attr3"), hint) == attr3 && !hint);
+
+ CHECK(node.attribute(STR("attr1"), hint) == attr1 && hint == attr2);
+ CHECK(node.attribute(STR("attr2"), hint) == attr2 && hint == attr3);
+ CHECK(node.attribute(STR("attr1"), hint) == attr1 && hint == attr2);
+ CHECK(node.attribute(STR("attr1"), hint) == attr1 && hint == attr2);
+
+ CHECK(!node.attribute(STR("attr"), hint) && hint == attr2);
+} \ No newline at end of file