@@ -34,19 +34,21 @@ class SwiftcFilemapInputEditorTests: FileXCTestCase {
3434 )
3535 private let sampleInfoContentData = #"{"":{"swift-dependencies":"/"}}"# . data ( using: . utf8) !
3636 private var inputFile : URL !
37- private var editor : SwiftcFilemapInputEditor !
37+ private var editorJson : SwiftcFilemapInputEditor !
38+ private var editorYaml : SwiftcFilemapInputEditor !
3839
3940 override func setUpWithError( ) throws {
4041 try super. setUpWithError ( )
4142 try prepareTempDir ( )
4243 inputFile = workingDirectory!. appendingPathComponent ( " swift.json " )
43- editor = SwiftcFilemapInputEditor ( inputFile, fileManager: fileManager)
44+ editorJson = SwiftcFilemapInputEditor ( inputFile, fileFormat: . json, fileManager: fileManager)
45+ editorYaml = SwiftcFilemapInputEditor ( inputFile, fileFormat: . yaml, fileManager: fileManager)
4446 }
4547
4648 func testReading( ) throws {
4749 try fileManager. spt_writeToFile ( atPath: inputFile. path, contents: sampleInfoContentData)
4850
49- let readInfo = try editor . read ( )
51+ let readInfo = try editorJson . read ( )
5052
5153 XCTAssertEqual ( readInfo, sampleInfo)
5254 }
@@ -80,13 +82,13 @@ class SwiftcFilemapInputEditorTests: FileXCTestCase {
8082 ] )
8183 try fileManager. spt_writeToFile ( atPath: inputFile. path, contents: infoContentData)
8284
83- let readInfo = try editor . read ( )
85+ let readInfo = try editorJson . read ( )
8486
8587 XCTAssertEqual ( readInfo, expectedInfo)
8688 }
8789
8890 func testWritingSavesContent( ) throws {
89- try editor . write ( sampleInfo)
91+ try editorJson . write ( sampleInfo)
9092
9193 let savedContent = try Data ( contentsOf: inputFile)
9294 let content = try JSONSerialization . jsonObject ( with: savedContent, options: [ ] ) as? [ String : Any ]
@@ -108,7 +110,7 @@ class SwiftcFilemapInputEditorTests: FileXCTestCase {
108110 ) ,
109111 ] )
110112
111- try editor . write ( extendedInfo)
113+ try editorJson . write ( extendedInfo)
112114
113115 let savedContent = try Data ( contentsOf: inputFile)
114116 let content = try JSONSerialization . jsonObject ( with: savedContent, options: [ ] ) as? [ String : Any ]
@@ -119,12 +121,48 @@ class SwiftcFilemapInputEditorTests: FileXCTestCase {
119121 func testModifyingFileCompilationInfo( ) throws {
120122 try fileManager. spt_writeToFile ( atPath: inputFile. path, contents: sampleInfoContentData)
121123
122- let originalInfo = try editor . read ( )
124+ let originalInfo = try editorJson . read ( )
123125 var modifiedInfo = originalInfo
124126 modifiedInfo. files = [ file]
125- try editor . write ( modifiedInfo)
126- let finalInfo = try editor . read ( )
127+ try editorJson . write ( modifiedInfo)
128+ let finalInfo = try editorJson . read ( )
127129
128130 XCTAssertEqual ( finalInfo, modifiedInfo)
129131 }
132+
133+ func testReadingSupplementaryInfoWithOptionalProperties( ) throws {
134+ let infoContentData = #"""
135+ "/file1.swift":
136+ swift-dependencies: "/file1.swiftdeps"
137+ dependencies: "/file1.d"
138+ "/file2.swift":
139+ dependencies: "/file2.d"
140+ object: "/file2.o"
141+ swift-dependencies: "/file2.swiftdeps"
142+ """# . data ( using: . utf8) !
143+ let expectedInfo = SwiftCompilationInfo (
144+ info: SwiftModuleCompilationInfo (
145+ dependencies: nil ,
146+ swiftDependencies: nil
147+ ) ,
148+ files: [
149+ SwiftFileCompilationInfo (
150+ file: " /file1.swift " ,
151+ dependencies: " /file1.d " ,
152+ object: nil ,
153+ swiftDependencies: " /file1.swiftdeps "
154+ ) ,
155+ SwiftFileCompilationInfo (
156+ file: " /file2.swift " ,
157+ dependencies: " /file2.d " ,
158+ object: " /file2.o " ,
159+ swiftDependencies: " /file2.swiftdeps "
160+ ) ,
161+ ] )
162+ try fileManager. spt_writeToFile ( atPath: inputFile. path, contents: infoContentData)
163+
164+ let readInfo = try editorYaml. read ( )
165+
166+ XCTAssertEqual ( readInfo, expectedInfo)
167+ }
130168}
0 commit comments