@@ -449,4 +449,40 @@ public void replaceValueExpr() throws EXistException, RecognitionException, XPat
449449 assertEquals ("doc(\" bib.xml\" )/child::{}books/child::{}book[1]/child::{}price * 1.1" ,((ReplaceExpr ) expr .getFirst ()).getWithExpr ().toString ());
450450 }
451451 }
452+
453+ @ Test
454+ public void renameExpr () throws EXistException , RecognitionException , XPathException , TokenStreamException , PermissionDeniedException
455+ {
456+ String query =
457+ "rename node fn:doc(\" bib.xml\" )/books/book[1]/author[1]\n " +
458+ "as \" principal-author\" " ;
459+
460+ BrokerPool pool = BrokerPool .getInstance ();
461+ try (final DBBroker broker = pool .getBroker ()) {
462+ // parse the query into the internal syntax tree
463+ XQueryContext context = new XQueryContext (broker .getBrokerPool ());
464+ XQueryLexer lexer = new XQueryLexer (context , new StringReader (query ));
465+ XQueryParser xparser = new XQueryParser (lexer );
466+ xparser .expr ();
467+ if (xparser .foundErrors ()) {
468+ fail (xparser .getErrorMessage ());
469+ return ;
470+ }
471+
472+ XQueryAST ast = (XQueryAST ) xparser .getAST ();
473+
474+ XQueryTreeParser treeParser = new XQueryTreeParser (context );
475+ PathExpr expr = new PathExpr (context );
476+ treeParser .expr (ast , expr );
477+
478+ if (treeParser .foundErrors ()) {
479+ fail (treeParser .getErrorMessage ());
480+ return ;
481+ }
482+
483+ assertTrue (expr .getFirst () instanceof RenameExpr );
484+ assertEquals ("doc(\" bib.xml\" )/child::{}books/child::{}book[1]/child::{}author[1]" ,((RenameExpr ) expr .getFirst ()).getTargetExpr ().toString ());
485+ assertEquals ("\" principal-author\" " ,((RenameExpr ) expr .getFirst ()).getNewNameExpr ().toString ());
486+ }
487+ }
452488}
0 commit comments