Skip to content

Commit

Permalink
Cannot verify whitespace related requirements as `TestMode.TEXT_MATCH…
Browse files Browse the repository at this point in the history
…` formats the sources
  • Loading branch information
benhalasi committed May 24, 2023
1 parent 17b7e2d commit 8a9c219
Showing 1 changed file with 105 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,12 @@ void replacementFirstSuggestedFix() {
.doTest(TestMode.TEXT_MATCH);
}

@SuppressWarnings("ErrorProneTestHelperSourceFormat")
@Test
void replacementSecondSuggestedFix() {
BugCheckerRefactoringTestHelper.newInstance(MemberOrdering.class, getClass())
.setFixChooser(SECOND)
.addInputLines(
"A.java",
"",
"class A {",
" private static final int X = 1;",
" char a = 'a';",
Expand All @@ -145,17 +143,19 @@ void replacementSecondSuggestedFix() {
"",
" void m2() {}",
"",
" public A () {}",
" public A() {}",
"",
" private static String BAR = \"bar\";",
" char b = 'b';",
"",
" void m1() {",
" System.out.println(\"foo\");",
" }",
"",
" static int TWO = 2;",
"",
" class Inner {}",
"",
" static class StaticInner {}",
"}")
.addOutputLines(
Expand All @@ -171,48 +171,49 @@ void replacementSecondSuggestedFix() {
" char a = 'a';",
"",
" char b = 'b';",
" public A () {}",
"",
" public A() {}",
"",
" void m2() {}",
"",
" void m1() {",
" System.out.println(\"foo\");",
" }",
"",
" class Inner {}",
"",
" static class StaticInner {}",
"}")
.doTest(TestMode.TEXT_MATCH);
}

@SuppressWarnings("ErrorProneTestHelperSourceFormat")
@Test
void replacementSecondSuggestedFixWithDefaultConstructor() {
void replacementSecondSuggestedFixConsidersDefaultConstructor() {
BugCheckerRefactoringTestHelper.newInstance(MemberOrdering.class, getClass())
.setFixChooser(SECOND)
.addInputLines(
"A.java",
"",
"class A {",
" void m1 () {}",
" void m1() {}",
"",
" char c = 'c';",
" private static final String foo = \"foo\";",
" static int one = 1;",
"}")
.addOutputLines(
"A.java",
"",
"class A {",
" private static final String foo = \"foo\";",
" static int one = 1;",
" char c = 'c';",
" void m1 () {}",
"",
" void m1() {}",
"}")
.doTest(TestMode.TEXT_MATCH);
}

@SuppressWarnings("ErrorProneTestHelperSourceFormat")
@Test
void replacementSecondSuggestedFixWithComments() {
void replacementSecondSuggestedFixConsidersComments() {
BugCheckerRefactoringTestHelper.newInstance(MemberOrdering.class, getClass())
.setFixChooser(SECOND)
.addInputLines(
Expand All @@ -223,16 +224,18 @@ void replacementSecondSuggestedFixWithComments() {
" // Print line 'foo' to stdout.",
" System.out.println(\"foo\");",
" }",
"",
" // foo",
" /** Instantiates a new {@link A} instance. */",
" public A () {}",
" public A() {}",
"}")
.addOutputLines(
"A.java",
"class A {",
" // foo",
" /** Instantiates a new {@link A} instance. */",
" public A () {}",
" public A() {}",
"",
" // `m1()` comment.",
" void m1() {",
" // Print line 'foo' to stdout.",
Expand All @@ -242,6 +245,94 @@ void replacementSecondSuggestedFixWithComments() {
.doTest(TestMode.TEXT_MATCH);
}

@SuppressWarnings("ErrorProneTestHelperSourceFormat")
@Test
void replacementSecondSuggestedFixDoesNotModifyWhitespace() {
BugCheckerRefactoringTestHelper.newInstance(MemberOrdering.class, getClass())
.setFixChooser(SECOND)
.addInputLines(
"A.java",
"",
"",
"class A {",
"",
"",
" // `m1()` comment.",
" void m1() {",
" // Print line 'foo' to stdout.",
" System.out.println(\"foo\");",
" }",
" public A () { }",
"",
"",
"}")
.addOutputLines(
"A.java",
"",
"",
"class A {",
"",
"",
"",
" public A () { }",
" // `m1()` comment.",
" void m1() {",
" // Print line 'foo' to stdout.",
" System.out.println(\"foo\");",
" }",
"",
"",
"}")
.doTest();
}

@SuppressWarnings("ErrorProneTestHelperSourceFormat")
@Test
void xxx() { // todo: Actually test that the whitespace is preserved.
BugCheckerRefactoringTestHelper.newInstance(MemberOrdering.class, getClass())
.setFixChooser(SECOND)
.addInputLines(
"A.java",
"",
"",
"class A {",
"",
"",
" // `m1()` comment.",
" void m1() {",
" // Print line 'foo' to stdout.",
" System.out.println(\"foo\");",
" }",
" public A () { }",
"",
"",
"}")
.addOutputLines(
"A.java",
"",
"",
"class A {",
"",
" ",
" ",
" \t \t",
" ",
" ",
"",
" public A () { }",
" // `m1()` comment.",
" void m1",
" ()",
" {",
" // Print line 'foo' to stdout.",
" System.out.println(\"foo\");",
" }",
"",
"",
"}")
.doTest(TestMode.TEXT_MATCH);
}

// todo: Test if second replacement considers annotations.
// todo: Chose between with, handles, considers, respects and regards for
// replacementSecondSuggestedFixXxxSomething
Expand Down

0 comments on commit 8a9c219

Please sign in to comment.