@@ -124,11 +124,13 @@ class TestNSFileManger : XCTestCase {
124
124
}
125
125
126
126
if let e = NSFileManager . defaultManager ( ) . enumeratorAtURL ( NSURL ( fileURLWithPath: path) , includingPropertiesForKeys: nil , options: [ ] , errorHandler: nil ) {
127
- XCTAssertEqual ( ( e. nextObject ( ) as? NSURL ) ? . path, itemPath)
128
- XCTAssertEqual ( e. level, 1 )
129
- XCTAssertNil ( e. nextObject ( ) )
130
- XCTAssertEqual ( e. level, 0 )
131
- XCTAssertNil ( e. nextObject ( ) )
127
+ var foundItems = [ String: Int] ( )
128
+ while let item = e. nextObject ( ) as? NSURL {
129
+ if let p = item. path {
130
+ foundItems [ p] = e. level
131
+ }
132
+ }
133
+ XCTAssertEqual ( foundItems [ itemPath] , 1 )
132
134
} else {
133
135
XCTFail ( )
134
136
}
@@ -143,40 +145,41 @@ class TestNSFileManger : XCTestCase {
143
145
}
144
146
145
147
if let e = NSFileManager . defaultManager ( ) . enumeratorAtURL ( NSURL ( fileURLWithPath: path) , includingPropertiesForKeys: nil , options: [ ] , errorHandler: nil ) {
146
- XCTAssertEqual ( ( e . nextObject ( ) as? NSURL ) ? . path , itemPath )
147
- XCTAssertEqual ( e . level , 1 )
148
- XCTAssertEqual ( ( e . nextObject ( ) as? NSURL ) ? . path, subDirPath )
149
- XCTAssertEqual ( e. level, 1 )
150
- XCTAssertEqual ( ( e . nextObject ( ) as? NSURL ) ? . path , subDirItemPath )
151
- XCTAssertEqual ( e . level , 2 )
152
- XCTAssertNil ( e . nextObject ( ) )
153
- XCTAssertEqual ( e . level , 0 )
154
- XCTAssertNil ( e . nextObject ( ) )
148
+ var foundItems = [ String : Int ] ( )
149
+ while let item = e . nextObject ( ) as? NSURL {
150
+ if let p = item . path {
151
+ foundItems [ p ] = e. level
152
+ }
153
+ }
154
+ XCTAssertEqual ( foundItems [ itemPath ] , 1 )
155
+ XCTAssertEqual ( foundItems [ subDirPath ] , 1 )
156
+ XCTAssertEqual ( foundItems [ subDirItemPath ] , 2 )
155
157
} else {
156
158
XCTFail ( )
157
159
}
158
160
159
161
if let e = NSFileManager . defaultManager ( ) . enumeratorAtURL ( NSURL ( fileURLWithPath: path) , includingPropertiesForKeys: nil , options: [ . SkipsSubdirectoryDescendants] , errorHandler: nil ) {
160
- XCTAssertEqual ( ( e. nextObject ( ) as? NSURL ) ? . path, itemPath)
161
- XCTAssertEqual ( e. level, 1 )
162
- XCTAssertEqual ( ( e. nextObject ( ) as? NSURL ) ? . path, subDirPath)
163
- XCTAssertEqual ( e. level, 1 )
164
- XCTAssertNil ( e. nextObject ( ) )
165
- XCTAssertEqual ( e. level, 0 )
166
- XCTAssertNil ( e. nextObject ( ) )
162
+ var foundItems = [ String: Int] ( )
163
+ while let item = e. nextObject ( ) as? NSURL {
164
+ if let p = item. path {
165
+ foundItems [ p] = e. level
166
+ }
167
+ }
168
+ XCTAssertEqual ( foundItems [ itemPath] , 1 )
169
+ XCTAssertEqual ( foundItems [ subDirPath] , 1 )
167
170
} else {
168
171
XCTFail ( )
169
172
}
170
173
171
174
if let e = NSFileManager . defaultManager ( ) . enumeratorAtURL ( NSURL ( fileURLWithPath: path) , includingPropertiesForKeys: nil , options: [ ] , errorHandler: nil ) {
172
- XCTAssertEqual ( ( e . nextObject ( ) as? NSURL ) ? . path , itemPath )
173
- XCTAssertEqual ( e . level , 1 )
174
- XCTAssertEqual ( ( e . nextObject ( ) as? NSURL ) ? . path, subDirPath )
175
- XCTAssertEqual ( e. level, 1 )
176
- e . skipDescendants ( )
177
- XCTAssertNil ( e . nextObject ( ) )
178
- XCTAssertEqual ( e . level , 0 )
179
- XCTAssertNil ( e . nextObject ( ) )
175
+ var foundItems = [ String : Int ] ( )
176
+ while let item = e . nextObject ( ) as? NSURL {
177
+ if let p = item . path {
178
+ foundItems [ p ] = e. level
179
+ }
180
+ }
181
+ XCTAssertEqual ( foundItems [ itemPath ] , 1 )
182
+ XCTAssertEqual ( foundItems [ subDirPath ] , 1 )
180
183
} else {
181
184
XCTFail ( )
182
185
}
@@ -194,10 +197,12 @@ class TestNSFileManger : XCTestCase {
194
197
XCTAssertTrue ( didGetError)
195
198
196
199
do {
197
- let contents = try NSFileManager . defaultManager ( ) . contentsOfDirectoryAtURL ( NSURL ( fileURLWithPath: path) , includingPropertiesForKeys: nil , options: [ ] )
200
+ let contents = try NSFileManager . defaultManager ( ) . contentsOfDirectoryAtURL ( NSURL ( fileURLWithPath: path) , includingPropertiesForKeys: nil , options: [ ] ) . map {
201
+ return $0. path!
202
+ }
198
203
XCTAssertEqual ( contents. count, 2 )
199
- XCTAssertEqual ( contents [ 0 ] . path , itemPath)
200
- XCTAssertEqual ( contents [ 1 ] . path , subDirPath)
204
+ XCTAssertTrue ( contents. contains ( itemPath) )
205
+ XCTAssertTrue ( contents. contains ( subDirPath) )
201
206
} catch {
202
207
XCTFail ( )
203
208
}
0 commit comments