|
8 | 8 | -module(xpath_abbrev). |
9 | 9 |
|
10 | 10 | -export([test/0, check_node_set/2, ticket_6873/0, ticket_7496/0, functions/0]). |
| 11 | +-export([relational_operators/0]). |
11 | 12 | -export([namespaces/0]). |
12 | 13 |
|
13 | 14 | -include_lib("common_test/include/ct.hrl"). |
@@ -218,6 +219,34 @@ ticket_7496() -> |
218 | 219 | ok = Test(Doc3,"//*[starts-with(local-name(),'p')]", |
219 | 220 | [parent,pet,pet]). |
220 | 221 |
|
| 222 | +%% Regression test for the relational operators '<', '<=' and '>='. |
| 223 | +%% These three clauses of xmerl_xpath_pred:comp_expr/4 each carried the |
| 224 | +%% body of '>' (a copy-paste error), so every one evaluated as 'a > b'. |
| 225 | +%% The cases below fail on the buggy code (each selects [e,f] / [] instead |
| 226 | +%% of the expected node sets) and pass once the operators are correct. |
| 227 | +relational_operators() -> |
| 228 | + Test = fun(Doc, XPath, Exp) -> |
| 229 | + Result = xmerl_xpath:string(XPath, Doc), |
| 230 | + Exp = [Name || #xmlElement{name = Name} <- Result], |
| 231 | + ok |
| 232 | + end, |
| 233 | + {Doc,_} = xmerl_scan:string("<a><b/><c/><d/><e/><f/></a>"), |
| 234 | + |
| 235 | + %% Relational predicates over position() (number vs number). |
| 236 | + ok = Test(Doc, "/a/*[position() < 3]", [b, c]), |
| 237 | + ok = Test(Doc, "/a/*[position() <= 3]", [b, c, d]), |
| 238 | + ok = Test(Doc, "/a/*[position() >= 3]", [d, e, f]), |
| 239 | + ok = Test(Doc, "/a/*[position() > 3]", [e, f]), |
| 240 | + |
| 241 | + %% Constant relational predicates, independent of position(): each is a |
| 242 | + %% boolean that is true, so it selects every child. |
| 243 | + All = [b, c, d, e, f], |
| 244 | + ok = Test(Doc, "/a/*[2 < 3]", All), |
| 245 | + ok = Test(Doc, "/a/*[3 <= 3]", All), |
| 246 | + ok = Test(Doc, "/a/*[3 >= 3]", All), |
| 247 | + ok = Test(Doc, "/a/*[3 > 2]", All), |
| 248 | + ok. |
| 249 | + |
221 | 250 |
|
222 | 251 | functions() -> |
223 | 252 | Test = fun(Doc, XPath, Exp) -> |
|
0 commit comments