use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class ForAxisTest method testFor.
@Test
public void testFor() throws SirixException {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveTo(1L);
AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in child::text() return child::node()"), new long[] { 4L, 5L, 8L, 9L, 13L, 4L, 5L, 8L, 9L, 13L, 4L, 5L, 8L, 9L, 13L });
AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in child::node() return $a/node()"), new long[] { 6L, 7L, 11L, 12L });
AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in child::node() return $a/text()"), new long[] { 6L, 12L });
AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in child::node() return $a/c"), new long[] { 7L, 11L });
// IAxisTest.testIAxisConventions(new XPathAxis(
// rtx,
// "for $a in child::node(), $b in /node(), $c in ., $d in /c return $a/c"),
// new long[] {7L, 11L});
AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in child::node() return $a[@p:x]"), new long[] { 9L });
AbsAxisTest.testIAxisConventions(new XPathAxis(rtx, "for $a in . return $a"), new long[] { 1L });
final AbstractAxis axis = new XPathAxis(rtx, "for $i in (10, 20), $j in (1, 2) return ($i + $j)");
assertEquals(true, axis.hasNext());
axis.next();
assertEquals("11.0", rtx.getValue());
assertEquals(true, axis.hasNext());
axis.next();
assertEquals("12.0", rtx.getValue());
assertEquals(true, axis.hasNext());
axis.next();
assertEquals("21.0", rtx.getValue());
assertEquals(true, axis.hasNext());
axis.next();
assertEquals("22.0", rtx.getValue());
assertEquals(false, axis.hasNext());
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class Function method ebv.
public static boolean ebv(final Axis axis) throws SirixXPathException {
final FuncDef ebv = FuncDef.BOOLEAN;
final List<Axis> param = new ArrayList<Axis>();
param.add(axis);
final AbstractAxis bAxis = new FNBoolean(axis.getTrx(), param, ebv.getMin(), ebv.getMax(), axis.getTrx().keyForName(ebv.getReturnType()));
if (bAxis.hasNext()) {
bAxis.next();
final boolean result = Boolean.parseBoolean(bAxis.getTrx().getValue());
if (!bAxis.hasNext()) {
bAxis.reset(axis.getTrx().getNodeKey());
return result;
}
}
// TODO!!
throw new IllegalStateException("This should not happen!");
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class InstanceOfExprTest method testInstanceOfExpr.
@Test(expected = NoSuchElementException.class)
public void testInstanceOfExpr() throws SirixException {
final AbstractAxis axis1 = new XPathAxis(holder.getReader(), "1 instance of xs:integer");
assertEquals(true, axis1.hasNext());
axis1.next();
assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis1.hasNext());
final AbstractAxis axis2 = new XPathAxis(holder.getReader(), "\"hallo\" instance of xs:integer");
assertEquals(true, axis2.hasNext());
axis2.next();
assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis2.hasNext());
final AbstractAxis axis3 = new XPathAxis(holder.getReader(), "\"hallo\" instance of xs:string ?");
assertEquals(true, axis3.hasNext());
axis3.next();
assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis3.hasNext());
final AbstractAxis axis4 = new XPathAxis(holder.getReader(), "\"hallo\" instance of xs:string +");
assertEquals(true, axis4.hasNext());
axis4.next();
assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis4.hasNext());
final AbstractAxis axis5 = new XPathAxis(holder.getReader(), "\"hallo\" instance of xs:string *");
assertEquals(true, axis5.hasNext());
axis5.next();
assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis5.hasNext());
axis5.next();
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class LiteralExprTest method testLiteralExpr.
@Test
public void testLiteralExpr() throws SirixException {
// Build simple test tree.
final AtomicValue item1 = new AtomicValue(false);
final AtomicValue item2 = new AtomicValue(14, Type.INTEGER);
final int key1 = holder.getReader().getItemList().addItem(item1);
final int key2 = holder.getReader().getItemList().addItem(item2);
final AbstractAxis axis1 = new LiteralExpr(holder.getReader(), key1);
assertEquals(true, axis1.hasNext());
axis1.next();
assertEquals(key1, holder.getReader().getNodeKey());
assertEquals(holder.getReader().keyForName("xs:boolean"), holder.getReader().getTypeKey());
assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis1.hasNext());
final AbstractAxis axis2 = new LiteralExpr(holder.getReader(), key2);
assertEquals(true, axis2.hasNext());
axis2.next();
assertEquals(key2, holder.getReader().getNodeKey());
assertEquals(holder.getReader().keyForName("xs:integer"), holder.getReader().getTypeKey());
assertEquals(14, Integer.parseInt(holder.getReader().getValue()));
assertEquals(false, axis2.hasNext());
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class OrExprTest method testOrQuery.
@Test
public void testOrQuery() throws SirixException {
holder.getReader().moveTo(1L);
final AbstractAxis axis1 = new XPathAxis(holder.getReader(), "text() or node()");
assertEquals(true, axis1.hasNext());
axis1.next();
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis1.hasNext());
final AbstractAxis axis2 = new XPathAxis(holder.getReader(), "comment() or node()");
assertEquals(true, axis2.hasNext());
axis2.next();
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis2.hasNext());
final AbstractAxis axis3 = new XPathAxis(holder.getReader(), "1 eq 1 or 2 eq 2");
assertEquals(true, axis3.hasNext());
axis3.next();
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis3.hasNext());
final AbstractAxis axis4 = new XPathAxis(holder.getReader(), "1 eq 1 or 2 eq 3");
assertEquals(true, axis4.hasNext());
axis4.next();
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis4.hasNext());
final AbstractAxis axis5 = new XPathAxis(holder.getReader(), "1 eq 2 or (3 idiv 0 = 1)");
try {
assertEquals(true, axis5.hasNext());
axis5.next();
assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis5.hasNext());
axis5.next();
fail("Exprected XPathError");
} catch (XPathError e) {
assertEquals("err:FOAR0001: Division by zero.", e.getMessage());
}
final AbstractAxis axis6 = new XPathAxis(holder.getReader(), "1 eq 1 or (3 idiv 0 = 1)");
assertEquals(true, axis6.hasNext());
axis6.next();
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
}
Aggregations