Checks the query plan and the result. @param query query @param expected result or null for no comparison @param tests queries on the query plan
(final String query, final Object expected, final String... tests)
| 270 | * @param tests queries on the query plan |
| 271 | */ |
| 272 | protected static void check(final String query, final Object expected, final String... tests) { |
| 273 | try(QueryProcessor qp = new QueryProcessor(query, context)) { |
| 274 | qp.optimize(); |
| 275 | final FNode plan = qp.toXml(); |
| 276 | // compare result |
| 277 | if(expected != null) { |
| 278 | compare(query, qp.value().serialize().toString(), expected, plan); |
| 279 | } |
| 280 | // check syntax tree |
| 281 | for(final String test : tests) { |
| 282 | final FNode doc = FDoc.build().node(plan).finish(); |
| 283 | try(QueryProcessor qp2 = new QueryProcessor(test, context).context(doc)) { |
| 284 | if(qp2.value() != Bln.TRUE) fail(Prop.NL + "QUERY: " + query + Prop.NL + |
| 285 | "OPTIMIZED: " + qp.qc.main + Prop.NL + "TEST: " + test + Prop.NL + serialize(plan)); |
| 286 | } |
| 287 | } |
| 288 | } catch(final QueryException | QueryIOException ex) { |
| 289 | Util.stack(ex); |
| 290 | fail(ex); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Checks types at runtime. |