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 " + "&1line\\r\\n\\r\\n >2line\\r\\n <3line\\r\\n" + " ']");
assertWithMessage("Generated queries do not match expected ones").that(expected).isEqualTo(actual);
}
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);
}
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);
}
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);
}
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='<>''\\"&abc;&lt;" + "\\u0080\\n']]", "/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorEscapeCharacters']]/" + "OBJBLOCK/VARIABLE_DEF[./IDENT[@text='testOne']]/ASSIGN/EXPR/" + "STRING_LITERAL[@text='<>''\\"&abc;&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='&#0;&#X0\\u0001\\r']]", "/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathQueryGeneratorEscapeCharacters']]/" + "OBJBLOCK/VARIABLE_DEF[./IDENT[@text='testTwo']]/ASSIGN/EXPR/" + "STRING_LITERAL[@text='&#0;&#X0\\u0001\\r']");
assertWithMessage("Generated queries do not match expected ones").that(actualTestTwo).isEqualTo(expectedTestTwo);
}
Aggregations