@@ -68,4 +68,87 @@ class JSON5IntegrationTest {
6868 settings = mapOf (" theme" to " dark" , " lang" to " en" )
6969 )
7070 }
71+
72+ @Serializable
73+ data class BuildConfig (
74+ val modelVersion : String ,
75+ val dependencies : Map <String , String >,
76+ val execution : ExecutionConfig ,
77+ val logging : LoggingConfig ,
78+ val debugging : DebuggingConfig ,
79+ val nodeOptions : NodeOptionsConfig
80+ )
81+
82+ @Serializable
83+ data class ExecutionConfig (
84+ val analyze : String ,
85+ val daemon : Boolean ,
86+ val incremental : Boolean ,
87+ val parallel : Boolean ,
88+ val typeCheck : Boolean
89+ )
90+
91+ @Serializable
92+ data class LoggingConfig (
93+ val level : String
94+ )
95+
96+ @Serializable
97+ data class DebuggingConfig (
98+ val stacktrace : Boolean
99+ )
100+
101+ @Serializable
102+ data class NodeOptionsConfig (
103+ val maxOldSpaceSize : Int ,
104+ val exposeGC : Boolean
105+ )
106+
107+ @Test
108+ fun `should handle complex JSON5 build configuration with mixed comment styles` () {
109+ val buildConfigJson5 = """
110+ {
111+ "modelVersion": "5.0.1", // Version of the hvigor base build capability
112+ "dependencies": {
113+ },
114+ "execution": {
115+ "analyze": "normal", /* Build analysis mode */
116+ "daemon": true, /* Whether to enable daemon process build */
117+ "incremental": true, /* Whether to enable incremental build */
118+ "parallel": true, /* Whether to enable parallel build */
119+ "typeCheck": false, /* Whether to enable type check */
120+ },
121+ "logging": {
122+ "level": "info" /* Log level */
123+ },
124+ "debugging": {
125+ "stacktrace": false /* Whether to enable stack trace */
126+ },
127+ "nodeOptions": {
128+ "maxOldSpaceSize": 4096, /* Memory size of the daemon process when the daemon process is enabled for build, in MB */
129+ "exposeGC": true /* Whether to enable GC */
130+ }
131+ }
132+ """ .trimIndent()
133+
134+ val buildConfig = JSON5 .decodeFromString(BuildConfig .serializer(), buildConfigJson5)
135+
136+ buildConfig shouldBe BuildConfig (
137+ modelVersion = " 5.0.1" ,
138+ dependencies = emptyMap(),
139+ execution = ExecutionConfig (
140+ analyze = " normal" ,
141+ daemon = true ,
142+ incremental = true ,
143+ parallel = true ,
144+ typeCheck = false
145+ ),
146+ logging = LoggingConfig (level = " info" ),
147+ debugging = DebuggingConfig (stacktrace = false ),
148+ nodeOptions = NodeOptionsConfig (
149+ maxOldSpaceSize = 4096 ,
150+ exposeGC = true
151+ )
152+ )
153+ }
71154}
0 commit comments