Skip to content

Commit a473521

Browse files
committed
chore: add tests for eclipse-wtp using config files
1 parent cc3b051 commit a473521

File tree

12 files changed

+472
-0
lines changed

12 files changed

+472
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.cli.steps;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.parallel.Isolated;
20+
21+
import com.diffplug.spotless.tag.CliNativeTest;
22+
import com.diffplug.spotless.tag.CliProcessTest;
23+
import com.diffplug.spotless.tag.SeparateJvmTest;
24+
25+
@Isolated
26+
@SeparateJvmTest
27+
@CliNativeTest
28+
@CliProcessTest
29+
public class EclipseWtpCssWithConfigTest extends EclipseWtpTestBase {
30+
31+
@Test
32+
void itUsesConfigurationFile() {
33+
String fileName = runEclipseWtpWithTypeAndConfigFile(
34+
EclipseWtp.Type.CSS,
35+
"body {\n" + "a: v; b: \n" + "v;\n" + "} \n",
36+
"org.eclipse.wst.css.core.prefs");
37+
selfie().expectResource(fileName).toMatchDisk();
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.cli.steps;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.parallel.Isolated;
20+
21+
import com.diffplug.spotless.tag.CliNativeTest;
22+
import com.diffplug.spotless.tag.CliProcessTest;
23+
import com.diffplug.spotless.tag.SeparateJvmTest;
24+
25+
@Isolated
26+
@SeparateJvmTest
27+
@CliNativeTest
28+
@CliProcessTest
29+
public class EclipseWtpHtmlWithConfigTest extends EclipseWtpTestBase {
30+
31+
@Test
32+
void itUsesConfigurationFile() {
33+
String fileName = runEclipseWtpWithTypeAndConfigFile(
34+
EclipseWtp.Type.HTML,
35+
"<!DOCTYPE html> <html>\t<head> <meta charset=\"UTF-8\"></head>\n" + "</html> ",
36+
"org.eclipse.wst.html.core.prefs");
37+
selfie().expectResource(fileName).toMatchDisk();
38+
}
39+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.cli.steps;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.parallel.Isolated;
20+
21+
import com.diffplug.spotless.tag.CliNativeTest;
22+
import com.diffplug.spotless.tag.CliProcessTest;
23+
import com.diffplug.spotless.tag.SeparateJvmTest;
24+
25+
@Isolated
26+
@SeparateJvmTest
27+
@CliNativeTest
28+
@CliProcessTest
29+
public class EclipseWtpJsWithConfigTest extends EclipseWtpTestBase {
30+
31+
@Test
32+
void itUsesConfigurationFile() {
33+
String fileName = runEclipseWtpWithTypeAndConfigFile(
34+
EclipseWtp.Type.JS, "function f( ) {\n" + "a.b(1,\n" + "2);}", "eclipse-wtp-js-profile.xml");
35+
selfie().expectResource(fileName).toMatchDisk();
36+
}
37+
}

app/src/test/java/com/diffplug/spotless/cli/steps/EclipseWtpTestBase.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,19 @@ protected String runEclipseWtpWithTypeInferred(String fileExtension, String unfo
4242

4343
return fileName;
4444
}
45+
46+
protected String runEclipseWtpWithTypeAndConfigFile(EclipseWtp.Type type, String unformatted, String configFile) {
47+
String fileName = "test." + type.name().toLowerCase();
48+
setFile(fileName).toContent(unformatted);
49+
setFile(configFile).toResource("eclipse-wtp/" + configFile);
50+
51+
SpotlessCLIRunner.Result result = cliRunner()
52+
.withTargets(fileName)
53+
.withStep(EclipseWtp.class)
54+
.withOption("--type", type.name())
55+
.withOption("--config-file", configFile)
56+
.run();
57+
58+
return fileName;
59+
}
4560
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.cli.steps;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.parallel.Isolated;
20+
21+
import com.diffplug.spotless.tag.CliNativeTest;
22+
import com.diffplug.spotless.tag.CliProcessTest;
23+
import com.diffplug.spotless.tag.SeparateJvmTest;
24+
25+
@Isolated
26+
@SeparateJvmTest
27+
@CliNativeTest
28+
@CliProcessTest
29+
public class EclipseWtpXhtmlWithConfigTest extends EclipseWtpTestBase {
30+
31+
@Test
32+
void itUsesConfigurationFile() {
33+
String fileName = runEclipseWtpWithTypeAndConfigFile(
34+
EclipseWtp.Type.XHTML,
35+
"<!DOCTYPE html> <html>\t<head> <meta charset=\"UTF-8\"></head>\n" + "</html> ",
36+
"org.eclipse.wst.html.core.prefs");
37+
selfie().expectResource(fileName).toMatchDisk();
38+
}
39+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
╔═ itUsesConfigurationFile ═╗
2+
body {
3+
a: v;
4+
b: v;
5+
}
6+
╔═ [end of file] ═╗
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
╔═ itUsesConfigurationFile ═╗
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta charset="UTF-8">
6+
</head>
7+
</html>
8+
9+
╔═ [end of file] ═╗
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
╔═ itUsesConfigurationFile ═╗
2+
function f() {
3+
a.b(1, 2);
4+
}
5+
╔═ [end of file] ═╗
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
╔═ itUsesConfigurationFile ═╗
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta charset="UTF-8">
6+
</head>
7+
</html>
8+
9+
╔═ [end of file] ═╗

0 commit comments

Comments
 (0)