Search in sources :

Example 36 with FileText

use of com.puppycrawl.tools.checkstyle.api.FileText in project checkstyle by checkstyle.

the class XpathQueryGeneratorTest method testTextBlocksWithNewCrlf.

@Test
public void testTextBlocksWithNewCrlf() throws Exception {
    final File testFile = new File(getNonCompilablePath("InputXpathQueryGeneratorTextBlockCrlf.java"));
    final FileText testFileText = new FileText(testFile, StandardCharsets.UTF_8.name());
    final DetailAST detailAst = JavaParser.parseFile(testFile, JavaParser.Options.WITHOUT_COMMENTS);
    final int tabWidth = 8;
    final int lineNumber = 6;
    final int columnNumber = 25;
    final XpathQueryGenerator queryGenerator = new XpathQueryGenerator(detailAst, lineNumber, columnNumber, testFileText, tabWidth);
    final List<String> actual = queryGenerator.generate();
    final List<String> expected = Collections.singletonList("/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorTextBlockCrlf']]/OBJBLOCK/" + "VARIABLE_DEF[./IDENT[@text='testOne']]/ASSIGN/EXPR/" + "TEXT_BLOCK_LITERAL_BEGIN/TEXT_BLOCK_CONTENT[@text='\\r\\n        " + "&amp;1line\\r\\n\\r\\n        &gt;2line\\r\\n        &lt;3line\\r\\n" + "        ']");
    assertWithMessage("Generated queries do not match expected ones").that(expected).isEqualTo(actual);
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 37 with FileText

use of com.puppycrawl.tools.checkstyle.api.FileText in project checkstyle by checkstyle.

the class XpathQueryGeneratorTest method testTabWidthBeforeSlist.

@Test
public void testTabWidthBeforeSlist() throws Exception {
    final File testFile = new File(getPath("InputXpathQueryGeneratorTabWidth.java"));
    final FileText testFileText = new FileText(testFile, StandardCharsets.UTF_8.name());
    final DetailAST detailAst = JavaParser.parseFile(testFile, JavaParser.Options.WITHOUT_COMMENTS);
    final int lineNumber = 12;
    final int columnNumber = 57;
    final int tabWidth = 8;
    final XpathQueryGenerator queryGenerator = new XpathQueryGenerator(detailAst, lineNumber, columnNumber, testFileText, tabWidth);
    final List<String> actual = queryGenerator.generate();
    final List<String> expected = Collections.singletonList("/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorTabWidth']]/OBJBLOCK" + "/METHOD_DEF[./IDENT[@text='tabAfterMe']]/SLIST");
    assertWithMessage("Generated queries do not match expected ones").that(actual).isEqualTo(expected);
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 38 with FileText

use of com.puppycrawl.tools.checkstyle.api.FileText in project checkstyle by checkstyle.

the class XpathQueryGeneratorTest method testTabWidthAfterVoidLiteral.

@Test
public void testTabWidthAfterVoidLiteral() throws Exception {
    final File testFile = new File(getPath("InputXpathQueryGeneratorTabWidth.java"));
    final FileText testFileText = new FileText(testFile, StandardCharsets.UTF_8.name());
    final DetailAST detailAst = JavaParser.parseFile(testFile, JavaParser.Options.WITHOUT_COMMENTS);
    final int lineNumber = 8;
    final int columnNumber = 41;
    final int tabWidth = 8;
    final XpathQueryGenerator queryGenerator = new XpathQueryGenerator(detailAst, lineNumber, columnNumber, testFileText, tabWidth);
    final List<String> actual = queryGenerator.generate();
    final List<String> expected = Arrays.asList("/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorTabWidth']]/OBJBLOCK" + "/METHOD_DEF[./IDENT[@text='getName']]/TYPE", "/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorTabWidth']]/OBJBLOCK" + "/METHOD_DEF[./IDENT[@text='getName']]/TYPE/LITERAL_VOID");
    assertWithMessage("Generated queries do not match expected ones").that(actual).isEqualTo(expected);
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 39 with FileText

use of com.puppycrawl.tools.checkstyle.api.FileText in project checkstyle by checkstyle.

the class XpathQueryGeneratorTest method init.

@BeforeEach
public void init() throws Exception {
    final File file = new File(getPath("InputXpathQueryGenerator.java"));
    fileText = new FileText(file, StandardCharsets.UTF_8.name());
    rootAst = JavaParser.parseFile(file, JavaParser.Options.WITH_COMMENTS);
}
Also used : FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 40 with FileText

use of com.puppycrawl.tools.checkstyle.api.FileText in project checkstyle by checkstyle.

the class XpathQueryGeneratorTest method testEscapeCharacters.

@Test
public void testEscapeCharacters() throws Exception {
    final File testFile = new File(getPath("InputXpathQueryGeneratorEscapeCharacters.java"));
    final FileText testFileText = new FileText(testFile, StandardCharsets.UTF_8.name());
    final DetailAST detailAst = JavaParser.parseFile(testFile, JavaParser.Options.WITHOUT_COMMENTS);
    final int tabWidth = 8;
    final int lineNumberOne = 4;
    final int columnNumberOne = 22;
    final XpathQueryGenerator queryGeneratorOne = new XpathQueryGenerator(detailAst, lineNumberOne, columnNumberOne, testFileText, tabWidth);
    final List<String> actualTestOne = queryGeneratorOne.generate();
    final List<String> expectedTestOne = Arrays.asList("/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorEscapeCharacters']]/" + "OBJBLOCK/VARIABLE_DEF[./IDENT[@text='testOne']]/ASSIGN/EXPR[./" + "STRING_LITERAL[@text='&lt;&gt;&apos;&apos;\\&quot;&amp;abc;&amp;lt;" + "\\u0080\\n']]", "/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorEscapeCharacters']]/" + "OBJBLOCK/VARIABLE_DEF[./IDENT[@text='testOne']]/ASSIGN/EXPR/" + "STRING_LITERAL[@text='&lt;&gt;&apos;&apos;\\&quot;&amp;abc;&amp;lt;" + "\\u0080\\n']");
    assertWithMessage("Generated queries do not match expected ones").that(actualTestOne).isEqualTo(expectedTestOne);
    final int lineNumberTwo = 6;
    final int columnNumberTwo = 22;
    final XpathQueryGenerator queryGeneratorTwo = new XpathQueryGenerator(detailAst, lineNumberTwo, columnNumberTwo, testFileText, tabWidth);
    final List<String> actualTestTwo = queryGeneratorTwo.generate();
    final List<String> expectedTestTwo = Arrays.asList("/COMPILATION_UNIT/CLASS_DEF[./IDENT" + "[@text='InputXpathQueryGeneratorEscapeCharacters']]/" + "OBJBLOCK/VARIABLE_DEF[./IDENT[@text='testTwo']]/ASSIGN/EXPR[./" + "STRING_LITERAL[@text='&amp;#0;&amp;#X0\\u0001\\r']]", "/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorEscapeCharacters']]/" + "OBJBLOCK/VARIABLE_DEF[./IDENT[@text='testTwo']]/ASSIGN/EXPR/" + "STRING_LITERAL[@text='&amp;#0;&amp;#X0\\u0001\\r']");
    assertWithMessage("Generated queries do not match expected ones").that(actualTestTwo).isEqualTo(expectedTestTwo);
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

FileText (com.puppycrawl.tools.checkstyle.api.FileText)49 File (java.io.File)41 Test (org.junit.jupiter.api.Test)29 FileContents (com.puppycrawl.tools.checkstyle.api.FileContents)18 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)15 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)7 Violation (com.puppycrawl.tools.checkstyle.api.Violation)7 ArrayList (java.util.ArrayList)6 TreeWalkerAuditEvent (com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent)5 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)4 TypeNameCheck (com.puppycrawl.tools.checkstyle.checks.naming.TypeNameCheck)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 TestLoggingReporter (com.puppycrawl.tools.checkstyle.internal.testmodules.TestLoggingReporter)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 RecognitionException (antlr.RecognitionException)1 TokenStreamException (antlr.TokenStreamException)1 TokenStreamRecognitionException (antlr.TokenStreamRecognitionException)1 ClassPath (com.google.common.reflect.ClassPath)1 LineColumn (com.puppycrawl.tools.checkstyle.api.LineColumn)1