@@ -67,6 +67,7 @@ class TestNSString : XCTestCase {
67
67
( " test_CFStringCreateMutableCopy " , test_CFStringCreateMutableCopy) ,
68
68
( " test_FromContentsOfURL " , test_FromContentsOfURL) ,
69
69
( " test_FromContentsOfURLUsedEncodingUTF16BE " , test_FromContentsOfURLUsedEncodingUTF16BE) ,
70
+ ( " test_FromContentsOfURLUsedEncodingUTF16LE " , test_FromContentsOfURLUsedEncodingUTF16LE) ,
70
71
( " test_FromContentOfFile " , test_FromContentOfFile) ,
71
72
( " test_swiftStringUTF16 " , test_swiftStringUTF16) ,
72
73
// This test takes forever on build servers; it has been seen up to 1852.084 seconds
@@ -313,7 +314,23 @@ class TestNSString : XCTestCase {
313
314
XCTAssertEqual ( string, " NSString fromURL usedEncoding test with UTF16 BE file " , " Wrong result when reading UTF16BE file " )
314
315
XCTAssertEqual ( encoding, String . Encoding. utf16BigEndian. rawValue, " Wrong encoding detected from UTF16BE file " )
315
316
} catch {
316
- XCTFail ( " Unable to init NSString from contentsOf:encoding: " )
317
+ XCTFail ( " Unable to init NSString from contentsOf:usedEncoding: " )
318
+ }
319
+ }
320
+
321
+ func test_FromContentsOfURLUsedEncodingUTF16LE( ) {
322
+ guard let testFileURL = testBundle ( ) . url ( forResource: " NSString-UTF16-LE-data " , withExtension: " txt " ) else {
323
+ XCTFail ( " URL for NSString-UTF16-LE-data.txt is nil " )
324
+ return
325
+ }
326
+
327
+ do {
328
+ var encoding : UInt = 0
329
+ let string = try NSString ( contentsOf: testFileURL, usedEncoding: & encoding)
330
+ XCTAssertEqual ( string, " NSString fromURL usedEncoding test with UTF16 LE file " , " Wrong result when reading UTF16LE file " )
331
+ XCTAssertEqual ( encoding, String . Encoding. utf16LittleEndian. rawValue, " Wrong encoding detected from UTF16LE file " )
332
+ } catch {
333
+ XCTFail ( " Unable to init NSString from contentOf:usedEncoding: " )
317
334
}
318
335
}
319
336
0 commit comments