generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
2 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
82 changes: 82 additions & 0 deletions
82
src/test/kotlin/io/github/orangain/prettyjsonlog/console/FoldingTest.kt
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,82 @@ | ||
package io.github.orangain.prettyjsonlog.console | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.fasterxml.jackson.databind.node.ObjectNode | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import junit.framework.TestCase | ||
|
||
class FoldingTest : TestCase() { | ||
private data class Param( | ||
val description: String, | ||
val jsonCreator: (ObjectNode) -> Unit | ||
) | ||
|
||
private val mapper = jacksonObjectMapper() | ||
|
||
private val params = listOf( | ||
Param("Empty object") { }, | ||
Param("Simple object") { | ||
it.put("string", "x") | ||
it.put("number", 1) | ||
it.put("true", true) | ||
it.put("false", false) | ||
it.putNull("null") | ||
}, | ||
Param("Nested object") { | ||
it.putObject("nested").apply { | ||
put("string", "x") | ||
put("number", 1) | ||
put("true", true) | ||
put("false", false) | ||
putNull("null") | ||
} | ||
}, | ||
Param("Array") { | ||
it.putArray("array").apply { | ||
add("x") | ||
add(1) | ||
add(true) | ||
add(false) | ||
addNull() | ||
addObject().apply { | ||
put("foo", "bar") | ||
} | ||
} | ||
}, | ||
Param("Nested array") { | ||
it.putObject("nested").apply { | ||
putArray("array").apply { | ||
add("x") | ||
add(1) | ||
add(true) | ||
add(false) | ||
addNull() | ||
} | ||
} | ||
}, | ||
Param("Array with many elements") { | ||
it.putArray("array").apply { | ||
for (i in 1..100) { | ||
add(i) | ||
} | ||
} | ||
}, | ||
) | ||
|
||
fun testFolding() { | ||
params.forEach { param -> | ||
val node = mapper.createObjectNode().apply(param.jsonCreator) | ||
assertAllLinesFolded(param.description, node) | ||
} | ||
} | ||
|
||
private fun assertAllLinesFolded(description: String, node: JsonNode) { | ||
val json = prettyPrintJson(node) | ||
println(json) | ||
val lines = json.lines() | ||
assertTrue("[$description] Lines should not be empty", lines.isNotEmpty()) | ||
lines.forEachIndexed { index, line -> | ||
assertTrue("[$description] Line $index should be folded", isPartOfPrettyJson(line)) | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/kotlin/io/github/orangain/prettyjsonlog/console/NotFoldingTest.kt
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,42 @@ | ||
package io.github.orangain.prettyjsonlog.console | ||
|
||
import junit.framework.TestCase | ||
|
||
|
||
class NotFoldingTest : TestCase() { | ||
private data class Param( | ||
val description: String, | ||
val text: String | ||
) | ||
|
||
private val params = listOf( | ||
Param("Log message", "[12:34:56.789] INFO: This is a log message"), | ||
Param("Empty line", ""), | ||
Param( | ||
"Multiline SQL", """ | ||
SELECT | ||
id, | ||
name | ||
FROM | ||
table | ||
WHERE | ||
id = 1 | ||
""".trimIndent() | ||
), | ||
Param("Starts with space and double quote", """ "foo" """), | ||
) | ||
|
||
fun testNotFolding() { | ||
params.forEach { param -> | ||
assertAllLinesNotFolded(param.description, param.text) | ||
} | ||
} | ||
|
||
private fun assertAllLinesNotFolded(description: String, text: String) { | ||
val lines = text.lines() | ||
assertTrue("[$description] Lines should not be empty", lines.isNotEmpty()) | ||
lines.forEachIndexed { index, line -> | ||
assertFalse("[$description] Line $index should not be folded", isPartOfPrettyJson(line)) | ||
} | ||
} | ||
} |