@@ -68,6 +68,8 @@ class TestNSString : XCTestCase {
68
68
( " test_FromContentsOfURL " , test_FromContentsOfURL) ,
69
69
( " test_FromContentsOfURLUsedEncodingUTF16BE " , test_FromContentsOfURLUsedEncodingUTF16BE) ,
70
70
( " test_FromContentsOfURLUsedEncodingUTF16LE " , test_FromContentsOfURLUsedEncodingUTF16LE) ,
71
+ ( " test_FromContentsOfURLUsedEncodingUTF32BE " , test_FromContentsOfURLUsedEncodingUTF32BE) ,
72
+ ( " test_FromContentsOfURLUsedEncodingUTF32LE " , test_FromContentsOfURLUsedEncodingUTF32LE) ,
71
73
( " test_FromContentOfFile " , test_FromContentOfFile) ,
72
74
( " test_swiftStringUTF16 " , test_swiftStringUTF16) ,
73
75
// This test takes forever on build servers; it has been seen up to 1852.084 seconds
@@ -334,6 +336,38 @@ class TestNSString : XCTestCase {
334
336
}
335
337
}
336
338
339
+ func test_FromContentsOfURLUsedEncodingUTF32BE( ) {
340
+ guard let testFileURL = testBundle ( ) . url ( forResource: " NSString-UTF32-BE-data " , withExtension: " txt " ) else {
341
+ XCTFail ( " URL for NSString-UTF32-BE-data.txt is nil " )
342
+ return
343
+ }
344
+
345
+ do {
346
+ var encoding : UInt = 0
347
+ let string = try NSString ( contentsOf: testFileURL, usedEncoding: & encoding)
348
+ XCTAssertEqual ( string, " NSString fromURL usedEncoding test with UTF32 BE file " , " Wrong result when reading UTF32BE file " )
349
+ XCTAssertEqual ( encoding, String . Encoding. utf32BigEndian. rawValue, " Wrong encoding detected from UTF32BE file " )
350
+ } catch {
351
+ XCTFail ( " Unable to init NSString from contentOf:usedEncoding: " )
352
+ }
353
+ }
354
+
355
+ func test_FromContentsOfURLUsedEncodingUTF32LE( ) {
356
+ guard let testFileURL = testBundle ( ) . url ( forResource: " NSString-UTF32-LE-data " , withExtension: " txt " ) else {
357
+ XCTFail ( " URL for NSString-UTF32-LE-data.txt is nil " )
358
+ return
359
+ }
360
+
361
+ do {
362
+ var encoding : UInt = 0
363
+ let string = try NSString ( contentsOf: testFileURL, usedEncoding: & encoding)
364
+ XCTAssertEqual ( string, " NSString fromURL usedEncoding test with UTF32 LE file " , " Wrong result when reading UTF32LE file " )
365
+ XCTAssertEqual ( encoding, String . Encoding. utf32LittleEndian. rawValue, " Wrong encoding detected from UTF32LE file " )
366
+ } catch {
367
+ XCTFail ( " Unable to init NSString from contentOf:usedEncoding: " )
368
+ }
369
+ }
370
+
337
371
func test_FromContentOfFile( ) {
338
372
let testFilePath = testBundle ( ) . path ( forResource: " NSStringTestData " , ofType: " txt " )
339
373
XCTAssertNotNil ( testFilePath)
0 commit comments