use of org.sonar.duplications.internal.pmd.TokensLine in project sonar-go by SonarSource.
the class CpdVisitorTest method test.
@Test
void test() throws IOException {
String filename = "lets.go";
String code = readTestResource(getClass(), filename);
String codeJson = readTestResource(getClass(), filename + ".uast.json");
InputFile inputFile = createInputFile("lets.go", code);
sensorContext.fileSystem().add(inputFile);
CpdVisitor cpdVisitor = new CpdVisitor(sensorContext, inputFile);
UastNode node = Uast.from(new StringReader(codeJson));
cpdVisitor.scan(node);
cpdVisitor.save();
List<TokensLine> tokensLines = sensorContext.cpdTokens("module:" + inputFile.filename());
assertThat(tokensLines).isNotNull().hasSize(5);
assertThat(tokensLines).extracting("value").isEqualTo(Arrays.asList("packagemain", "funcfun()string{", "a:=LITERAL", "returna", "}"));
assertThat(tokensLines).extracting("startLine").isEqualTo(Arrays.asList(1, 3, 4, 5, 6));
}
use of org.sonar.duplications.internal.pmd.TokensLine in project sonarqube by SonarSource.
the class DefaultCpdTokens method addNewTokensLine.
private static void addNewTokensLine(ImmutableList.Builder<TokensLine> result, int startUnit, int endUnit, int startLine, StringBuilder sb) {
if (sb.length() != 0) {
result.add(new TokensLine(startUnit, endUnit, startLine, sb.toString()));
sb.setLength(0);
}
}
Aggregations