@@ -90,6 +90,7 @@ class TestNSString : XCTestCase {
90
90
( " test_deletingPathExtension " , test_deletingPathExtension) ,
91
91
( " test_ExternalRepresentation " , test_ExternalRepresentation) ,
92
92
( " test_mutableStringConstructor " , test_mutableStringConstructor) ,
93
+ ( " test_emptyStringPrefixAndSuffix " , test_emptyStringPrefixAndSuffix) ,
93
94
( " test_PrefixSuffix " , test_PrefixSuffix) ,
94
95
( " test_utf16StringRangeCount " , test_StringUTF16ViewIndexStrideableRange) ,
95
96
( " test_reflection " , { _ in test_reflection } ) ,
@@ -1056,6 +1057,12 @@ class TestNSString : XCTestCase {
1056
1057
XCTAssertEqual ( outContentsEndIndex, twoLines. index ( twoLines. startIndex, offsetBy: 11 ) )
1057
1058
XCTAssertEqual ( outEndIndex, twoLines. index ( twoLines. startIndex, offsetBy: 12 ) )
1058
1059
}
1060
+
1061
+ func test_emptyStringPrefixAndSuffix( ) {
1062
+ let testString = " hello "
1063
+ XCTAssertTrue ( testString. hasPrefix ( " " ) )
1064
+ XCTAssertTrue ( testString. hasSuffix ( " " ) )
1065
+ }
1059
1066
}
1060
1067
1061
1068
struct ComparisonTest {
@@ -1086,7 +1093,8 @@ let comparisonTests = [
1086
1093
// ASCII cases
1087
1094
ComparisonTest ( " t " , " tt " ) ,
1088
1095
ComparisonTest ( " t " , " Tt " ) ,
1089
- ComparisonTest ( " \u{0} " , " " ) ,
1096
+ ComparisonTest ( " \u{0} " , " " ,
1097
+ reason: " https://bugs.swift.org/browse/SR-332 " ) ,
1090
1098
ComparisonTest ( " \u{0} " , " \u{0} " ,
1091
1099
reason: " https://bugs.swift.org/browse/SR-332 " ) ,
1092
1100
ComparisonTest ( " \r \n " , " t " ) ,
@@ -1183,17 +1191,21 @@ enum Stack: Swift.Error {
1183
1191
}
1184
1192
1185
1193
func checkHasPrefixHasSuffix( _ lhs: String , _ rhs: String , _ stack: [ UInt ] ) -> Int {
1186
- if lhs == " " {
1194
+ if ( lhs == " " && rhs == " " ) {
1187
1195
var failures = 0
1188
- failures += lhs. hasPrefix ( rhs) ? 1 : 0
1189
- failures += lhs. hasSuffix ( rhs) ? 1 : 0
1196
+ failures += lhs. hasPrefix ( rhs) ? 0 : 1
1197
+ failures += lhs. hasSuffix ( rhs) ? 0 : 1
1190
1198
return failures
1191
- }
1192
- if rhs == " " {
1199
+ } else if lhs == " " {
1193
1200
var failures = 0
1194
1201
failures += lhs. hasPrefix ( rhs) ? 1 : 0
1195
1202
failures += lhs. hasSuffix ( rhs) ? 1 : 0
1196
1203
return failures
1204
+ } else if rhs == " " {
1205
+ var failures = 0
1206
+ failures += lhs. hasPrefix ( rhs) ? 0 : 1
1207
+ failures += lhs. hasSuffix ( rhs) ? 0 : 1
1208
+ return failures
1197
1209
}
1198
1210
1199
1211
// To determine the expected results, compare grapheme clusters,
@@ -1228,7 +1240,6 @@ func checkHasPrefixHasSuffix(_ lhs: String, _ rhs: String, _ stack: [UInt]) -> I
1228
1240
1229
1241
extension TestNSString {
1230
1242
func test_PrefixSuffix( ) {
1231
- #if !_runtime(_ObjC)
1232
1243
for test in comparisonTests {
1233
1244
var failures = 0
1234
1245
failures += checkHasPrefixHasSuffix ( test. lhs, test. rhs, [ test. loc, #line] )
@@ -1249,7 +1260,6 @@ extension TestNSString {
1249
1260
}
1250
1261
XCTAssert ( test. xfail == fail, " Unexpected \( test. xfail ? " success " : " failure " ) : \( test. loc) " )
1251
1262
}
1252
- #endif
1253
1263
}
1254
1264
}
1255
1265
0 commit comments