Skip to content

Commit a4f8c32

Browse files
Copilothossain-khan
andcommitted
Add real-life JSON5 files and corresponding unit tests
Co-authored-by: hossain-khan <99822+hossain-khan@users.noreply.github.com>
1 parent e818a86 commit a4f8c32

File tree

3 files changed

+1346
-0
lines changed

3 files changed

+1346
-0
lines changed

lib/src/test/kotlin/dev/hossain/json5kt/JSON5ParserTextExampleFiles.kt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,61 @@ class JSON5ParserTextExampleFiles {
203203

204204
assertEquals(expected, result)
205205
}
206+
207+
/**
208+
* Tests parsing of a real-world HarmonyOS IDE hvigor build profile from `harmonyos-ide-hvigor-build-profile-V13.json5`.
209+
* This file represents a complex build configuration with nested objects, arrays,
210+
* and extensive use of JSON5 features like comments and trailing commas.
211+
*/
212+
@Test
213+
fun testParseHarmonyOSBuildProfileJson5() {
214+
val path = Paths.get("src/test/resources/harmonyos-ide-hvigor-build-profile-V13.json5")
215+
val json5Text = Files.readString(path)
216+
val result = JSON5Parser.parse(json5Text)
217+
218+
// Validate basic structure and key properties
219+
val resultMap = result as Map<*, *>
220+
assert(resultMap.containsKey("app")) { "Should contain 'app' key" }
221+
assert(resultMap.containsKey("modules")) { "Should contain 'modules' key" }
222+
223+
val app = resultMap["app"] as Map<*, *>
224+
assert(app.containsKey("signingConfigs")) { "App should contain 'signingConfigs'" }
225+
assert(app.containsKey("products")) { "App should contain 'products'" }
226+
assert(app.containsKey("buildModeSet")) { "App should contain 'buildModeSet'" }
227+
228+
val modules = resultMap["modules"] as List<*>
229+
assert(modules.isNotEmpty()) { "Modules should not be empty" }
230+
val firstModule = modules.first() as Map<*, *>
231+
assertEquals("entry", firstModule["name"]) { "First module name should be 'entry'" }
232+
assertEquals("./entry", firstModule["srcPath"]) { "First module srcPath should be './entry'" }
233+
}
234+
235+
/**
236+
* Tests parsing of a real-world Blink renderer core frame settings from `blink-renderer-core-frame-settings.json5`.
237+
* This file represents a comprehensive configuration with parameters and data arrays,
238+
* demonstrating JSON5's capability to handle large, complex configuration files with comments.
239+
*/
240+
@Test
241+
fun testParseBlinkRendererFrameSettingsJson5() {
242+
val path = Paths.get("src/test/resources/blink-renderer-core-frame-settings.json5")
243+
val json5Text = Files.readString(path)
244+
val result = JSON5Parser.parse(json5Text)
245+
246+
// Validate basic structure and key properties
247+
val resultMap = result as Map<*, *>
248+
assert(resultMap.containsKey("parameters")) { "Should contain 'parameters' key" }
249+
assert(resultMap.containsKey("data")) { "Should contain 'data' key" }
250+
251+
val parameters = resultMap["parameters"] as Map<*, *>
252+
assert(parameters.containsKey("type")) { "Parameters should contain 'type'" }
253+
assert(parameters.containsKey("include_paths")) { "Parameters should contain 'include_paths'" }
254+
assert(parameters.containsKey("initial")) { "Parameters should contain 'initial'" }
255+
assert(parameters.containsKey("invalidate")) { "Parameters should contain 'invalidate'" }
256+
257+
val data = resultMap["data"] as List<*>
258+
assert(data.isNotEmpty()) { "Data should not be empty" }
259+
val firstDataItem = data.first() as Map<*, *>
260+
assertEquals("defaultTextEncodingName", firstDataItem["name"]) { "First data item name should be 'defaultTextEncodingName'" }
261+
assertEquals("String", firstDataItem["type"]) { "First data item type should be 'String'" }
262+
}
206263
}

0 commit comments

Comments
 (0)