use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class XpathFilterElementTest method testNonMatchingTokenType.
@Test
public void testNonMatchingTokenType() throws Exception {
final String xpath = "//METHOD_DEF[./IDENT[@text='countTokens']]";
final XpathFilterElement filter = new XpathFilterElement("InputXpathFilterElementSuppressByXpath", "Test", null, null, xpath);
final TreeWalkerAuditEvent ev = getEvent(4, 4, TokenTypes.CLASS_DEF);
assertWithMessage("Event should be accepted").that(filter.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class XpathFilterElementTest method testComplexQuery.
@Test
public void testComplexQuery() throws Exception {
final String xpath = "//VARIABLE_DEF[./IDENT[@text='pi'] and " + "../../IDENT[@text='countTokens']] " + "| //VARIABLE_DEF[./IDENT[@text='someVariable'] and ../../IDENT[@text='sum']]";
final XpathFilterElement filter = new XpathFilterElement("InputXpathFilterElementSuppressByXpath", "Test", null, null, xpath);
final TreeWalkerAuditEvent eventOne = getEvent(5, 8, TokenTypes.VARIABLE_DEF);
final TreeWalkerAuditEvent eventTwo = getEvent(10, 4, TokenTypes.VARIABLE_DEF);
final TreeWalkerAuditEvent eventThree = getEvent(15, 8, TokenTypes.VARIABLE_DEF);
assertWithMessage("Event should be rejected").that(filter.accept(eventOne)).isFalse();
assertWithMessage("Event should be accepted").that(filter.accept(eventTwo)).isTrue();
assertWithMessage("Event should be rejected").that(filter.accept(eventThree)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class XpathFilterElementTest method testDecideByMessage.
@Test
public void testDecideByMessage() throws Exception {
final Violation message = new Violation(1, 0, TokenTypes.CLASS_DEF, "", "", null, null, null, getClass(), "Test");
final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(fileContents, file.getName(), message, JavaParser.parseFile(file, JavaParser.Options.WITHOUT_COMMENTS));
final XpathFilterElement filter1 = new XpathFilterElement(null, null, "Test", null, null);
final XpathFilterElement filter2 = new XpathFilterElement(null, null, "Bad", null, null);
assertWithMessage("Message match").that(filter1.accept(ev)).isFalse();
assertWithMessage("Message not match").that(filter2.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class XpathFilterElementTest method testNonMatchingLineNumber.
@Test
public void testNonMatchingLineNumber() throws Exception {
final String xpath = "//CLASS_DEF[./IDENT[@text='InputXpathFilterElementSuppressByXpath']]";
final XpathFilterElement filter = new XpathFilterElement("InputXpathFilterElementSuppressByXpath", "Test", null, null, xpath);
final TreeWalkerAuditEvent ev = getEvent(100, 0, TokenTypes.CLASS_DEF);
assertWithMessage("Event should be accepted").that(filter.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class XpathFilterElementTest method testMatching.
@Test
public void testMatching() throws Exception {
final String xpath = "//CLASS_DEF[./IDENT[@text='InputXpathFilterElementSuppressByXpath']]";
final XpathFilterElement filter = new XpathFilterElement("InputXpathFilterElementSuppressByXpath", "Test", null, null, xpath);
final TreeWalkerAuditEvent ev = getEvent(3, 0, TokenTypes.CLASS_DEF);
assertWithMessage("Event should be rejected").that(filter.accept(ev)).isFalse();
}
Aggregations