Skip to content

Commit 44f3765

Browse files
committed
Fixed an issue in wrappers(in:) Added simple test cases
1 parent 7b010d2 commit 44f3765

File tree

4 files changed

+242
-1
lines changed

4 files changed

+242
-1
lines changed

LSFileWrapper.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ - (LSFileWrapper *)fileWrapperWithPath:(NSString *)path
227227
- (NSArray<LSFileWrapper*> *)fileWrappersInPath:(NSString *)path
228228
{
229229
NSMutableArray<LSFileWrapper*> *array = [[NSMutableArray alloc] init];
230-
LSFileWrapper *dirFileWrapper = [self fileWrapperWithPath:path];
230+
LSFileWrapper *dirFileWrapper = ([path isEqual: @"/"] || [path isEqual: @""]) ? self : [self fileWrapperWithPath:path];
231231
if (dirFileWrapper) {
232232
[dirFileWrapper.fileWrappers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, LSFileWrapper * _Nonnull obj, BOOL * _Nonnull stop) {
233233
[array addObject:obj];

LSFileWrapper.xcodeproj/project.pbxproj

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,20 @@
1313
3B1C07DA22D8951F00244E2D /* LSDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B1C07C722D892C900244E2D /* LSDocument.h */; settings = {ATTRIBUTES = (Public, ); }; };
1414
3B1C07DB22D8955700244E2D /* LSFileWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 3B1C07C622D892C900244E2D /* LSFileWrapper.m */; };
1515
3B1C07DC22D8955900244E2D /* LSFileWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 3B1C07D222D893A900244E2D /* LSFileWrapper.h */; settings = {ATTRIBUTES = (Public, ); }; };
16+
3B599D4325D697FB00675DE0 /* LSFileWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B599D4225D697FB00675DE0 /* LSFileWrapperTests.swift */; };
17+
3B599D4525D697FB00675DE0 /* LSFileWrapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B1C07BA22D8922900244E2D /* LSFileWrapper.framework */; };
1618
/* End PBXBuildFile section */
1719

20+
/* Begin PBXContainerItemProxy section */
21+
3B599D4625D697FB00675DE0 /* PBXContainerItemProxy */ = {
22+
isa = PBXContainerItemProxy;
23+
containerPortal = 3B1C07B122D8922900244E2D /* Project object */;
24+
proxyType = 1;
25+
remoteGlobalIDString = 3B1C07B922D8922900244E2D;
26+
remoteInfo = "LSFileWrapper (macOS)";
27+
};
28+
/* End PBXContainerItemProxy section */
29+
1830
/* Begin PBXFileReference section */
1931
3B1C07BA22D8922900244E2D /* LSFileWrapper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LSFileWrapper.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2032
3B1C07BE22D8922900244E2D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -24,6 +36,9 @@
2436
3B1C07D022D893A900244E2D /* LSFileWrapper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LSFileWrapper.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2537
3B1C07D222D893A900244E2D /* LSFileWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LSFileWrapper.h; sourceTree = "<group>"; };
2638
3B1C07D322D893A900244E2D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
39+
3B599D4025D697FB00675DE0 /* LSFileWrapperTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LSFileWrapperTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
40+
3B599D4225D697FB00675DE0 /* LSFileWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LSFileWrapperTests.swift; sourceTree = "<group>"; };
41+
3B599D4425D697FB00675DE0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2742
3B6C6ABD2353C47D00E989C2 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
2843
3B73C1E325BDE2BB000E4B4E /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
2944
3B73C1E425BDE2BB000E4B4E /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
@@ -44,6 +59,14 @@
4459
);
4560
runOnlyForDeploymentPostprocessing = 0;
4661
};
62+
3B599D3D25D697FB00675DE0 /* Frameworks */ = {
63+
isa = PBXFrameworksBuildPhase;
64+
buildActionMask = 2147483647;
65+
files = (
66+
3B599D4525D697FB00675DE0 /* LSFileWrapper.framework in Frameworks */,
67+
);
68+
runOnlyForDeploymentPostprocessing = 0;
69+
};
4770
/* End PBXFrameworksBuildPhase section */
4871

4972
/* Begin PBXGroup section */
@@ -54,6 +77,7 @@
5477
3B73C1E325BDE2BB000E4B4E /* README.md */,
5578
3B73C1E425BDE2BB000E4B4E /* LICENSE */,
5679
3B1C07D822D894BC00244E2D /* LSFileWrapper */,
80+
3B599D4125D697FB00675DE0 /* LSFileWrapperTests */,
5781
3B1C07BB22D8922900244E2D /* Products */,
5882
);
5983
sourceTree = "<group>";
@@ -63,6 +87,7 @@
6387
children = (
6488
3B1C07BA22D8922900244E2D /* LSFileWrapper.framework */,
6589
3B1C07D022D893A900244E2D /* LSFileWrapper.framework */,
90+
3B599D4025D697FB00675DE0 /* LSFileWrapperTests.xctest */,
6691
);
6792
name = Products;
6893
sourceTree = "<group>";
@@ -96,6 +121,15 @@
96121
name = LSFileWrapper;
97122
sourceTree = "<group>";
98123
};
124+
3B599D4125D697FB00675DE0 /* LSFileWrapperTests */ = {
125+
isa = PBXGroup;
126+
children = (
127+
3B599D4225D697FB00675DE0 /* LSFileWrapperTests.swift */,
128+
3B599D4425D697FB00675DE0 /* Info.plist */,
129+
);
130+
path = LSFileWrapperTests;
131+
sourceTree = "<group>";
132+
};
99133
/* End PBXGroup section */
100134

101135
/* Begin PBXHeadersBuildPhase section */
@@ -155,12 +189,31 @@
155189
productReference = 3B1C07D022D893A900244E2D /* LSFileWrapper.framework */;
156190
productType = "com.apple.product-type.framework";
157191
};
192+
3B599D3F25D697FB00675DE0 /* LSFileWrapperTests */ = {
193+
isa = PBXNativeTarget;
194+
buildConfigurationList = 3B599D4825D697FB00675DE0 /* Build configuration list for PBXNativeTarget "LSFileWrapperTests" */;
195+
buildPhases = (
196+
3B599D3C25D697FB00675DE0 /* Sources */,
197+
3B599D3D25D697FB00675DE0 /* Frameworks */,
198+
3B599D3E25D697FB00675DE0 /* Resources */,
199+
);
200+
buildRules = (
201+
);
202+
dependencies = (
203+
3B599D4725D697FB00675DE0 /* PBXTargetDependency */,
204+
);
205+
name = LSFileWrapperTests;
206+
productName = LSFileWrapperTests;
207+
productReference = 3B599D4025D697FB00675DE0 /* LSFileWrapperTests.xctest */;
208+
productType = "com.apple.product-type.bundle.unit-test";
209+
};
158210
/* End PBXNativeTarget section */
159211

160212
/* Begin PBXProject section */
161213
3B1C07B122D8922900244E2D /* Project object */ = {
162214
isa = PBXProject;
163215
attributes = {
216+
LastSwiftUpdateCheck = 1240;
164217
LastUpgradeCheck = 1230;
165218
ORGANIZATIONNAME = "Adam Kopeć";
166219
TargetAttributes = {
@@ -170,6 +223,9 @@
170223
3B1C07CF22D893A900244E2D = {
171224
CreatedOnToolsVersion = 11.0;
172225
};
226+
3B599D3F25D697FB00675DE0 = {
227+
CreatedOnToolsVersion = 12.4;
228+
};
173229
};
174230
};
175231
buildConfigurationList = 3B1C07B422D8922900244E2D /* Build configuration list for PBXProject "LSFileWrapper" */;
@@ -187,6 +243,7 @@
187243
targets = (
188244
3B1C07B922D8922900244E2D /* LSFileWrapper (macOS) */,
189245
3B1C07CF22D893A900244E2D /* LSFileWrapper (iOS) */,
246+
3B599D3F25D697FB00675DE0 /* LSFileWrapperTests */,
190247
);
191248
};
192249
/* End PBXProject section */
@@ -206,6 +263,13 @@
206263
);
207264
runOnlyForDeploymentPostprocessing = 0;
208265
};
266+
3B599D3E25D697FB00675DE0 /* Resources */ = {
267+
isa = PBXResourcesBuildPhase;
268+
buildActionMask = 2147483647;
269+
files = (
270+
);
271+
runOnlyForDeploymentPostprocessing = 0;
272+
};
209273
/* End PBXResourcesBuildPhase section */
210274

211275
/* Begin PBXSourcesBuildPhase section */
@@ -226,8 +290,24 @@
226290
);
227291
runOnlyForDeploymentPostprocessing = 0;
228292
};
293+
3B599D3C25D697FB00675DE0 /* Sources */ = {
294+
isa = PBXSourcesBuildPhase;
295+
buildActionMask = 2147483647;
296+
files = (
297+
3B599D4325D697FB00675DE0 /* LSFileWrapperTests.swift in Sources */,
298+
);
299+
runOnlyForDeploymentPostprocessing = 0;
300+
};
229301
/* End PBXSourcesBuildPhase section */
230302

303+
/* Begin PBXTargetDependency section */
304+
3B599D4725D697FB00675DE0 /* PBXTargetDependency */ = {
305+
isa = PBXTargetDependency;
306+
target = 3B1C07B922D8922900244E2D /* LSFileWrapper (macOS) */;
307+
targetProxy = 3B599D4625D697FB00675DE0 /* PBXContainerItemProxy */;
308+
};
309+
/* End PBXTargetDependency section */
310+
231311
/* Begin XCBuildConfiguration section */
232312
3B1C07C022D8922900244E2D /* Debug */ = {
233313
isa = XCBuildConfiguration;
@@ -431,6 +511,39 @@
431511
};
432512
name = Release;
433513
};
514+
3B599D4925D697FB00675DE0 /* Debug */ = {
515+
isa = XCBuildConfiguration;
516+
buildSettings = {
517+
CODE_SIGN_STYLE = Automatic;
518+
COMBINE_HIDPI_IMAGES = YES;
519+
DEVELOPMENT_TEAM = S73MBXSV7H;
520+
INFOPLIST_FILE = LSFileWrapperTests/Info.plist;
521+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
522+
MACOSX_DEPLOYMENT_TARGET = 11.1;
523+
PRODUCT_BUNDLE_IDENTIFIER = com.adamkopec.LSFileWrapperTests;
524+
PRODUCT_NAME = "$(TARGET_NAME)";
525+
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
526+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
527+
SWIFT_VERSION = 5.0;
528+
};
529+
name = Debug;
530+
};
531+
3B599D4A25D697FB00675DE0 /* Release */ = {
532+
isa = XCBuildConfiguration;
533+
buildSettings = {
534+
CODE_SIGN_STYLE = Automatic;
535+
COMBINE_HIDPI_IMAGES = YES;
536+
DEVELOPMENT_TEAM = S73MBXSV7H;
537+
INFOPLIST_FILE = LSFileWrapperTests/Info.plist;
538+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
539+
MACOSX_DEPLOYMENT_TARGET = 11.1;
540+
PRODUCT_BUNDLE_IDENTIFIER = com.adamkopec.LSFileWrapperTests;
541+
PRODUCT_NAME = "$(TARGET_NAME)";
542+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
543+
SWIFT_VERSION = 5.0;
544+
};
545+
name = Release;
546+
};
434547
/* End XCBuildConfiguration section */
435548

436549
/* Begin XCConfigurationList section */
@@ -461,6 +574,15 @@
461574
defaultConfigurationIsVisible = 0;
462575
defaultConfigurationName = Release;
463576
};
577+
3B599D4825D697FB00675DE0 /* Build configuration list for PBXNativeTarget "LSFileWrapperTests" */ = {
578+
isa = XCConfigurationList;
579+
buildConfigurations = (
580+
3B599D4925D697FB00675DE0 /* Debug */,
581+
3B599D4A25D697FB00675DE0 /* Release */,
582+
);
583+
defaultConfigurationIsVisible = 0;
584+
defaultConfigurationName = Release;
585+
};
464586
/* End XCConfigurationList section */
465587
};
466588
rootObject = 3B1C07B122D8922900244E2D /* Project object */;

LSFileWrapperTests/Info.plist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
</dict>
22+
</plist>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//
2+
// LSFileWrapperTests.swift
3+
// LSFileWrapperTests
4+
//
5+
// Created by Adam Kopeć on 12/02/2021.
6+
// Copyright © 2021 Adam Kopeć. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import LSFileWrapper
11+
12+
class LSFileWrapperTests: XCTestCase {
13+
14+
override func setUpWithError() throws {
15+
// Put setup code here. This method is called before the invocation of each test method in the class.
16+
}
17+
18+
override func tearDownWithError() throws {
19+
// Put teardown code here. This method is called after the invocation of each test method in the class.
20+
}
21+
22+
func testUpdateContent() {
23+
// This is a test case for testing update(newContent:) method
24+
let fileWrapper = LSFileWrapper(file: ())
25+
fileWrapper.update(newContent: "Hello World!" as NSString)
26+
27+
XCTAssertNotNil(fileWrapper.string())
28+
XCTAssertEqual(fileWrapper.string(), "Hello World!")
29+
}
30+
31+
func testAddContent() {
32+
// This is a test case for testing add(content: withFilename:) method
33+
let wrapper = LSFileWrapper(directory: ())
34+
wrapper.add(content: "Hello World!" as NSString, withFilename: "hello.txt")
35+
36+
let fileWrapper = wrapper.wrapper(with: "hello.txt")
37+
38+
XCTAssertNotNil(fileWrapper)
39+
XCTAssertNotNil(fileWrapper?.string())
40+
41+
XCTAssertEqual(fileWrapper?.string(), "Hello World!")
42+
}
43+
44+
func testRemoveContent() {
45+
// This is a test case for testing add(content: withFilename:) method
46+
let wrapper = LSFileWrapper(directory: ())
47+
wrapper.add(content: "Hello World!" as NSString, withFilename: "hello.txt")
48+
wrapper.removeWrapper(with: "hello.txt")
49+
50+
let fileWrapper = wrapper.wrapper(with: "hello.txt")
51+
52+
XCTAssertNil(fileWrapper)
53+
}
54+
55+
func testMultipleWrappers() {
56+
// This is a test case for testing add(content: withFilename:) method
57+
let wrapper = LSFileWrapper(directory: ())
58+
wrapper.add(content: "Hello World!" as NSString, withFilename: "hello.txt")
59+
wrapper.add(wrapper: LSFileWrapper(directory: ()), withFilename: "directory")
60+
61+
let fileWrapper = wrapper.wrapper(with: "hello.txt")
62+
let dirWrapper = wrapper.wrapper(with: "directory")
63+
64+
XCTAssertNotNil(fileWrapper)
65+
XCTAssertNotNil(dirWrapper)
66+
67+
XCTAssertEqual(fileWrapper?.string(), "Hello World!")
68+
XCTAssertEqual(fileWrapper?.isDirectory, false)
69+
XCTAssertEqual(dirWrapper?.isDirectory, true)
70+
}
71+
72+
func testWrapperEnumerator() {
73+
// This is a test case for testing wrappers(in:) method using "/" path
74+
let wrapper = LSFileWrapper(directory: ())
75+
wrapper.add(content: "Hello World!" as NSString, withFilename: "hello.txt")
76+
wrapper.add(wrapper: LSFileWrapper(directory: ()), withFilename: "directory")
77+
78+
let wrappers = wrapper.wrappers(in: "/")
79+
80+
let wrapperNames = wrappers.map({ $0.filename })
81+
82+
XCTAssertEqual(wrapperNames.sorted(by: { $1 ?? "" < $0 ?? "" }), ["hello.txt", "directory"])
83+
}
84+
85+
func testWrapperEnumeratorAlternatePath() {
86+
// This is a test case for testing wrappers(in:) method using "" path
87+
let wrapper = LSFileWrapper(directory: ())
88+
wrapper.add(content: "Hello World!" as NSString, withFilename: "hello.txt")
89+
wrapper.add(wrapper: LSFileWrapper(directory: ()), withFilename: "directory")
90+
91+
let wrappers = wrapper.wrappers(in: "")
92+
93+
let wrapperNames = wrappers.map({ $0.filename })
94+
95+
XCTAssertEqual(wrapperNames.sorted(by: { $1 ?? "" < $0 ?? "" }), ["hello.txt", "directory"])
96+
}
97+
}

0 commit comments

Comments
 (0)