Search in sources :

Example 21 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class RootNodeTest method testXpath.

@Test
public void testXpath() throws Exception {
    final String xpath = "/";
    final List<NodeInfo> nodes = getXpathItems(xpath, rootNode);
    assertWithMessage("Invalid number of nodes").that(nodes).hasSize(1);
    final NodeInfo firstNode = nodes.get(0);
    assertWithMessage("Should return true, because selected node is RootNode").that(firstNode instanceof RootNode).isTrue();
    assertWithMessage("Result node should have same reference as expected").that(rootNode).isEqualTo(firstNode);
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.jupiter.api.Test)

Example 22 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class FollowingIteratorTest method testFollowingSibling.

@Test
public void testFollowingSibling() {
    final NodeInfo startNode = findNode("ANNOTATIONS");
    try (FollowingIterator iterator = new FollowingIterator(startNode)) {
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("CLASS_DEF"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("OBJBLOCK"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("LCURLY"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("METHOD_DEF"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("RCURLY"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("PARAMETERS"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("SLIST"));
        assertWithMessage("Node should be null").that(iterator.next()).isNull();
        assertWithMessage("Node should be null").that(iterator.next()).isNull();
    }
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.jupiter.api.Test)

Example 23 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class XpathMapperTest method testQuerySelf.

@Test
public void testQuerySelf() throws Exception {
    final String objectXpath = "//CLASS_DEF[./IDENT[@text='InputXpathMapperAst']]//OBJBLOCK";
    final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
    final List<NodeInfo> objectNodes = getXpathItems(objectXpath, rootNode);
    assertWithMessage("Invalid number of nodes").that(objectNodes).hasSize(1);
    final AbstractNode objNode = (AbstractNode) objectNodes.get(0);
    final String methodsXpath = "self::OBJBLOCK";
    final DetailAST[] actual = convertToArray(getXpathItems(methodsXpath, objNode));
    final DetailAST expectedObjBlockNode = getSiblingByType(rootNode.getUnderlyingNode(), TokenTypes.COMPILATION_UNIT).findFirstToken(TokenTypes.CLASS_DEF).findFirstToken(TokenTypes.OBJBLOCK);
    final DetailAST[] expected = { expectedObjBlockNode };
    assertWithMessage("Result nodes differ from expected").that(actual).isEqualTo(expected);
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.jupiter.api.Test)

Example 24 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class XpathMapperTest method testQueryAllClassDefinitions.

@Test
public void testQueryAllClassDefinitions() throws Exception {
    final String xpath = "/COMPILATION_UNIT/CLASS_DEF";
    final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
    final List<NodeInfo> nodes = getXpathItems(xpath, rootNode);
    assertWithMessage("Invalid number of nodes").that(nodes).hasSize(1);
    final AbstractNode classDefNode = (AbstractNode) nodes.get(0);
    assertWithMessage("Invalid line number").that(classDefNode.getLineNumber()).isEqualTo(3);
    assertWithMessage("Invalid column number").that(classDefNode.getColumnNumber()).isEqualTo(0);
    final DetailAST[] actual = convertToArray(nodes);
    final DetailAST expectedClassDefNode = getSiblingByType(rootNode.getUnderlyingNode(), TokenTypes.COMPILATION_UNIT).findFirstToken(TokenTypes.CLASS_DEF);
    final DetailAST[] expected = { expectedClassDefNode };
    assertWithMessage("Result nodes differ from expected").that(actual).isEqualTo(expected);
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.jupiter.api.Test)

Example 25 with NodeInfo

use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.

the class DescendantIteratorTest method testIncludeSelf.

@Test
public void testIncludeSelf() {
    final NodeInfo startNode = findNode("CLASS_DEF");
    try (DescendantIterator iterator = new DescendantIterator(startNode, DescendantIterator.StartWith.CURRENT_NODE)) {
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(startNode);
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("OBJBLOCK"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("LCURLY"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("METHOD_DEF"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("RCURLY"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("PARAMETERS"));
        assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("SLIST"));
        assertWithMessage("Node should be null").that(iterator.next()).isNull();
        assertWithMessage("Node should be null").that(iterator.next()).isNull();
    }
}
Also used : NodeInfo(net.sf.saxon.om.NodeInfo) Test(org.junit.jupiter.api.Test)

Aggregations

NodeInfo (net.sf.saxon.om.NodeInfo)52 Test (org.junit.Test)21 XPathExpression (javax.xml.xpath.XPathExpression)16 Test (org.junit.jupiter.api.Test)14 Processor (net.sf.saxon.s9api.Processor)8 Configuration (net.sf.saxon.Configuration)7 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)5 DocumentWrapper (org.sirix.saxon.wrapper.DocumentWrapper)5 NameTest (net.sf.saxon.pattern.NameTest)4 SaxonApiException (net.sf.saxon.s9api.SaxonApiException)4 XQueryCompiler (net.sf.saxon.s9api.XQueryCompiler)3 XQueryExecutable (net.sf.saxon.s9api.XQueryExecutable)3 AxisIterator (net.sf.saxon.tree.iter.AxisIterator)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Item (net.sf.saxon.om.Item)2 Serializer (net.sf.saxon.s9api.Serializer)2 NodeReadTrx (org.sirix.api.NodeReadTrx)2 NodeList (org.w3c.dom.NodeList)2