CastableExpr extends AbstractExpression { public CastableExpr(final XmlNodeReadOnlyTrx rtx, final Axis inputExpr, final SingleType mTarget) { super(rtx); mSourceExpr = inputExpr; mTargetType = mTarget.getAtomic(); mPermitEmptySeq = mTarget.hasInterogation(); } CastableExpr(final XmlNodeReadOnlyTrx rtx, final Axis inputExpr, final SingleType mTarget); @Override void reset(final long mNodeKey); @Override void evaluate();  }
@Test public void testCastableExpr() throws SirixException { final AbstractAxis axis1 = new XPathAxis(holder.getXmlNodeReadTrx(), "1 castable as xs:decimal"); assertEquals(true, axis1.hasNext()); axis1.next(); assertEquals(holder.getXmlNodeReadTrx().keyForName("xs:boolean"), holder.getXmlNodeReadTrx().getTypeKey()); assertEquals(true, Boolean.parseBoolean(holder.getXmlNodeReadTrx().getValue())); assertEquals(false, axis1.hasNext()); final AbstractAxis axis2 = new XPathAxis(holder.getXmlNodeReadTrx(), "10.0 castable as xs:anyAtomicType"); try { assertEquals(true, axis2.hasNext()); axis2.next(); } catch (XPathError e) { assertThat( e.getMessage(), is( "err:XPST0080 " + "Target type of a cast or castable expression must not be " + "xs:NOTATION or xs:anyAtomicType.")); } final AbstractAxis axis4 = new XPathAxis(holder.getXmlNodeReadTrx(), "\"hello\" castable as xs:string"); assertEquals(true, axis4.hasNext()); axis4.next(); assertEquals(holder.getXmlNodeReadTrx().keyForName("xs:boolean"), holder.getXmlNodeReadTrx().getTypeKey()); assertEquals(true, Boolean.parseBoolean(holder.getXmlNodeReadTrx().getValue())); assertEquals(false, axis4.hasNext()); }