@@ -22,6 +22,10 @@ class TestNSString : XCTestCase {
2222 var allTests : [ ( String , ( ) -> ( ) ) ] {
2323 return [
2424 ( " test_BridgeConstruction " , test_BridgeConstruction ) ,
25+ ( " test_isEqualToStringWithStringLiteral " , test_isEqualToStringWithStringLiteral ) ,
26+ ( " test_FromASCIIData " , test_FromASCIIData ) ,
27+ ( " test_FromUTF8Data " , test_FromUTF8Data ) ,
28+ ( " test_FromMalformedUTF8Data " , test_FromMalformedUTF8Data ) ,
2529 ]
2630 }
2731
@@ -42,4 +46,29 @@ class TestNSString : XCTestCase {
4246 let cluster : NSString = " ✌🏾 "
4347 XCTAssertEqual ( cluster. length, 3 )
4448 }
49+
50+ func test_isEqualToStringWithStringLiteral( ) {
51+ let string : NSString = " literal "
52+ XCTAssertTrue ( string. isEqualToString ( " literal " ) )
53+ }
54+
55+ func test_FromASCIIData( ) {
56+ let bytes : [ UInt8 ] = [ 0x48 , 0x65 , 0x6C , 0x6C , 0x6F , 0x20 , 0x53 , 0x77 , 0x69 , 0x66 , 0x74 , 0x21 ] // "Hello Swift!"
57+ let string = NSString ( bytes: bytes, length: bytes. count, encoding: NSASCIIStringEncoding)
58+ XCTAssertNotNil ( string)
59+ XCTAssertTrue ( string!. isEqualToString ( " Hello Swift! " ) )
60+ }
61+
62+ func test_FromUTF8Data( ) {
63+ let bytes : [ UInt8 ] = [ 0x49 , 0x20 , 0xE2 , 0x9D , 0xA4 , 0xEF , 0xB8 , 0x8F , 0x20 , 0x53 , 0x77 , 0x69 , 0x66 , 0x74 ] // "I ❤️ Swift"
64+ let string = NSString ( bytes: bytes, length: bytes. count, encoding: NSUTF8StringEncoding)
65+ XCTAssertNotNil ( string)
66+ XCTAssertTrue ( string? . isEqualToString ( " I ❤️ Swift " ) ?? false )
67+ }
68+
69+ func test_FromMalformedUTF8Data( ) {
70+ let bytes : [ UInt8 ] = [ 0xFF ]
71+ let string = NSString ( bytes: bytes, length: bytes. count, encoding: NSUTF8StringEncoding)
72+ XCTAssertNil ( string)
73+ }
4574}
0 commit comments