use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class XpathMapperTest method testIdent.
@Test
public void testIdent() throws Exception {
final String xpath = "//CLASS_DEF/IDENT[@text='InputXpathMapperAst']";
final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
final List<NodeInfo> nodes = getXpathItems(xpath, rootNode);
final DetailAST[] actual = convertToArray(nodes);
final DetailAST expectedIdentNode = getSiblingByType(rootNode.getUnderlyingNode(), TokenTypes.COMPILATION_UNIT).findFirstToken(TokenTypes.CLASS_DEF).findFirstToken(TokenTypes.IDENT);
final DetailAST[] expected = { expectedIdentNode };
assertWithMessage("Result nodes differ from expected").that(actual).isEqualTo(expected);
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class XpathMapperTest method testQueryClassDefinitionByClassName.
@Test
public void testQueryClassDefinitionByClassName() throws Exception {
final String xpath = "//CLASS_DEF[./IDENT[@text='InputXpathMapperAst']]";
final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
final List<NodeInfo> nodes = getXpathItems(xpath, rootNode);
final DetailAST[] actual = convertToArray(nodes);
final DetailAST expectedClassDefNode = getSiblingByType(rootNode.getUnderlyingNode(), TokenTypes.COMPILATION_UNIT).findFirstToken(TokenTypes.CLASS_DEF);
final DetailAST[] expected = { expectedClassDefNode };
final ElementNode classDefNode = (ElementNode) nodes.get(0);
assertWithMessage("Invalid node name").that(classDefNode.getLocalPart()).isEqualTo("CLASS_DEF");
assertWithMessage("Result nodes differ from expected").that(actual).isEqualTo(expected);
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class XpathMapperTest method testNodeOrdering.
@Test
public void testNodeOrdering() throws Exception {
final String xpath = "//METHOD_DEF/SLIST/*";
final RootNode rootNode = getRootNode("InputXpathMapperAst.java");
final List<NodeInfo> nodes = getXpathItems(xpath, rootNode);
for (int i = 1; i < nodes.size(); i++) {
final NodeInfo curr = nodes.get(i);
final NodeInfo prev = nodes.get(i - 1);
if (curr.getLineNumber() == prev.getLineNumber()) {
assertWithMessage("Column number is not in document order").that(curr.getColumnNumber()).isGreaterThan(prev.getColumnNumber());
} else {
assertWithMessage("Line number is not in document order").that(curr.getLineNumber()).isGreaterThan(prev.getLineNumber());
}
}
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class PrecedingIteratorTest method testPrecedingNodes.
@Test
public void testPrecedingNodes() {
final NodeInfo startNode = findNode("SLIST");
try (PrecedingIterator iterator = new PrecedingIterator(startNode)) {
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("PARAMETERS"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("METHOD_DEF"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("LCURLY"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("OBJBLOCK"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("CLASS_DEF"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("ANNOTATIONS"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("ANNOTATION_DEF"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("PACKAGE_DEF"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("ROOT"));
assertWithMessage("Node should be null").that(iterator.next()).isNull();
assertWithMessage("Node should be null").that(iterator.next()).isNull();
}
}
use of net.sf.saxon.om.NodeInfo in project checkstyle by checkstyle.
the class PrecedingIteratorTest method testNoSibling.
@Test
public void testNoSibling() {
final NodeInfo startNode = findNode("ANNOTATIONS");
try (PrecedingIterator iterator = new PrecedingIterator(startNode)) {
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("PACKAGE_DEF"));
assertWithMessage("Invalid node").that(iterator.next()).isEqualTo(findNode("ROOT"));
assertWithMessage("Node should be null").that(iterator.next()).isNull();
}
}
Aggregations