Skip to content

Commit

Permalink
test: Add test reproducing issue #4021 (#4030)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtoison authored Jul 8, 2021
1 parent d7b8daa commit ff7798f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/test/java/spoon/test/prettyprinter/TestSniperPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package spoon.test.prettyprinter;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import spoon.Launcher;
Expand Down Expand Up @@ -40,6 +41,7 @@
import spoon.support.modelobs.ChangeCollector;
import spoon.support.modelobs.SourceFragmentCreator;
import spoon.support.sniper.SniperJavaPrettyPrinter;
import spoon.test.GitHubIssue;
import spoon.test.prettyprinter.testclasses.OneLineMultipleVariableDeclaration;
import spoon.test.prettyprinter.testclasses.Throw;
import spoon.test.prettyprinter.testclasses.InvocationReplacement;
Expand Down Expand Up @@ -772,6 +774,21 @@ void testSniperRespectsDeletionInForUpdate() {

testSniper("ForLoop", deleteForUpdate, assertNotStaticFindFirstIsEmpty);
}

@Test
@Disabled("UnresolvedBug")
@GitHubIssue(issueNumber = 4021)
void testSniperRespectsSuperWithUnaryOperator() {
// Combining CtSuperAccess and CtUnaryOperator leads to SpoonException with Sniper

// Noop
Consumer<CtType<?>> deleteForUpdate = type -> {};

BiConsumer<CtType<?>, String> assertContainsSuperWithUnaryOperator = (type, result) ->
assertThat(result, containsString("super.a(-x);"));

testSniper("superCall.SuperCallSniperTestClass", deleteForUpdate, assertContainsSuperWithUnaryOperator);
}

/**
* 1) Runs spoon using sniper mode,
Expand Down
18 changes: 18 additions & 0 deletions src/test/resources/superCall/SuperCallSniperTestClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package superCall;

/**
* Test class to reproduce issue #4021
*/
public class SuperCallSniperTestClass {
int m = 0;

public int a(int x) {
return x;
}
}

class Child extends SuperCallSniperTestClass {
public int b(int x) {
return super.a(-x);
}
}

0 comments on commit ff7798f

Please sign in to comment.