Search in sources :

Example 6 with LiteralExpr

use of org.sirix.service.xml.xpath.expr.LiteralExpr 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 7 with LiteralExpr

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

the class NodeCompTest method testAtomize.

@Test
public void testAtomize() throws SirixXPathException {
    Axis axis = new LiteralExpr(holder.getReader(), -2);
    axis.hasNext();
    axis.next();
    AtomicValue[] value = comparator.atomize(axis);
    assertEquals(value.length, 1);
    assertEquals(holder.getReader().getNodeKey(), value[0].getNodeKey());
    assertEquals("xs:integer", value[0].getType());
    try {
        axis = new DescendantAxis(holder.getReader());
        axis.hasNext();
        comparator.atomize(axis);
    } catch (SirixXPathException e) {
        assertEquals("err:XPTY0004 The type is not appropriate the expression or" + " the typedoes not match a required type as specified by the " + "matching rules.", e.getMessage());
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) LiteralExpr(org.sirix.service.xml.xpath.expr.LiteralExpr) AtomicValue(org.sirix.service.xml.xpath.AtomicValue) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test)

Example 8 with LiteralExpr

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

Example 9 with LiteralExpr

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

the class AddOpAxisTest 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 AddOpAxis(holder.getReader(), op1, op2);
    assertEquals(true, axis.hasNext());
    axis.next();
    assertThat(3.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 10 with LiteralExpr

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

the class MulOpAxisTest 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 MulOpAxis(holder.getReader(), op1, op2);
    assertEquals(true, axis.hasNext());
    axis.next();
    assertThat(6.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

LiteralExpr (org.sirix.service.xml.xpath.expr.LiteralExpr)11 AtomicValue (org.sirix.service.xml.xpath.AtomicValue)10 Test (org.junit.Test)9 AbstractAxis (org.sirix.service.xml.xpath.AbstractAxis)7 Axis (org.sirix.api.Axis)2 SirixXPathException (org.sirix.exception.SirixXPathException)2 DescendantAxis (org.sirix.axis.DescendantAxis)1 ForAxis (org.sirix.axis.ForAxis)1 FilterAxis (org.sirix.axis.filter.FilterAxis)1 PredicateFilterAxis (org.sirix.axis.filter.PredicateFilterAxis)1 ExceptAxis (org.sirix.service.xml.xpath.expr.ExceptAxis)1 IfAxis (org.sirix.service.xml.xpath.expr.IfAxis)1 IntersectAxis (org.sirix.service.xml.xpath.expr.IntersectAxis)1 RangeAxis (org.sirix.service.xml.xpath.expr.RangeAxis)1 SequenceAxis (org.sirix.service.xml.xpath.expr.SequenceAxis)1 UnionAxis (org.sirix.service.xml.xpath.expr.UnionAxis)1 VariableAxis (org.sirix.service.xml.xpath.expr.VariableAxis)1 DupFilterAxis (org.sirix.service.xml.xpath.filter.DupFilterAxis)1 AddOpAxis (org.sirix.service.xml.xpath.operators.AddOpAxis)1 DivOpAxis (org.sirix.service.xml.xpath.operators.DivOpAxis)1