use of org.sirix.service.xml.xpath.XPathAxis 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());
}
}
use of org.sirix.service.xml.xpath.XPathAxis 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());
}
use of org.sirix.service.xml.xpath.XPathAxis in project sirix by sirixdb.
the class ExceptAxisTest method testExcept.
@Test
public void testExcept() throws SirixException {
holder.getReader().moveTo(1L);
AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "child::node() except b"), new long[] { 4L, 8L, 13L });
AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "child::node() except child::node()[attribute::p:x]"), new long[] { 4L, 5L, 8L, 13L });
AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "child::node()/parent::node() except self::node()"), new long[] {});
AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "//node() except //text()"), new long[] { 1L, 5L, 9L, 7L, 11L });
holder.getReader().moveTo(1L);
AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "b/preceding::node() except text()"), new long[] { 7L, 6L, 5L });
}
use of org.sirix.service.xml.xpath.XPathAxis in project sirix by sirixdb.
the class IfAxisTest method testIf.
@Test
public void testIf() throws SirixException {
holder.getReader().moveTo(1L);
AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "if (text()) then . else child::node()"), new long[] { 1L });
AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "if (node()) then . else child::node()"), new long[] { 1L });
AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "if (processing-instruction()) then . else child::node()"), new long[] { 4L, 5L, 8L, 9L, 13L });
}
use of org.sirix.service.xml.xpath.XPathAxis in project sirix by sirixdb.
the class SomeExprTest method testEveryExpr.
@Test
public void testEveryExpr() throws SirixException {
final AbstractAxis axis1 = new XPathAxis(holder.getReader(), "some $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(), "some $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(), "some $child in child::node() satisfies $child/attribute::attribute()");
assertEquals(true, axis3.hasNext());
axis3.next();
assertEquals(true, Boolean.parseBoolean(holder.getReader().getValue()));
assertEquals(false, axis3.hasNext());
}
Aggregations