@@ -23,6 +23,9 @@ final class ConfigurationTests: XCTestCase {
2323
2424 let emptyDictionaryData = " {} \n " . data ( using: . utf8) !
2525 let jsonDecoder = JSONDecoder ( )
26+ #if canImport(Darwin) || compiler(>=6)
27+ jsonDecoder. allowsJSON5 = true
28+ #endif
2629 let emptyJSONConfig =
2730 try ! jsonDecoder. decode ( Configuration . self, from: emptyDictionaryData)
2831
@@ -79,7 +82,11 @@ final class ConfigurationTests: XCTestCase {
7982 }
8083 """ . data ( using: . utf8) !
8184
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)
8390 XCTAssertEqual ( config. reflowMultilineStringLiterals, expectedBehavior)
8491 }
8592 }
@@ -99,9 +106,33 @@ final class ConfigurationTests: XCTestCase {
99106 }
100107 """ . data ( using: . utf8) !
101108
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)
103114 XCTAssertEqual ( config. reflowMultilineStringLiterals, expectedBehavior)
104115 }
105116 }
106117
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+ }
107138}
0 commit comments