use of org.sonar.duplications.index.CloneGroup in project sonarqube by SonarSource.
the class DetectorTestCase method problemWithNestedCloneGroups.
/**
* Given:
* <pre>
* b: 1 2 1 2 1 2 1
* a: 1 2 1 2 1 2
* </pre>
* Expected:
* <pre>
* a-b-b (1 2 1 2 1) - note that there is overlapping among parts for "b"
* a-b (1 2 1 2 1 2)
* </pre>
*/
@Test
public void problemWithNestedCloneGroups() {
CloneIndex index = createIndex(newBlocks("b", "1 2 1 2 1 2 1"));
Block[] fileBlocks = newBlocks("a", "1 2 1 2 1 2");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
assertThat(result.size(), is(2));
assertThat(result, hasCloneGroup(6, newClonePart("a", 0, 6), newClonePart("b", 0, 6)));
assertThat(result, hasCloneGroup(5, newClonePart("a", 0, 5), newClonePart("b", 0, 5), newClonePart("b", 2, 5)));
}
use of org.sonar.duplications.index.CloneGroup in project sonarqube by SonarSource.
the class FilterTest method second_part_of_C2_covers_first_part_of_C1.
/**
* Given:
* <pre>
* c1: a[2-2]
* c2: a[0-1], a[2-3]
* </pre>
* Expected:
* <pre>
* c1 in c2
* c2 not in c1
* </pre>
*/
@Test
public void second_part_of_C2_covers_first_part_of_C1() {
CloneGroup c1 = newCloneGroup(1, newClonePart("a", 2));
CloneGroup c2 = newCloneGroup(2, newClonePart("a", 0), newClonePart("a", 2));
assertThat(Filter.containsIn(c1, c2), is(true));
assertThat(Filter.containsIn(c2, c1), is(false));
}
use of org.sonar.duplications.index.CloneGroup in project sonarqube by SonarSource.
the class FilterTest method start_index_in_C1_less_than_in_C2.
/**
* Given:
* <pre>
* c1: a[1-1]
* c2: a[2-2]
* </pre>
* Expected: c1 not in c2, c2 not in c1
*/
@Test
public void start_index_in_C1_less_than_in_C2() {
CloneGroup c1 = newCloneGroup(1, newClonePart("a", 1));
CloneGroup c2 = newCloneGroup(1, newClonePart("a", 2));
assertThat(Filter.containsIn(c1, c2), is(false));
}
use of org.sonar.duplications.index.CloneGroup in project sonarqube by SonarSource.
the class FilterTest method reflexive_and_antisymmetric.
/**
* Given:
* <pre>
* c1: a[1-1]
* c2: a[1-1]
* </pre>
* Expected:
* reflexive - c1 in c1,
* antisymmetric - c1 in c2, c2 in c1, because c1 = c2
*/
@Test
public void reflexive_and_antisymmetric() {
CloneGroup c1 = newCloneGroup(1, newClonePart("a", 1));
CloneGroup c2 = newCloneGroup(1, newClonePart("a", 1));
assertThat(Filter.containsIn(c1, c1), is(true));
assertThat(Filter.containsIn(c1, c2), is(true));
assertThat(Filter.containsIn(c2, c1), is(true));
}
use of org.sonar.duplications.index.CloneGroup in project sonarqube by SonarSource.
the class CpdExecutorTest method reportTooManyDuplicates.
@Test
public void reportTooManyDuplicates() throws Exception {
// 1 origin part + 101 duplicates = 102
List<ClonePart> parts = new ArrayList<>(CpdExecutor.MAX_CLONE_PART_PER_GROUP + 2);
for (int i = 0; i < CpdExecutor.MAX_CLONE_PART_PER_GROUP + 2; i++) {
parts.add(new ClonePart(batchComponent1.key(), i, i, i + 1));
}
List<CloneGroup> groups = Arrays.asList(CloneGroup.builder().setLength(0).setOrigin(parts.get(0)).setParts(parts).build());
executor.saveDuplications(batchComponent1, groups);
Duplication[] dups = readDuplications(1);
assertThat(dups[0].getDuplicateList()).hasSize(CpdExecutor.MAX_CLONE_PART_PER_GROUP);
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Too many duplication references on file " + batchComponent1 + " for block at line 0. Keep only the first " + CpdExecutor.MAX_CLONE_PART_PER_GROUP + " references.");
}
Aggregations