summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-27 18:50:09 -0700
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-27 18:50:09 -0700
commitc64d4820b142e6df93ccf612d0e4717159a36591 (patch)
tree67b41215c627fa43283fb1b9a3e14e1bd66fa946 /tests
parentdbfe85a717b7ac8b9bd30eb51796811c0c651da9 (diff)
XPath: Optimize [position()=expr] and [last()]
To get more benefits from constant predicate/filter optimization we rewrite [position()=expr] predicates into [expr] for numeric expressions. Right now the rewrite is only for entire expressions - it may be beneficial to split complex expressions like [position()=constant and expr] into [constant][expr] but that is more complicated. last() does not depend on the node set contents so is "constant" as far as our optimization is concerned so we can evaluate it once.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_xpath_paths.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/test_xpath_paths.cpp b/tests/test_xpath_paths.cpp
index 046592a..df0dfa4 100644
--- a/tests/test_xpath_paths.cpp
+++ b/tests/test_xpath_paths.cpp
@@ -475,6 +475,14 @@ TEST_XML(xpath_paths_predicate_constant_boolean, "<node><chapter/><chapter/><cha
CHECK_XPATH_NODESET_VAR(n, STR("following-sibling::chapter[$true]"), &set) % 6 % 7;
}
+TEST_XML(xpath_paths_predicate_position_eq, "<node><chapter/><chapter/><chapter>3</chapter><chapter/><chapter/></node>")
+{
+ CHECK_XPATH_NODESET(doc, STR("node/chapter[position()=1]")) % 3;
+ CHECK_XPATH_NODESET(doc, STR("node/chapter[position()=2+2]")) % 7;
+ CHECK_XPATH_NODESET(doc, STR("node/chapter[position()=last()]")) % 8;
+ CHECK_XPATH_NODESET(doc, STR("node/chapter[position()=string()]")) % 5;
+}
+
TEST_XML(xpath_paths_predicate_several, "<node><employee/><employee secretary=''/><employee assistant=''/><employee secretary='' assistant=''/><employee assistant='' secretary=''/></node>")
{
xml_node n = doc.child(STR("node"));