Skip to content

Commit e381421

Browse files
gabriele-tomassettiadamretter
authored andcommitted
[test] Add test for delete expression
1 parent f10a4b2 commit e381421

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

exist-core/src/test/java/org/exist/xquery/update/XQueryUpdate3Test.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,38 @@ public void insertExpr() throws EXistException, RecognitionException, XPathExcep
341341
assertEquals(Expression.Category.UPDATING, expr.getFirst().getCategory());
342342
}
343343
}
344+
345+
@Test
346+
public void deleteExpr() throws EXistException, RecognitionException, XPathException, TokenStreamException, PermissionDeniedException
347+
{
348+
String query =
349+
"delete node fn:doc(\"bib.xml\")/books/book[1]/author[last()]";
350+
351+
BrokerPool pool = BrokerPool.getInstance();
352+
try(final DBBroker broker = pool.getBroker()) {
353+
// parse the query into the internal syntax tree
354+
XQueryContext context = new XQueryContext(broker.getBrokerPool());
355+
XQueryLexer lexer = new XQueryLexer(context, new StringReader(query));
356+
XQueryParser xparser = new XQueryParser(lexer);
357+
xparser.expr();
358+
if (xparser.foundErrors()) {
359+
fail(xparser.getErrorMessage());
360+
return;
361+
}
362+
363+
XQueryAST ast = (XQueryAST) xparser.getAST();
364+
365+
XQueryTreeParser treeParser = new XQueryTreeParser(context);
366+
PathExpr expr = new PathExpr(context);
367+
treeParser.expr(ast, expr);
368+
369+
if (treeParser.foundErrors()) {
370+
fail(treeParser.getErrorMessage());
371+
return;
372+
}
373+
374+
assertTrue(expr.getFirst() instanceof DeleteExpr);
375+
assertEquals(Expression.Category.UPDATING, expr.getFirst().getCategory());
376+
}
377+
}
344378
}

0 commit comments

Comments
 (0)