Skip to content

Commit

Permalink
test: Add test for fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Al-Istannen committed Nov 17, 2024
1 parent 3299157 commit f73d5e0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/test/java/spoon/test/comment/CommentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;
import spoon.Launcher;
import spoon.LauncherTest;
import spoon.SpoonException;
import spoon.reflect.CtModel;
import spoon.reflect.code.CtArrayAccess;
Expand Down Expand Up @@ -110,6 +111,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static spoon.testing.assertions.SpoonAssertions.assertThat;


public class CommentTest {
Expand Down Expand Up @@ -1325,4 +1327,30 @@ public void testTypeParameterComments(CtModel model) {
assertEquals("comment 3", typeParameters.get(1).getComments().get(1).getContent());
assertEquals("comment 4", typeParameters.get(1).getComments().get(2).getContent());
}

@Test
@GitHubIssue(issueNumber = 6069, fixed = true)
@ExtendWith(LineSeparatorExtension.class)
public void testCommentInLambda() {
// contract: Comments inside lambdas should not crash or disappear.
CtClass<?> ctClass = Launcher.parseClass("""
class Foo {
public void bar() {
Runnable r = () -> {
/* hello */ System.exit(1);
};
Runnable b = () -> /* hello2 */ System.exit(1);
Runnable c = /* hello3 */ () -> System.exit(1);
java.util.function.IntFunction<Void> d = ( /* hello4 */ int a ) -> null;
int e = /* hello5 */ 5;
}
}
""");
assertThat(ctClass).asString().contains("/* hello */");
// Wrong output, there should not be a newline here. Codify it for now in the test case
assertThat(ctClass).asString().containsPattern("/\\* hello2 \\*/\n\\s+System");
assertThat(ctClass).asString().contains("/* hello3 */");
assertThat(ctClass).asString().contains("/* hello4 */");
assertThat(ctClass).asString().contains("/* hello5 */");
}
}

0 comments on commit f73d5e0

Please sign in to comment.