From 5141f46a04322babfa264f7dc3eec8f05eea15c2 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Wed, 16 Jun 2021 09:23:31 +0100 Subject: [PATCH] debugging --- .../gradle/spotless/JsonExtensionTest.java | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java index 8ae9040c37..ddf2f15398 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java @@ -61,4 +61,160 @@ public void formattingWithCustomNumberOfSpaces() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json"); } + + @Test + public void formattingWithCustomNumberOfSpaces___() throws IOException { + setFile("build.gradle").toLines( + "buildscript { repositories { mavenCentral() } }", + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " json {" + + " target '**/*.json'" + + " simple().indentWithSpaces(6)" + + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json"); + } + + @Test + public void formattingWithCustomNumberOfSpaces___format() throws IOException { + setFile("build.gradle").toLines( + "buildscript { repositories { mavenCentral() } }", + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " format 'json', {" + + " target '**/*.json'" + + " simple().indentWithSpaces(6)" + + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json"); + } + + @Test + public void formattingWithCustomNumberOfSpaces___formatWithClass() throws IOException { + setFile("build.gradle").toLines( + "buildscript { repositories { mavenCentral() } }", + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " format 'json', com.diffplug.gradle.spotless.JsonExtension, {" + + " target '**/*.json'" + + " simple().indentWithSpaces(6)" + + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json"); + } + + @Test + public void defaultFormattingWithTargetAfter() throws IOException { + setFile("build.gradle").toLines( + "buildscript { repositories { mavenCentral() } }", + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " json {" + + " simple()" + + " target 'examples/**/*.json'" + + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/nestedObjectBefore.json"); + setFile("examples/main/resources/example.json").toResource("json/nestedObjectBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/nestedObjectBefore.json"); + assertFile("examples/main/resources/example.json").sameAsResource("json/nestedObjectAfter.json"); + } + + @Test + public void formattingWithCustomNumberOfSpacesWithTargetAfter() throws IOException { + setFile("build.gradle").toLines( + "buildscript { repositories { mavenCentral() } }", + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " json {" + + " simple {" + + " indentWithSpaces(6)" + + " }", + " target '**/*.json'" + + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json"); + } + + @Test + public void formattingWithCustomNumberOfSpaces___WithTargetAfter() throws IOException { + setFile("build.gradle").toLines( + "buildscript { repositories { mavenCentral() } }", + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " json {" + + " simple().indentWithSpaces(6)" + + " target '**/*.json'" + + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json"); + } + + @Test + public void formattingWithCustomNumberOfSpaces___formatWithTargetAfter() throws IOException { + setFile("build.gradle").toLines( + "buildscript { repositories { mavenCentral() } }", + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " format 'json', {" + + " simple().indentWithSpaces(6)" + + " target '**/*.json'" + + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json"); + } + + @Test + public void formattingWithCustomNumberOfSpaces___formatWithClassWithTargetAfter() throws IOException { + setFile("build.gradle").toLines( + "buildscript { repositories { mavenCentral() } }", + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " format 'json', com.diffplug.gradle.spotless.JsonExtension, {" + + " simple().indentWithSpaces(6)" + + " target '**/*.json'" + + "}", + "}"); + setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/singletonArrayAfter6Spaces.json"); + } }