Skip to content

Commit 0507518

Browse files
committed
Make NSString(contentsOf:usedEncoding:) tests work on macOS
- Add the NSString-UTF32-{LE,BE}-data.txt tests to the copy resources. - Add the BOM marker 0xFEFF to the start of the comparison string.
1 parent a64dc48 commit 0507518

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Foundation.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@
321321
B90C57BC1EEEEA5A005208AE /* TestThread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5835F31C20C9B500C81317 /* TestThread.swift */; };
322322
B910957A1EEF237800A71930 /* NSString-UTF16-LE-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = B91095781EEF237800A71930 /* NSString-UTF16-LE-data.txt */; };
323323
B910957B1EEF237800A71930 /* NSString-UTF16-BE-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = B91095791EEF237800A71930 /* NSString-UTF16-BE-data.txt */; };
324+
B933A79E1F3055F700FE6846 /* NSString-UTF32-BE-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = B933A79C1F3055F600FE6846 /* NSString-UTF32-BE-data.txt */; };
325+
B933A79F1F3055F700FE6846 /* NSString-UTF32-LE-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = B933A79D1F3055F600FE6846 /* NSString-UTF32-LE-data.txt */; };
324326
B9974B961EDF4A22007F15B8 /* TransferState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9974B8F1EDF4A22007F15B8 /* TransferState.swift */; };
325327
B9974B971EDF4A22007F15B8 /* MultiHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9974B901EDF4A22007F15B8 /* MultiHandle.swift */; };
326328
B9974B981EDF4A22007F15B8 /* libcurlHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9974B911EDF4A22007F15B8 /* libcurlHelpers.swift */; };
@@ -785,6 +787,8 @@
785787
B167A6641ED7303F0040B09A /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
786788
B91095781EEF237800A71930 /* NSString-UTF16-LE-data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "NSString-UTF16-LE-data.txt"; sourceTree = "<group>"; };
787789
B91095791EEF237800A71930 /* NSString-UTF16-BE-data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "NSString-UTF16-BE-data.txt"; sourceTree = "<group>"; };
790+
B933A79C1F3055F600FE6846 /* NSString-UTF32-BE-data.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "NSString-UTF32-BE-data.txt"; sourceTree = "<group>"; };
791+
B933A79D1F3055F600FE6846 /* NSString-UTF32-LE-data.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = "NSString-UTF32-LE-data.txt"; sourceTree = "<group>"; };
788792
B9974B8F1EDF4A22007F15B8 /* TransferState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TransferState.swift; path = http/TransferState.swift; sourceTree = "<group>"; };
789793
B9974B901EDF4A22007F15B8 /* MultiHandle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MultiHandle.swift; path = http/MultiHandle.swift; sourceTree = "<group>"; };
790794
B9974B911EDF4A22007F15B8 /* libcurlHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = libcurlHelpers.swift; path = http/libcurlHelpers.swift; sourceTree = "<group>"; };
@@ -1402,6 +1406,8 @@
14021406
CE19A88B1C23AA2300B4CB6A /* NSStringTestData.txt */,
14031407
B91095781EEF237800A71930 /* NSString-UTF16-LE-data.txt */,
14041408
B91095791EEF237800A71930 /* NSString-UTF16-BE-data.txt */,
1409+
B933A79C1F3055F600FE6846 /* NSString-UTF32-BE-data.txt */,
1410+
B933A79D1F3055F600FE6846 /* NSString-UTF32-LE-data.txt */,
14051411
528776181BF27D9500CB0090 /* Test.plist */,
14061412
EA66F63B1BF1619600136161 /* NSURLTestData.plist */,
14071413
E1A3726E1C31EBFB0023AF4D /* NSXMLDocumentTestData.xml */,
@@ -2076,6 +2082,8 @@
20762082
isa = PBXResourcesBuildPhase;
20772083
buildActionMask = 2147483647;
20782084
files = (
2085+
B933A79E1F3055F700FE6846 /* NSString-UTF32-BE-data.txt in Resources */,
2086+
B933A79F1F3055F700FE6846 /* NSString-UTF32-LE-data.txt in Resources */,
20792087
D3A597F41C34142600295652 /* NSKeyedUnarchiver-NotificationTest.plist in Resources */,
20802088
528776191BF27D9500CB0090 /* Test.plist in Resources */,
20812089
EA66F6481BF1619600136161 /* NSURLTestData.plist in Resources */,

TestFoundation/TestNSString.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class TestNSString : XCTestCase {
313313
do {
314314
var encoding: UInt = 0
315315
let string = try NSString(contentsOf: testFileURL, usedEncoding: &encoding)
316-
XCTAssertEqual(string, "NSString fromURL usedEncoding test with UTF16 BE file", "Wrong result when reading UTF16BE file")
316+
XCTAssertEqual(string, "\u{FEFF}NSString fromURL usedEncoding test with UTF16 BE file", "Wrong result when reading UTF16BE file")
317317
XCTAssertEqual(encoding, String.Encoding.utf16BigEndian.rawValue, "Wrong encoding detected from UTF16BE file")
318318
} catch {
319319
XCTFail("Unable to init NSString from contentsOf:usedEncoding:")
@@ -329,7 +329,7 @@ class TestNSString : XCTestCase {
329329
do {
330330
var encoding: UInt = 0
331331
let string = try NSString(contentsOf: testFileURL, usedEncoding: &encoding)
332-
XCTAssertEqual(string, "NSString fromURL usedEncoding test with UTF16 LE file", "Wrong result when reading UTF16LE file")
332+
XCTAssertEqual(string, "\u{FEFF}NSString fromURL usedEncoding test with UTF16 LE file", "Wrong result when reading UTF16LE file")
333333
XCTAssertEqual(encoding, String.Encoding.utf16LittleEndian.rawValue, "Wrong encoding detected from UTF16LE file")
334334
} catch {
335335
XCTFail("Unable to init NSString from contentOf:usedEncoding:")
@@ -345,7 +345,7 @@ class TestNSString : XCTestCase {
345345
do {
346346
var encoding: UInt = 0
347347
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")
348+
XCTAssertEqual(string, "\u{FEFF}NSString fromURL usedEncoding test with UTF32 BE file", "Wrong result when reading UTF32BE file")
349349
XCTAssertEqual(encoding, String.Encoding.utf32BigEndian.rawValue, "Wrong encoding detected from UTF32BE file")
350350
} catch {
351351
XCTFail("Unable to init NSString from contentOf:usedEncoding:")
@@ -361,7 +361,7 @@ class TestNSString : XCTestCase {
361361
do {
362362
var encoding: UInt = 0
363363
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")
364+
XCTAssertEqual(string, "\u{FEFF}NSString fromURL usedEncoding test with UTF32 LE file", "Wrong result when reading UTF32LE file")
365365
XCTAssertEqual(encoding, String.Encoding.utf32LittleEndian.rawValue, "Wrong encoding detected from UTF32LE file")
366366
} catch {
367367
XCTFail("Unable to init NSString from contentOf:usedEncoding:")

0 commit comments

Comments
 (0)