-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
166 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
plugin-gradle/src/test/java/com/diffplug/gradle/spotless/IndentIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2021-2024 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.gradle.spotless; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.util.stream.Stream; | ||
|
||
import org.gradle.testkit.runner.BuildResult; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class IndentIntegrationTest extends GradleIntegrationHarness { | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"indentWithSpaces", "indentWithTabs"}) | ||
void oldIndentApiLogsDeprecationWarning(String indentationMethodName) throws IOException { | ||
BuildResult result = runIndentFormatter(indentationMethodName); | ||
assertThat(result.getOutput()).containsPattern(".*" + indentationMethodName + ".*deprecated.*"); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"leadingTabsToSpaces", "leadingSpacesToTabs"}) | ||
void newIndentApiDoesNotLogDeprecationWarning(String indentationMethodName) throws IOException { | ||
BuildResult result = runIndentFormatter(indentationMethodName); | ||
assertThat(result.getOutput()).doesNotContainPattern(".*" + indentationMethodName + ".*deprecated.*"); | ||
} | ||
|
||
@ParameterizedTest(name = "{0}") | ||
@MethodSource("indentationCombinations") | ||
void indentationCombinations(String testName, String indentationMethodName, String actualResource, String expectedResultResource) throws IOException { | ||
runIndentFormatter(indentationMethodName, actualResource); | ||
assertFile("test.txt").sameAsResource(expectedResultResource); | ||
} | ||
|
||
private static Stream<Arguments> indentationCombinations() { | ||
return Stream.of( | ||
// new API | ||
Arguments.of("tabsToTabs", "leadingSpacesToTabs", "indent/IndentedWithTab.test", "indent/IndentedWithTab.test"), | ||
Arguments.of("spacesToSpaces", "leadingTabsToSpaces", "indent/IndentedWithSpace.test", "indent/IndentedWithSpace.test"), | ||
Arguments.of("spacesToTabs", "leadingSpacesToTabs", "indent/IndentedWithSpace.test", "indent/IndentedWithTab.test"), | ||
Arguments.of("tabsToSpaces", "leadingTabsToSpaces", "indent/IndentedWithTab.test", "indent/IndentedWithSpace.test"), | ||
Arguments.of("mixedToTabs", "leadingSpacesToTabs", "indent/IndentedMixed.test", "indent/IndentedWithTab.test"), | ||
Arguments.of("mixedToSpaces", "leadingTabsToSpaces", "indent/IndentedMixed.test", "indent/IndentedWithSpace.test"), | ||
// legacy API | ||
Arguments.of("legacy: tabsToTabs", "indentWithTabs", "indent/IndentedWithTab.test", "indent/IndentedWithTab.test"), | ||
Arguments.of("legacy: spacesToSpaces", "indentWithSpaces", "indent/IndentedWithSpace.test", "indent/IndentedWithSpace.test"), | ||
Arguments.of("legacy: spacesToTabs", "indentWithTabs", "indent/IndentedWithSpace.test", "indent/IndentedWithTab.test"), | ||
Arguments.of("legacy: tabsToSpaces", "indentWithSpaces", "indent/IndentedWithTab.test", "indent/IndentedWithSpace.test"), | ||
Arguments.of("legacy: mixedToTabs", "indentWithTabs", "indent/IndentedMixed.test", "indent/IndentedWithTab.test"), | ||
Arguments.of("legacy: mixedToSpaces", "indentWithSpaces", "indent/IndentedMixed.test", "indent/IndentedWithSpace.test")); | ||
} | ||
|
||
private BuildResult runIndentFormatter(String indentationMethodName) throws IOException { | ||
return runIndentFormatter(indentationMethodName, "indent/IndentedMixed.test"); | ||
} | ||
|
||
private BuildResult runIndentFormatter(String indentationMethodName, String resourceFile) throws IOException { | ||
setFile("build.gradle").toLines( | ||
"plugins {", | ||
" id 'com.diffplug.spotless'", | ||
"}", | ||
"spotless {", | ||
" format 'test', {", | ||
" target '**/*.txt'", | ||
" " + indentationMethodName + "()", | ||
" }", | ||
"}"); | ||
setFile("test.txt").toResource(resourceFile); | ||
BuildResult result = gradleRunner().withArguments("spotlessApply").build(); | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.github.youribonnaffe.gradle.format; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* Test class. | ||
*/ | ||
public class Java8Test { | ||
/** | ||
* Test method. | ||
*/ | ||
public void doStuff() throws Exception { | ||
Function<String, Integer> example = Integer::parseInt; | ||
example.andThen(val -> { | ||
return val + 2; | ||
} ); | ||
SimpleEnum val = SimpleEnum.A; | ||
switch (val) { | ||
case A: | ||
break; | ||
case B: | ||
break; | ||
case C: | ||
break; | ||
default: | ||
throw new Exception(); | ||
} | ||
} | ||
|
||
/** Test enum | ||
* with weirdly formatted javadoc | ||
* which IndentStep should not change | ||
*/ | ||
public enum SimpleEnum { | ||
A, B, C; | ||
} | ||
} |