aboutsummaryrefslogtreecommitdiff
path: root/core/src/test
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2023-02-20 21:45:48 +0100
committerGitHub <noreply@github.com>2023-02-20 21:45:48 +0100
commitfa22175d91fd63b833c537990b79569fa3e2f97d (patch)
tree9d18b5522d34f85286ff787e150c4f533bbfedd3 /core/src/test
parentdbff38bacb25fc3021bbdd67ac25762bc0b0d30f (diff)
downloaddokka-fa22175d91fd63b833c537990b79569fa3e2f97d.tar.gz
dokka-fa22175d91fd63b833c537990b79569fa3e2f97d.tar.bz2
dokka-fa22175d91fd63b833c537990b79569fa3e2f97d.zip
Add the ability to pretty print DokkaConfiguration (#2872)
Diffstat (limited to 'core/src/test')
-rw-r--r--core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt2
-rw-r--r--core/src/test/kotlin/utilities/JsonKtTest.kt57
2 files changed, 58 insertions, 1 deletions
diff --git a/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt b/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt
index ba33ab92..9ac5fea0 100644
--- a/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt
+++ b/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt
@@ -20,7 +20,7 @@ class DokkaConfigurationJsonTest {
)
)
- val jsonString = configuration.toJsonString()
+ val jsonString = configuration.toCompactJsonString()
val parsedConfiguration = DokkaConfigurationImpl(jsonString)
assertEquals(configuration, parsedConfiguration)
}
diff --git a/core/src/test/kotlin/utilities/JsonKtTest.kt b/core/src/test/kotlin/utilities/JsonKtTest.kt
new file mode 100644
index 00000000..ee78392c
--- /dev/null
+++ b/core/src/test/kotlin/utilities/JsonKtTest.kt
@@ -0,0 +1,57 @@
+package utilities
+
+import org.jetbrains.dokka.utilities.serializeAsCompactJson
+import org.jetbrains.dokka.utilities.serializeAsPrettyJson
+import kotlin.test.assertEquals
+import kotlin.test.Test
+
+class JsonTest {
+
+ @Test
+ fun `should serialize an object as compact json`() {
+ val testObject = SimpleTestDataClass(
+ someString = "Foo",
+ someInt = 42,
+ someDouble = 42.0
+ )
+
+ val actual = serializeAsCompactJson(testObject)
+ val expected = "{\"someString\":\"Foo\",\"someInt\":42,\"someIntWithDefaultValue\":42,\"someDouble\":42.0}"
+
+ assertEquals(expected, actual)
+ }
+
+ @Test
+ fun `should serialize an object as pretty json`() {
+ val testObject = SimpleTestDataClass(
+ someString = "Foo",
+ someInt = 42,
+ someDouble = 42.0
+ )
+
+ val actual = serializeAsPrettyJson(testObject)
+
+ val expected = """
+ {
+ "someString" : "Foo",
+ "someInt" : 42,
+ "someIntWithDefaultValue" : 42,
+ "someDouble" : 42.0
+ }""".trimIndent().withSystemLineSeparator()
+
+ assertEquals(expected, actual)
+ }
+
+ /**
+ * If the expected output was generated on Linux, but the tests are run under Windows,
+ * the test might fail when comparing the strings due to different separators.
+ */
+ private fun String.withSystemLineSeparator(): String = this.replace("\n", System.lineSeparator())
+}
+
+data class SimpleTestDataClass(
+ val someString: String,
+ val someInt: Int,
+ val someIntWithDefaultValue: Int = 42,
+ val someDouble: Double
+)