Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,16 @@ public Sequence eval(final Sequence contextSequence, final Item contextItem) thr
return null;
}
} else {
return value.get().eval(null, null);
final Sequence result = value.get().eval(null, null);
Comment thread
adamretter marked this conversation as resolved.
Resolved
if (result.isEmpty() || result.hasMany()) {
throw new XPathException(this, ErrorCodes.XPTY0004, "The context item must be exactly one item");
} else {
return result;
}
}
}


@Override
public int returnsType() {
return itemType.map(SequenceType::getPrimaryType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

/**
* Tests for XQuery 3.0's declare context item
Expand Down Expand Up @@ -144,6 +145,39 @@ public void declareContextItem() throws EXistException, PermissionDeniedExceptio
}
}

@Test
public void declareContextItemMoreThanOneItem() throws EXistException, PermissionDeniedException, XPathException, IOException {
Comment thread
adamretter marked this conversation as resolved.
Resolved
final String query =
"xquery version \"3.0\";\n" +
"declare context item := (1,2); \n" +
".";

final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.getBroker();
final XQueryUtil.QueryResult queryResult = XQueryUtil.query(broker, new StringSource(query), false, null, null, null, null, null)) {
fail("Expected XQuery error XPTY0004");
} catch (final XPathException e){
assertEquals(ErrorCodes.XPTY0004, e.getErrorCode());
}
}

@Test
public void declareContextItemNoItems() throws EXistException, PermissionDeniedException, XPathException, IOException {
final String query =
"xquery version \"3.0\";\n" +
"declare context item := (); \n" +
".";

final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.getBroker();
final XQueryUtil.QueryResult queryResult = XQueryUtil.query(broker, new StringSource(query), false, null, null, null, null, null)) {
fail("Expected XQuery error XPTY0004");
} catch (final XPathException e){
assertEquals(ErrorCodes.XPTY0004, e.getErrorCode());
}
}


/**
* See issue https://github.com/eXist-db/exist/issues/2156
*/
Expand Down
Loading