@@ -23,6 +23,9 @@ final class ConfigurationTests: XCTestCase {
23
23
24
24
let emptyDictionaryData = " {} \n " . data ( using: . utf8) !
25
25
let jsonDecoder = JSONDecoder ( )
26
+ #if canImport(Darwin) || compiler(>=6)
27
+ jsonDecoder. allowsJSON5 = true
28
+ #endif
26
29
let emptyJSONConfig =
27
30
try ! jsonDecoder. decode ( Configuration . self, from: emptyDictionaryData)
28
31
@@ -79,7 +82,11 @@ final class ConfigurationTests: XCTestCase {
79
82
}
80
83
""" . data ( using: . utf8) !
81
84
82
- let config = try JSONDecoder ( ) . decode ( Configuration . self, from: jsonData)
85
+ let jsonDecoder = JSONDecoder ( )
86
+ #if canImport(Darwin) || compiler(>=6)
87
+ jsonDecoder. allowsJSON5 = true
88
+ #endif
89
+ let config = try jsonDecoder. decode ( Configuration . self, from: jsonData)
83
90
XCTAssertEqual ( config. reflowMultilineStringLiterals, expectedBehavior)
84
91
}
85
92
}
@@ -99,9 +106,33 @@ final class ConfigurationTests: XCTestCase {
99
106
}
100
107
""" . data ( using: . utf8) !
101
108
102
- let config = try JSONDecoder ( ) . decode ( Configuration . self, from: jsonData)
109
+ let jsonDecoder = JSONDecoder ( )
110
+ #if canImport(Darwin) || compiler(>=6)
111
+ jsonDecoder. allowsJSON5 = true
112
+ #endif
113
+ let config = try jsonDecoder. decode ( Configuration . self, from: jsonData)
103
114
XCTAssertEqual ( config. reflowMultilineStringLiterals, expectedBehavior)
104
115
}
105
116
}
106
117
118
+ func testConfigurationWithComments( ) throws {
119
+ #if !canImport(Darwin) && compiler(<6)
120
+ try XCTSkipIf ( true , " JSONDecoder does not support JSON5 " )
121
+ #else
122
+ let expected = Configuration ( )
123
+
124
+ let jsonData = """
125
+ {
126
+ // Indicates the configuration schema version.
127
+ " version " : 1,
128
+ }
129
+ """ . data ( using: . utf8) !
130
+
131
+ let jsonDecoder = JSONDecoder ( )
132
+
133
+ jsonDecoder. allowsJSON5 = true
134
+ let config = try jsonDecoder. decode ( Configuration . self, from: jsonData)
135
+ XCTAssertEqual ( config, expected)
136
+ #endif
137
+ }
107
138
}
0 commit comments