Skip to content

Commit b1d14de

Browse files
gabriele-tomassettiadamretter
authored andcommitted
[test] Add test for insert expression
1 parent e2895fa commit b1d14de

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,39 @@ public void dynamicUpdatingFunctionCall() throws EXistException, RecognitionExce
306306
assertEquals(Expression.Category.UPDATING, dfc.getCategory());
307307
}
308308
}
309+
310+
@Test
311+
public void insertExpr() throws EXistException, RecognitionException, XPathException, TokenStreamException, PermissionDeniedException
312+
{
313+
String query =
314+
"insert node <year>2005</year>\n" +
315+
" after book/publisher";
316+
317+
BrokerPool pool = BrokerPool.getInstance();
318+
try(final DBBroker broker = pool.getBroker()) {
319+
// parse the query into the internal syntax tree
320+
XQueryContext context = new XQueryContext(broker.getBrokerPool());
321+
XQueryLexer lexer = new XQueryLexer(context, new StringReader(query));
322+
XQueryParser xparser = new XQueryParser(lexer);
323+
xparser.expr();
324+
if (xparser.foundErrors()) {
325+
fail(xparser.getErrorMessage());
326+
return;
327+
}
328+
329+
XQueryAST ast = (XQueryAST) xparser.getAST();
330+
331+
XQueryTreeParser treeParser = new XQueryTreeParser(context);
332+
PathExpr expr = new PathExpr(context);
333+
treeParser.expr(ast, expr);
334+
335+
if (treeParser.foundErrors()) {
336+
fail(treeParser.getErrorMessage());
337+
return;
338+
}
339+
340+
assertTrue(expr.getFirst() instanceof InsertExpr);
341+
assertEquals(Expression.Category.UPDATING, expr.getFirst().getCategory());
342+
}
343+
}
309344
}

0 commit comments

Comments
 (0)