@@ -47,6 +47,8 @@ class TestNSArray : XCTestCase {
47
47
( " test_mutableCopying " , test_mutableCopying) ,
48
48
( " test_writeToFile " , test_writeToFile) ,
49
49
( " test_initWithContentsOfFile " , test_initWithContentsOfFile) ,
50
+ ( " test_initMutableWithContentsOfFile " , test_initMutableWithContentsOfFile) ,
51
+ ( " test_initMutableWithContentsOfURL " , test_initMutableWithContentsOfURL) ,
50
52
( " test_readWriteURL " , test_readWriteURL) ,
51
53
( " test_insertObjectAtIndex " , test_insertObjectAtIndex) ,
52
54
( " test_insertObjectsAtIndexes " , test_insertObjectsAtIndexes) ,
@@ -647,7 +649,46 @@ class TestNSArray : XCTestCase {
647
649
XCTFail ( " Temporary file creation failed " )
648
650
}
649
651
}
650
-
652
+
653
+ func test_initMutableWithContentsOfFile( ) {
654
+ if let testFilePath = createTestFile ( " TestFileOut.txt " , _contents: Data ( capacity: 234 ) ) {
655
+ let a1 : NSArray = [ " foo " , " bar " ]
656
+ let isWritten = a1. write ( toFile: testFilePath, atomically: true )
657
+ if isWritten {
658
+ let array = NSMutableArray . init ( contentsOfFile: testFilePath)
659
+ XCTAssert ( array == a1)
660
+ XCTAssertEqual ( array? . count, 2 )
661
+ array? . removeAllObjects ( )
662
+ XCTAssertEqual ( array? . count, 0 )
663
+ } else {
664
+ XCTFail ( " Write to file failed " )
665
+ }
666
+ removeTestFile ( testFilePath)
667
+ } else {
668
+ XCTFail ( " Temporary file creation failed " )
669
+ }
670
+ }
671
+
672
+ func test_initMutableWithContentsOfURL( ) {
673
+ if let testFilePath = createTestFile ( " TestFileOut.txt " , _contents: Data ( capacity: 234 ) ) {
674
+ let a1 : NSArray = [ " foo " , " bar " ]
675
+ let isWritten = a1. write ( toFile: testFilePath, atomically: true )
676
+ if isWritten {
677
+ let url = URL ( fileURLWithPath: testFilePath, isDirectory: false )
678
+ let array = NSMutableArray . init ( contentsOf: url)
679
+ XCTAssert ( array == a1)
680
+ XCTAssertEqual ( array? . count, 2 )
681
+ array? . removeAllObjects ( )
682
+ XCTAssertEqual ( array? . count, 0 )
683
+ } else {
684
+ XCTFail ( " Write to file failed " )
685
+ }
686
+ removeTestFile ( testFilePath)
687
+ } else {
688
+ XCTFail ( " Temporary file creation failed " )
689
+ }
690
+ }
691
+
651
692
func test_writeToFile( ) {
652
693
let testFilePath = createTestFile ( " TestFileOut.txt " , _contents: Data ( capacity: 234 ) )
653
694
if let _ = testFilePath {
0 commit comments