Skip to content

Commit

Permalink
Introduce failing test case for INRIA#4018
Browse files Browse the repository at this point in the history
  • Loading branch information
algomaster99 committed Nov 11, 2021
1 parent 7052a94 commit c3d6daf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/test/java/spoon/test/prettyprinter/TestSniperPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import spoon.reflect.code.CtStatement;
import spoon.reflect.code.CtThrow;
import spoon.reflect.cu.SourcePosition;
import spoon.reflect.declaration.CtAnnotation;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtCompilationUnit;
import spoon.reflect.declaration.CtElement;
Expand All @@ -39,7 +40,6 @@
import spoon.reflect.declaration.CtType;
import spoon.reflect.declaration.ModifierKind;
import spoon.reflect.factory.Factory;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtReference;
import spoon.reflect.reference.CtTypeReference;
Expand Down Expand Up @@ -74,7 +74,7 @@
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -797,6 +797,19 @@ void testSniperRespectsSuperWithUnaryOperator() {
testSniper("superCall.SuperCallSniperTestClass", deleteForUpdate, assertContainsSuperWithUnaryOperator);
}

@Test
@GitHubIssue(issueNumber = 4018)
void testSniperDeletesAnnotation() {
Consumer<CtType<?>> deleteAnnotation = type -> {
type.getAnnotations().forEach(CtAnnotation::delete);
};

BiConsumer<CtType<?>, String> assertDoesNotContainAnnotation = (type, result) ->
assertThat(result, not(containsString("@abc.def.xyz")));

testSniper("sniperPrinter.DeleteAnnotation", deleteAnnotation, assertDoesNotContainAnnotation);
}

/**
* 1) Runs spoon using sniper mode,
* 2) runs `typeChanger` to modify the code,
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/sniperPrinter/DeleteAnnotation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package sniperPrinter;

@abc.def.xyz
class DeleteAnnotation { }

0 comments on commit c3d6daf

Please sign in to comment.