Search in sources :

Example 1 with AbstractAxis

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

Example 2 with AbstractAxis

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!");
}
Also used : FNBoolean(org.sirix.service.xml.xpath.functions.sequences.FNBoolean) ArrayList(java.util.ArrayList) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) Axis(org.sirix.api.Axis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis)

Example 3 with AbstractAxis

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

Example 4 with AbstractAxis

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

Example 5 with AbstractAxis

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()));
}
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)

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