File tree Expand file tree Collapse file tree 4 files changed +30
-54
lines changed
lib/src/test/kotlin/dev/hossain/json5kt Expand file tree Collapse file tree 4 files changed +30
-54
lines changed Original file line number Diff line number Diff line change @@ -13,24 +13,7 @@ import org.junit.jupiter.api.Test
1313 */
1414@DisplayName(" JSON5.parse errors" )
1515class JSON5ParseErrorsTest {
16- /* *
17- * Helper function to convert JSON5Value back to raw Kotlin objects for testing compatibility.
18- */
19- private fun JSON5Value.toAny (): Any? {
20- return when (this ) {
21- is JSON5Value .Null -> null
22- is JSON5Value .Boolean -> this .value
23- is JSON5Value .String -> this .value
24- is JSON5Value .Number .Integer -> this .value.toDouble() // Convert to Double for consistency with parseToAny
25- is JSON5Value .Number .Decimal -> this .value
26- is JSON5Value .Number .Hexadecimal -> this .value.toDouble() // Convert to Double for consistency
27- is JSON5Value .Number .PositiveInfinity -> Double .POSITIVE_INFINITY
28- is JSON5Value .Number .NegativeInfinity -> Double .NEGATIVE_INFINITY
29- is JSON5Value .Number .NaN -> Double .NaN
30- is JSON5Value .Object -> this .value.mapValues { it.value.toAny() }
31- is JSON5Value .Array -> this .value.map { it.toAny() }
32- }
33- }
16+
3417
3518
3619 /* *
Original file line number Diff line number Diff line change @@ -21,24 +21,7 @@ import kotlin.test.assertTrue
2121@DisplayName(" JSON5.parse" )
2222class JSON5ParseTest {
2323
24- /* *
25- * Helper function to convert JSON5Value back to raw Kotlin objects for testing compatibility.
26- */
27- private fun JSON5Value.toAny (): Any? {
28- return when (this ) {
29- is JSON5Value .Null -> null
30- is JSON5Value .Boolean -> this .value
31- is JSON5Value .String -> this .value
32- is JSON5Value .Number .Integer -> this .value.toDouble() // Convert to Double for consistency with parseToAny
33- is JSON5Value .Number .Decimal -> this .value
34- is JSON5Value .Number .Hexadecimal -> this .value.toDouble() // Convert to Double for consistency
35- is JSON5Value .Number .PositiveInfinity -> Double .POSITIVE_INFINITY
36- is JSON5Value .Number .NegativeInfinity -> Double .NEGATIVE_INFINITY
37- is JSON5Value .Number .NaN -> Double .NaN
38- is JSON5Value .Object -> this .value.mapValues { it.value.toAny() }
39- is JSON5Value .Array -> this .value.map { it.toAny() }
40- }
41- }
24+
4225
4326 /* *
4427 * Tests parsing of an empty JSON5 object.
Original file line number Diff line number Diff line change 1+ package dev.hossain.json5kt
2+
3+ /* *
4+ * Test utilities for JSON5 parsing.
5+ * Contains helper functions for testing compatibility between the new type-safe API
6+ * and the legacy parseToAny behavior.
7+ */
8+
9+ /* *
10+ * Converts a JSON5Value to a raw Any? object for testing compatibility.
11+ * This helper function maintains compatibility with the behavior of the deprecated parseToAny API.
12+ */
13+ fun JSON5Value.toAny (): Any? {
14+ return when (this ) {
15+ is JSON5Value .Null -> null
16+ is JSON5Value .Boolean -> this .value
17+ is JSON5Value .String -> this .value
18+ is JSON5Value .Number .Integer -> this .value.toDouble() // Convert to Double for consistency with parseToAny
19+ is JSON5Value .Number .Decimal -> this .value
20+ is JSON5Value .Number .Hexadecimal -> this .value.toDouble() // Convert to Double for consistency
21+ is JSON5Value .Number .PositiveInfinity -> Double .POSITIVE_INFINITY
22+ is JSON5Value .Number .NegativeInfinity -> Double .NEGATIVE_INFINITY
23+ is JSON5Value .Number .NaN -> Double .NaN
24+ is JSON5Value .Object -> this .value.mapValues { it.value.toAny() }
25+ is JSON5Value .Array -> this .value.map { it.toAny() }
26+ }
27+ }
Original file line number Diff line number Diff line change @@ -12,24 +12,7 @@ import org.junit.jupiter.api.DisplayName
1212 */
1313@DisplayName(" JSON5.parse with JSON5Value" )
1414class JSON5ValueTest {
15- /* *
16- * Helper function to convert JSON5Value back to raw Kotlin objects for testing compatibility.
17- */
18- private fun JSON5Value.toAny (): Any? {
19- return when (this ) {
20- is JSON5Value .Null -> null
21- is JSON5Value .Boolean -> this .value
22- is JSON5Value .String -> this .value
23- is JSON5Value .Number .Integer -> this .value.toDouble() // Convert to Double for consistency with parseToAny
24- is JSON5Value .Number .Decimal -> this .value
25- is JSON5Value .Number .Hexadecimal -> this .value.toDouble() // Convert to Double for consistency
26- is JSON5Value .Number .PositiveInfinity -> Double .POSITIVE_INFINITY
27- is JSON5Value .Number .NegativeInfinity -> Double .NEGATIVE_INFINITY
28- is JSON5Value .Number .NaN -> Double .NaN
29- is JSON5Value .Object -> this .value.mapValues { it.value.toAny() }
30- is JSON5Value .Array -> this .value.map { it.toAny() }
31- }
32- }
15+
3316
3417
3518 @Test
You can’t perform that action at this time.
0 commit comments