use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class ModOpAxisTest method testOperate.
@Test
public final void testOperate() throws SirixException {
AtomicValue item1 = new AtomicValue(3.0, Type.DOUBLE);
AtomicValue item2 = new AtomicValue(2.0, Type.DOUBLE);
AbstractAxis op1 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item1));
AbstractAxis op2 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item2));
AbstractObAxis axis = new ModOpAxis(holder.getReader(), op1, op2);
assertEquals(true, axis.hasNext());
axis.next();
assertThat(1.0, is(Double.parseDouble(holder.getReader().getValue())));
assertEquals(holder.getReader().keyForName("xs:double"), holder.getReader().getTypeKey());
assertEquals(false, axis.hasNext());
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class AndExprTest method testAndQuery.
@Test
public void testAndQuery() throws SirixException {
holder.getReader().moveTo(1L);
final AbstractAxis axis1 = new XPathAxis(holder.getReader(), "text() and 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() and node()");
assertEquals(true, axis2.hasNext());
axis2.next();
assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis2.hasNext());
final AbstractAxis axis3 = new XPathAxis(holder.getReader(), "1 eq 1 and 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 and 2 eq 3");
assertEquals(true, axis4.hasNext());
axis4.next();
assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis4.hasNext());
// is never evaluated.
final AbstractAxis axis5 = new XPathAxis(holder.getReader(), "1 eq 2 and (3 idiv 0 = 1)");
assertEquals(true, axis5.hasNext());
axis5.next();
assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis5.hasNext());
final AbstractAxis axis6 = new XPathAxis(holder.getReader(), "1 eq 1 and 3 idiv 0 = 1");
try {
assertEquals(true, axis6.hasNext());
axis6.next();
fail("Expected XPath exception, because of division by zero");
} catch (XPathError e) {
assertEquals("err:FOAR0001: Division by zero.", e.getMessage());
}
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class AndExprTest method testAnd.
@Test(expected = NoSuchElementException.class)
public void testAnd() throws SirixException {
long iTrue = holder.getReader().getItemList().addItem(new AtomicValue(true));
long iFalse = holder.getReader().getItemList().addItem(new AtomicValue(false));
AbstractAxis trueLit1 = new LiteralExpr(holder.getReader(), iTrue);
AbstractAxis trueLit2 = new LiteralExpr(holder.getReader(), iTrue);
AbstractAxis falseLit1 = new LiteralExpr(holder.getReader(), iFalse);
AbstractAxis falseLit2 = new LiteralExpr(holder.getReader(), iFalse);
AbstractAxis axis1 = new AndExpr(holder.getReader(), trueLit1, trueLit2);
assertEquals(true, axis1.hasNext());
axis1.next();
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis1.hasNext());
AbstractAxis axis2 = new AndExpr(holder.getReader(), trueLit1, falseLit1);
assertEquals(true, axis2.hasNext());
axis2.next();
assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis2.hasNext());
AbstractAxis axis3 = new AndExpr(holder.getReader(), falseLit1, trueLit1);
assertEquals(true, axis3.hasNext());
axis3.next();
assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis3.hasNext());
AbstractAxis axis4 = new AndExpr(holder.getReader(), falseLit1, falseLit2);
assertEquals(true, axis4.hasNext());
axis4.next();
assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis4.hasNext());
axis4.next();
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class EveryExprTest method testEveryExpr.
@Test
public void testEveryExpr() throws SirixException {
final AbstractAxis axis1 = new XPathAxis(holder.getReader(), "every $child in child::node()" + "satisfies $child/@i");
assertEquals(true, axis1.hasNext());
axis1.next();
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis1.hasNext());
final AbstractAxis axis2 = new XPathAxis(holder.getReader(), "every $child in child::node()" + "satisfies $child/@abc");
assertEquals(true, axis2.hasNext());
axis2.next();
assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis2.hasNext());
holder.getReader().moveTo(1L);
final AbstractAxis axis3 = new XPathAxis(holder.getReader(), "every $child in child::element()" + " satisfies $child/attribute::attribute()");
assertEquals(true, axis3.hasNext());
axis3.next();
assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis3.hasNext());
holder.getReader().moveTo(1L);
final AbstractAxis axis4 = new XPathAxis(holder.getReader(), "every $child in child::element() satisfies $child/child::c");
assertEquals(true, axis4.hasNext());
axis4.next();
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis4.hasNext());
}
use of org.sirix.service.xml.xpath.AbstractAxis in project sirix by sirixdb.
the class AbsOpAxisTest method testHasNext.
@Test
public final void testHasNext() throws SirixException {
final AtomicValue item1 = new AtomicValue(1.0, Type.DOUBLE);
final AtomicValue item2 = new AtomicValue(2.0, Type.DOUBLE);
AbstractAxis op1 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item1));
AbstractAxis op2 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item2));
AbstractObAxis axis = new DivOpAxis(holder.getReader(), op1, op2);
assertEquals(true, axis.hasNext());
assertEquals(holder.getReader().keyForName("xs:double"), holder.getReader().getTypeKey());
assertEquals(false, axis.hasNext());
// here both operands are the empty sequence
axis = new DivOpAxis(holder.getReader(), op1, op2);
assertEquals(true, axis.hasNext());
axis.next();
assertThat(Double.NaN, is(Double.parseDouble(holder.getReader().getValue())));
assertEquals(holder.getReader().keyForName("xs:double"), holder.getReader().getTypeKey());
assertEquals(false, axis.hasNext());
}
Aggregations