Search in sources :

Example 16 with AbstractAxis

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());
}
Also used : AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) LiteralExpr(org.sirix.service.xml.xpath.expr.LiteralExpr) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) Test(org.junit.Test)

Example 17 with AbstractAxis

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());
    }
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) XPathError(org.sirix.service.xml.xpath.XPathError) Test(org.junit.Test)

Example 18 with AbstractAxis

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();
}
Also used : AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) Test(org.junit.Test)

Example 19 with AbstractAxis

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());
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) Test(org.junit.Test)

Example 20 with AbstractAxis

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());
}
Also used : AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) LiteralExpr(org.sirix.service.xml.xpath.expr.LiteralExpr) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) Test(org.junit.Test)

Aggregations

AbstractAxis (org.sirix.service.xml.xpath.AbstractAxis)29 Test (org.junit.Test)28 XPathAxis (org.sirix.service.xml.xpath.XPathAxis)12 AtomicValue (org.sirix.service.xml.xpath.AtomicValue)10 XPathError (org.sirix.service.xml.xpath.XPathError)8 LiteralExpr (org.sirix.service.xml.xpath.expr.LiteralExpr)7 SequenceAxis (org.sirix.service.xml.xpath.expr.SequenceAxis)6 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)2 ArrayList (java.util.ArrayList)1 Axis (org.sirix.api.Axis)1 FilterTest (org.sirix.axis.filter.FilterTest)1 TypeFilter (org.sirix.axis.filter.TypeFilter)1 SirixXPathException (org.sirix.exception.SirixXPathException)1 FNBoolean (org.sirix.service.xml.xpath.functions.sequences.FNBoolean)1