Search in sources :

Example 21 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class OrExprTest method testOr.

@Test
public void testOr() 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 OrExpr(holder.getReader(), trueLit1, trueLit2);
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis1.hasNext());
    AbstractAxis axis2 = new OrExpr(holder.getReader(), trueLit1, falseLit1);
    assertEquals(true, axis2.hasNext());
    axis2.next();
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis2.hasNext());
    AbstractAxis axis3 = new OrExpr(holder.getReader(), falseLit1, trueLit1);
    assertEquals(true, axis3.hasNext());
    axis3.next();
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis3.hasNext());
    AbstractAxis axis4 = new OrExpr(holder.getReader(), falseLit1, falseLit2);
    assertEquals(true, axis4.hasNext());
    axis4.next();
    assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis4.hasNext());
}
Also used : AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) Test(org.junit.Test)

Example 22 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class NodeCompTest method testCompare.

@Test
public void testCompare() throws SirixXPathException {
    AtomicValue[] op1 = { new AtomicValue(2, Type.INTEGER) };
    AtomicValue[] op2 = { new AtomicValue(3, Type.INTEGER) };
    AtomicValue[] op3 = { new AtomicValue(3, Type.INTEGER) };
    assertEquals(false, comparator.compare(op1, op2));
    assertEquals(true, comparator.compare(op3, op2));
    try {
        comparator = new NodeComp(holder.getReader(), new LiteralExpr(holder.getReader(), -2), new LiteralExpr(holder.getReader(), -1), CompKind.PRE);
        comparator.compare(op1, op2);
        fail("Expexcted not yet implemented exception.");
    } catch (IllegalStateException e) {
        assertEquals("Evaluation of node comparisons not possible", e.getMessage());
    }
    try {
        comparator = new NodeComp(holder.getReader(), new LiteralExpr(holder.getReader(), -2), new LiteralExpr(holder.getReader(), -1), CompKind.FO);
        comparator.compare(op1, op2);
        fail("Expexcted not yet implemented exception.");
    } catch (IllegalStateException e) {
        assertEquals("Evaluation of node comparisons not possible", e.getMessage());
    }
}
Also used : LiteralExpr(org.sirix.service.xml.xpath.expr.LiteralExpr) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) Test(org.junit.Test)

Example 23 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class DivOpAxisTest method testOperate.

@Test
public final void testOperate() throws SirixException {
    AtomicValue item1 = new AtomicValue(1.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 DivOpAxis(holder.getReader(), op1, op2);
    assertEquals(true, axis.hasNext());
    axis.next();
    assertThat(0.5, 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 24 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue in project sirix by sirixdb.

the class IDivOpAxisTest 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 IDivOpAxis(holder.getReader(), op1, op2);
    assertEquals(true, axis.hasNext());
    axis.next();
    // note: although getRawValue() returns [1], parseString returns ""
    // assertEquals(1,
    // Integer.parseInt(TypedValue.parseString(holder.getRtx().getRawValue())));
    assertEquals(holder.getReader().keyForName("xs:integer"), 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 25 with AtomicValue

use of org.sirix.service.xml.xpath.AtomicValue 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)

Aggregations

AtomicValue (org.sirix.service.xml.xpath.AtomicValue)47 Test (org.junit.Test)12 AbstractAxis (org.sirix.service.xml.xpath.AbstractAxis)10 LiteralExpr (org.sirix.service.xml.xpath.expr.LiteralExpr)10 Type (org.sirix.service.xml.xpath.types.Type)7 XPathError (org.sirix.service.xml.xpath.XPathError)6 ErrorType (org.sirix.service.xml.xpath.XPathError.ErrorType)6 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)4 Axis (org.sirix.api.Axis)3 SirixXPathException (org.sirix.exception.SirixXPathException)3 ArrayList (java.util.ArrayList)1 DescendantAxis (org.sirix.axis.DescendantAxis)1 SingleType (org.sirix.service.xml.xpath.SingleType)1