Search in sources :

Example 6 with AbstractAxis

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

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

the class VarRefExprTest method testEveryExpr.

@Test
public void testEveryExpr() throws SirixException {
    final AbstractAxis axis = new XPathAxis(holder.getReader(), "for $a in b return $a");
    final VariableAxis variable = new VariableAxis(holder.getReader(), axis);
    final VarRefExpr axis1 = new VarRefExpr(holder.getReader(), variable);
    // assertEquals(false, axis1.hasNext());
    axis1.update(5L);
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(5L, holder.getReader().getNodeKey());
    axis1.update(13L);
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(13L, holder.getReader().getNodeKey());
    axis1.update(1L);
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(1L, holder.getReader().getNodeKey());
    assertEquals(false, axis1.hasNext());
    final VarRefExpr axis2 = new VarRefExpr(holder.getReader(), variable);
    // assertEquals(false, axis2.hasNext());
    axis2.update(13L);
    assertEquals(true, axis2.hasNext());
    axis2.next();
    assertEquals(13L, holder.getReader().getNodeKey());
    assertEquals(false, axis2.hasNext());
    axis2.update(12L);
    assertEquals(true, axis2.hasNext());
    axis2.next();
    assertEquals(12L, holder.getReader().getNodeKey());
    assertEquals(false, axis2.hasNext());
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) Test(org.junit.Test)

Example 8 with AbstractAxis

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

the class CastableExprTest method testCastableExpr.

@Test
public void testCastableExpr() throws SirixException {
    final AbstractAxis axis1 = new XPathAxis(holder.getReader(), "1 castable as xs:decimal");
    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(), "10.0 castable as xs:anyAtomicType");
    try {
        assertEquals(true, axis2.hasNext());
        axis2.next();
    } catch (XPathError e) {
        assertThat(e.getMessage(), is("err:XPST0080 " + "Target type of a cast or castable expression must not be " + "xs:NOTATION or xs:anyAtomicType."));
    }
    // Token is not implemented yet.
    // final IAxis axis3 = new XPathAxis(holder.getRtx(),
    // "\"hello\" castable as xs:token");
    // assertEquals(true, axis3.hasNext());
    // assertEquals(Type.BOOLEAN, holder.getRtx().getValueTypeAsType());
    // assertEquals(true, holder.getRtx().getValueAsBoolean());
    // assertEquals(false, axis3.hasNext());
    final AbstractAxis axis4 = new XPathAxis(holder.getReader(), "\"hello\" castable as 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 IAxis axis5 = new XPathAxis(holder.getRtx(),
// "\"hello\" castable as xs:decimal");
// assertEquals(true, axis5.hasNext());
// assertEquals(holder.getRtx().keyForName("xs:boolean"),
// holder.getRtx().getTypeKey());
// assertEquals(true, Boolean.parseBoolean(holder.getRtx().getValue()));
// assertEquals(false, axis5.hasNext());
}
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 9 with AbstractAxis

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

the class CompAxisTest method testComp.

@Test
public void testComp() throws SirixException {
    final AbstractAxis axis1 = new XPathAxis(holder.getReader(), "1.0 = 1.0");
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis1.hasNext());
    final AbstractAxis axis2 = new XPathAxis(holder.getReader(), "(1, 2, 3) < (2, 3)");
    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, 2, 3) > (3, 4)");
    assertEquals(true, axis3.hasNext());
    axis3.next();
    assertEquals(false, Boolean.parseBoolean(holder.getReader().getValue()));
    assertEquals(false, axis3.hasNext());
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) Test(org.junit.Test)

Example 10 with AbstractAxis

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

the class FunctionAxisTest method testFunctions.

@Test
public void testFunctions() throws SirixException {
    holder.getReader().moveTo(1L);
    final AbstractAxis axis1 = new XPathAxis(holder.getReader(), "fn:count(text())");
    assertEquals(true, axis1.hasNext());
    axis1.next();
    assertEquals(3, Integer.parseInt(holder.getReader().getValue()));
    assertEquals(false, axis1.hasNext());
    final AbstractAxis axis2 = new XPathAxis(holder.getReader(), "fn:count(//node())");
    assertEquals(true, axis2.hasNext());
    axis2.next();
    assertEquals(10, Integer.parseInt(holder.getReader().getValue()));
    assertEquals(false, axis2.hasNext());
    final AbstractAxis axis3 = new XPathAxis(holder.getReader(), "fn:string(//node())");
    assertEquals(true, axis3.hasNext());
    axis3.next();
    assertEquals("oops1 foo oops2 bar oops3 oops1 foo oops2 bar oops3 foo bar", holder.getReader().getValue());
    assertEquals(false, axis3.hasNext());
    final AbstractAxis axis4 = new XPathAxis(holder.getReader(), "fn:string()");
    assertEquals(true, axis4.hasNext());
    axis4.next();
    assertEquals("oops1 foo oops2 bar oops3", holder.getReader().getValue());
    assertEquals(false, axis4.hasNext());
    final AbstractAxis axis5 = new XPathAxis(holder.getReader(), "fn:string(./attribute::attribute())");
    assertEquals(true, axis5.hasNext());
    axis5.next();
    assertEquals("j", holder.getReader().getValue());
    assertEquals(false, axis5.hasNext());
    holder.getReader().moveToAttribute(0);
    final AbstractAxis axis6 = new XPathAxis(holder.getReader(), "fn:string()");
    assertEquals(true, axis6.hasNext());
    axis6.next();
    assertEquals("j", holder.getReader().getValue());
    assertEquals(false, axis6.hasNext());
}
Also used : XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) 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