@@ -29,7 +29,7 @@ class LSFileWrapperTests: XCTestCase {
2929 }
3030
3131 func testUpdateDataContent( ) {
32- // This is a test case for testing update(newContent:) method
32+ // This is a test case for testing update(newContent:) method using raw Data
3333 let fileWrapper = LSFileWrapper ( file: ( ) )
3434 fileWrapper. update ( newContent: Data ( " Hello World! " . utf8) as NSData )
3535
@@ -40,7 +40,7 @@ class LSFileWrapperTests: XCTestCase {
4040 }
4141
4242 func testUpdateDictionaryContent( ) {
43- // This is a test case for testing update(newContent:) method
43+ // This is a test case for testing update(newContent:) method using simple Dictionary
4444 let testDict = [ " Name " : " LSFileWrapper " , " Platforms " : " macOS, iOS " , " Version " : " 2 " ]
4545 let fileWrapper = LSFileWrapper ( file: ( ) )
4646 fileWrapper. update ( newContent: testDict as NSDictionary )
@@ -50,7 +50,7 @@ class LSFileWrapperTests: XCTestCase {
5050 }
5151
5252 func testUpdateAnyDictionaryContent( ) {
53- // This is a test case for testing update(newContent:) method
53+ // This is a test case for testing update(newContent:) method using an advanced Dictionary
5454 let testDict = [ " Name " : " LSFileWrapper " , " Platforms " : [ " macOS " , " iOS " ] , " Version " : 2 ] as [ String : Any ]
5555 let fileWrapper = LSFileWrapper ( file: ( ) )
5656 fileWrapper. update ( newContent: testDict as NSDictionary )
@@ -64,7 +64,7 @@ class LSFileWrapperTests: XCTestCase {
6464 }
6565
6666 func testUpdateImageContent( ) {
67- // This is a test case for testing update(newContent:) method
67+ // This is a test case for testing update(newContent:) method using an Image
6868 let testImg = NSImage ( named: " NSApplicationIcon " ) ?? NSImage ( )
6969 let fileWrapper = LSFileWrapper ( file: ( ) )
7070 fileWrapper. update ( newContent: testImg)
@@ -86,6 +86,63 @@ class LSFileWrapperTests: XCTestCase {
8686 XCTAssertEqual ( fileWrapper? . string ( ) , " Hello World! " )
8787 }
8888
89+ func testSetContent( ) {
90+ // This is a test case for testing set(content: withFilename:) method
91+ let wrapper = LSFileWrapper ( directory: ( ) )
92+ wrapper. set ( content: " Hello World! " as NSString , withFilename: " hello.txt " )
93+
94+ let fileWrapper = wrapper. wrapper ( with: " hello.txt " )
95+
96+ XCTAssertNotNil ( fileWrapper)
97+ XCTAssertNotNil ( fileWrapper? . string ( ) )
98+
99+ XCTAssertEqual ( fileWrapper? . string ( ) , " Hello World! " )
100+ }
101+
102+ func testAddContentNameAlteration( ) {
103+ // This is a test case for testing add(content: withFilename:) method when a file already exists
104+ let wrapper = LSFileWrapper ( directory: ( ) )
105+ wrapper. add ( content: " Hello World! " as NSString , withFilename: " hello.txt " )
106+ let newName = wrapper. add ( content: " Hello Altered World! " as NSString , withFilename: " hello.txt " )
107+
108+ XCTAssertNotEqual ( newName, " hello.txt " )
109+ XCTAssertEqual ( newName, " hello 1.txt " )
110+
111+ let fileWrapper = wrapper. wrapper ( with: " hello.txt " )
112+ let secondWrapper = wrapper. wrapper ( with: newName)
113+
114+ XCTAssertNotNil ( fileWrapper)
115+ XCTAssertNotNil ( fileWrapper? . string ( ) )
116+
117+ XCTAssertEqual ( fileWrapper? . string ( ) , " Hello World! " )
118+
119+ XCTAssertNotNil ( secondWrapper)
120+ XCTAssertNotNil ( secondWrapper? . string ( ) )
121+
122+ XCTAssertEqual ( secondWrapper? . string ( ) , " Hello Altered World! " )
123+ }
124+
125+ func testSetContentReplacement( ) {
126+ // This is a test case for testing set(content: withFilename:) method when a file already exists
127+ let wrapper = LSFileWrapper ( directory: ( ) )
128+ wrapper. add ( content: " Hello World! " as NSString , withFilename: " hello.txt " )
129+
130+ let fileWrapper = wrapper. wrapper ( with: " hello.txt " )
131+
132+ XCTAssertNotNil ( fileWrapper)
133+ XCTAssertNotNil ( fileWrapper? . string ( ) )
134+
135+ XCTAssertEqual ( fileWrapper? . string ( ) , " Hello World! " )
136+
137+ wrapper. set ( content: " Hello Altered World! " as NSString , withFilename: " hello.txt " )
138+ let secondWrapper = wrapper. wrapper ( with: " hello.txt " )
139+
140+ XCTAssertNotNil ( secondWrapper)
141+ XCTAssertNotNil ( secondWrapper? . string ( ) )
142+
143+ XCTAssertEqual ( secondWrapper? . string ( ) , " Hello Altered World! " )
144+ }
145+
89146 func testRemoveContent( ) {
90147 // This is a test case for testing add(content: withFilename:) method
91148 let wrapper = LSFileWrapper ( directory: ( ) )
@@ -141,6 +198,7 @@ class LSFileWrapperTests: XCTestCase {
141198 }
142199
143200 func testWriteToURL( ) throws {
201+ // This is a test case for testing write(to:) method
144202 let url = URL ( fileURLWithPath: NSTemporaryDirectory ( ) ) . appendingPathComponent ( " testWrite.package " )
145203 let testDict = [ " Name " : " LSFileWrapper " , " Platforms " : [ " macOS " , " iOS " ] , " Version " : 2 ] as [ String : Any ]
146204 let testImg = NSImage ( named: " NSApplicationIcon " ) ?? NSImage ( )
@@ -179,6 +237,7 @@ class LSFileWrapperTests: XCTestCase {
179237 }
180238
181239 func testWriteFileToURL( ) throws {
240+ // This is a test case for testing write(to:) method on regular file wrappers
182241 let url = URL ( fileURLWithPath: NSTemporaryDirectory ( ) ) . appendingPathComponent ( " hello.txt " )
183242 let fileWrapper = LSFileWrapper ( file: ( ) )
184243 fileWrapper. update ( newContent: " Hello World! " as NSString )
@@ -199,6 +258,7 @@ class LSFileWrapperTests: XCTestCase {
199258 }
200259
201260 func testInitWithContentsAutomaticDirDiscovery( ) throws {
261+ // This is a test case for testing initializer's isDirectory property
202262 let url = URL ( fileURLWithPath: NSTemporaryDirectory ( ) ) . appendingPathComponent ( " testAutoDir.package " )
203263 let wrapper = LSFileWrapper ( directory: ( ) )
204264 wrapper. add ( content: " Hello World! " as NSString , withFilename: " hello.txt " )
@@ -218,6 +278,7 @@ class LSFileWrapperTests: XCTestCase {
218278 }
219279
220280 func testWriteUpdatesToURL( ) throws {
281+ // This is a test case for testing writeUpdates(to:) method
221282 let url = URL ( fileURLWithPath: NSTemporaryDirectory ( ) ) . appendingPathComponent ( " testWriteUpdates.package " )
222283 let wrapper = LSFileWrapper ( directory: ( ) )
223284 wrapper. add ( content: " Hello World! " as NSString , withFilename: " hello.txt " )
0 commit comments