Skip to content

Commit f528018

Browse files
committed
[ADDED] Test for loading chromium config
1 parent 37133f6 commit f528018

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.github.json5.kotlin
2+
3+
import org.junit.jupiter.api.Assertions.assertEquals
4+
import org.junit.jupiter.api.Test
5+
import java.nio.file.Files
6+
import java.nio.file.Paths
7+
8+
class JSON5ParserTestLargeFile {
9+
@Test
10+
fun testParseSimpleChromiumConfig() {
11+
val path = Paths.get("src/test/resources/runtime_enabled_features.json5")
12+
val json5Text = Files.readString(path)
13+
val result = JSON5Parser.parse(json5Text)
14+
15+
// Basic structural assertions
16+
assert(result is Map<*, *>) { "Parsed result should be a Map" }
17+
val rootMap = result as Map<String, Any?>
18+
19+
assert(rootMap.containsKey("parameters")) { "Root map should contain 'parameters' key" }
20+
assert(rootMap.containsKey("data")) { "Root map should contain 'data' key" }
21+
22+
val parameters = rootMap["parameters"]
23+
assert(parameters is Map<*, *>) { "'parameters' should be a Map" }
24+
val parametersMap = parameters as Map<String, Any?>
25+
26+
val data = rootMap["data"]
27+
assert(data is List<*>) { "'data' should be a List" }
28+
val dataList = data as List<Any?>
29+
30+
// Validate 'parameters' content (example: status parameter)
31+
assert(parametersMap.containsKey("status")) { "Parameters should contain 'status'" }
32+
val statusParam = parametersMap["status"]
33+
assert(statusParam is Map<*, *>) { "'status' parameter should be a Map" }
34+
val statusParamMap = statusParam as Map<String, Any?>
35+
assert(statusParamMap.containsKey("valid_values")) { "'status' parameter should have 'valid_values'" }
36+
val validStatusValues = statusParamMap["valid_values"]
37+
assert(validStatusValues is List<*>) { "'valid_values' for status should be a List" }
38+
val validStatusList = validStatusValues as List<String>
39+
assert(validStatusList.contains("stable")) { "'valid_values' for status should include 'stable'" }
40+
assert(validStatusList.contains("experimental")) { "'valid_values' for status should include 'experimental'" }
41+
assert(validStatusList.contains("test")) { "'valid_values' for status should include 'test'" }
42+
43+
// Validate 'data' content (example: first feature)
44+
assert(dataList.isNotEmpty()) { "Data list should not be empty" }
45+
val firstFeature = dataList.first()
46+
assert(firstFeature is Map<*, *>) { "First feature in data list should be a Map" }
47+
val firstFeatureMap = firstFeature as Map<String, Any?>
48+
49+
assertEquals("Accelerated2dCanvas", firstFeatureMap["name"]) {"First feature name mismatch"}
50+
assertEquals(true, firstFeatureMap["settable_from_internals"]) {"First feature settable_from_internals mismatch"}
51+
assertEquals("stable", firstFeatureMap["status"]) {"First feature status mismatch"}
52+
53+
// Example: Find a specific feature and validate its properties
54+
val adInterestGroupAPI = dataList.find { it is Map<*, *> && (it as Map<String, Any?>)["name"] == "AdInterestGroupAPI" }
55+
assert(adInterestGroupAPI != null) { "Feature 'AdInterestGroupAPI' should exist" }
56+
val adInterestGroupAPIMap = adInterestGroupAPI as Map<String, Any?>
57+
assertEquals("stable", adInterestGroupAPIMap["status"]) { "'AdInterestGroupAPI' status mismatch" }
58+
assertEquals(true, adInterestGroupAPIMap["public"]) { "'AdInterestGroupAPI' public flag mismatch" }
59+
val impliedByFledge = (adInterestGroupAPIMap["implied_by"] as? List<*>)?.contains("Fledge")
60+
assertEquals(true, impliedByFledge) { "'AdInterestGroupAPI' should be implied_by 'Fledge'" }
61+
62+
// Example: Check a feature with a map as status
63+
val aiPromptAPI = dataList.find { it is Map<*, *> && (it as Map<String, Any?>)["name"] == "AIPromptAPI" }
64+
assert(aiPromptAPI != null) { "Feature 'AIPromptAPI' should exist" }
65+
val aiPromptAPIMap = aiPromptAPI as Map<String, Any?>
66+
val aiPromptAPIStatus = aiPromptAPIMap["status"]
67+
assert(aiPromptAPIStatus is Map<*, *>) { "'AIPromptAPI' status should be a Map" }
68+
val aiPromptAPIStatusMap = aiPromptAPIStatus as Map<String, Any?>
69+
assertEquals("experimental", aiPromptAPIStatusMap["Win"]) { "'AIPromptAPI' status for Win mismatch" }
70+
assertEquals("experimental", aiPromptAPIStatusMap["Mac"]) { "'AIPromptAPI' status for Mac mismatch" }
71+
}
72+
73+
}

0 commit comments

Comments
 (0)