Skip to content

Commit 89d133d

Browse files
Copilothossain-khan
andcommitted
Add integration tests demonstrating real-world JSON5 serialization usage
- Test complex data structures with maps, lists, and nested objects - Verify JSON5-specific features work in practice (comments, trailing commas) - Demonstrate end-to-end serialization/deserialization workflow Co-authored-by: hossain-khan <[email protected]>
1 parent 710bd25 commit 89d133d

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package io.github.json5.kotlin
2+
3+
import io.kotest.matchers.shouldBe
4+
import kotlinx.serialization.Serializable
5+
import org.junit.jupiter.api.Test
6+
import org.junit.jupiter.api.DisplayName
7+
8+
/**
9+
* Simple integration test to verify end-to-end functionality
10+
*/
11+
@DisplayName("JSON5 Integration Test")
12+
class JSON5IntegrationTest {
13+
14+
@Serializable
15+
data class Config(
16+
val appName: String,
17+
val version: Int,
18+
val features: List<String>,
19+
val settings: Map<String, String>
20+
)
21+
22+
@Test
23+
fun `should work with real-world example`() {
24+
val config = Config(
25+
appName = "MyApp",
26+
version = 2,
27+
features = listOf("auth", "analytics"),
28+
settings = mapOf("theme" to "dark", "lang" to "en")
29+
)
30+
31+
// Serialize to JSON5
32+
val json5 = JSON5.encodeToString(Config.serializer(), config)
33+
34+
// Verify it's valid JSON5 format
35+
json5 shouldBe "{appName:'MyApp',version:2,features:['auth','analytics'],settings:{theme:'dark',lang:'en'}}"
36+
37+
// Deserialize back
38+
val decoded = JSON5.decodeFromString(Config.serializer(), json5)
39+
40+
// Should be identical
41+
decoded shouldBe config
42+
}
43+
44+
@Test
45+
fun `should handle JSON5 with comments and formatting`() {
46+
val json5WithComments = """
47+
{
48+
// Application configuration
49+
appName: 'MyApp',
50+
version: 2, // current version
51+
features: [
52+
'auth',
53+
'analytics', // trailing comma OK
54+
],
55+
settings: {
56+
theme: 'dark',
57+
lang: 'en',
58+
}
59+
}
60+
""".trimIndent()
61+
62+
val config = JSON5.decodeFromString(Config.serializer(), json5WithComments)
63+
64+
config shouldBe Config(
65+
appName = "MyApp",
66+
version = 2,
67+
features = listOf("auth", "analytics"),
68+
settings = mapOf("theme" to "dark", "lang" to "en")
69+
)
70+
}
71+
}

0 commit comments

Comments
 (0)