@@ -1013,23 +1013,22 @@ suite.test("UTF-16 breadcrumbs") {
1013
1013
c̵̛̘̥̮̙̥̟̘̝͙̤̮͉͔̭̺̺̅̀̽̒̽̏̊̆͒͌̂͌̌̓̈́̐̔̿̂͑͠͝͝ͅ\#
1014
1014
"""#
1015
1015
1016
- print ( string. utf16. count)
1017
1016
let indices = Array ( string. utf16. indices) + [ string. utf16. endIndex]
1018
1017
for i in 0 ..< indices. count {
1019
1018
for j in 0 ..< indices. count {
1020
1019
let distance = string. utf16. distance ( from: indices [ i] , to: indices [ j] )
1021
1020
expectEqual ( distance, j - i,
1022
1021
"""
1023
- i: \( i) , indices[i]: \( indices [ i] . _description )
1024
- j: \( j) , indices[j]: \( indices [ j] . _description )
1022
+ i: \( i) , indices[i]: \( indices [ i] )
1023
+ j: \( j) , indices[j]: \( indices [ j] )
1025
1024
""" )
1026
1025
1027
1026
let target = string. utf16. index ( indices [ i] , offsetBy: j - i)
1028
1027
expectEqual ( target, indices [ j] ,
1029
1028
"""
1030
- i: \( i) , indices[i]: \( indices [ i] . _description )
1031
- j: \( j) , indices[j]: \( indices [ j] . _description )
1032
- target: \( target. _description )
1029
+ i: \( i) , indices[i]: \( indices [ i] )
1030
+ j: \( j) , indices[j]: \( indices [ j] )
1031
+ target: \( target)
1033
1032
""" )
1034
1033
}
1035
1034
}
@@ -1136,9 +1135,9 @@ if #available(SwiftStdlib 5.8, *) {
1136
1135
let actual = string. _index ( roundingDown: index)
1137
1136
expectEqual ( actual, expected,
1138
1137
"""
1139
- index: \( index. _description )
1140
- actual: \( actual. _description )
1141
- expected: \( expected. _description )
1138
+ index: \( index)
1139
+ actual: \( actual)
1140
+ expected: \( expected)
1142
1141
""" )
1143
1142
}
1144
1143
}
@@ -1154,9 +1153,9 @@ suite.test("String index rounding/Scalars")
1154
1153
let actual = string. unicodeScalars. _index ( roundingDown: index)
1155
1154
expectEqual ( actual, expected,
1156
1155
"""
1157
- index: \( index. _description )
1158
- actual: \( actual. _description )
1159
- expected: \( expected. _description )
1156
+ index: \( index)
1157
+ actual: \( actual)
1158
+ expected: \( expected)
1160
1159
""" )
1161
1160
}
1162
1161
}
@@ -1180,9 +1179,9 @@ suite.test("String index rounding/UTF-16")
1180
1179
let actual = string. utf16. _index ( roundingDown: index)
1181
1180
expectEqual ( actual, expected,
1182
1181
"""
1183
- index: \( index. _description )
1184
- actual: \( actual. _description )
1185
- expected: \( expected. _description )
1182
+ index: \( index)
1183
+ actual: \( actual)
1184
+ expected: \( expected)
1186
1185
""" )
1187
1186
}
1188
1187
}
@@ -1205,9 +1204,81 @@ suite.test("String index rounding/UTF-8")
1205
1204
let actual = string. utf8. _index ( roundingDown: index)
1206
1205
expectEqual ( actual, expected,
1207
1206
"""
1208
- index: \( index. _description )
1209
- actual: \( actual. _description )
1210
- expected: \( expected. _description )
1207
+ index: \( index)
1208
+ actual: \( actual)
1209
+ expected: \( expected)
1211
1210
""" )
1212
1211
}
1213
1212
}
1213
+
1214
+ if #available( SwiftStdlib 6 . 1 , * ) {
1215
+ suite. test ( " String index printing (native) " ) {
1216
+ let str = " nai \u{308} ve 🪻 "
1217
+
1218
+ let utf8Indices = [
1219
+ " 0[any] " , " 1[utf8] " , " 2[utf8] " , " 3[utf8] " , " 4[utf8] " , " 5[utf8] " ,
1220
+ " 6[utf8] " , " 7[utf8] " , " 8[utf8] " , " 9[utf8] " , " 10[utf8] " , " 11[utf8] "
1221
+ ]
1222
+ expectEqual ( str. utf8. indices. map { " \( $0) " } , utf8Indices)
1223
+
1224
+ let utf16Indices = [
1225
+ " 0[any] " , " 1[utf8] " , " 2[utf8] " , " 3[utf8] " , " 5[utf8] " , " 6[utf8] " ,
1226
+ " 7[utf8] " , " 8[utf8] " , " 8[utf8]+1 "
1227
+ ]
1228
+ expectEqual ( str. utf16. indices. map { " \( $0) " } , utf16Indices)
1229
+
1230
+ let scalarIndices = [
1231
+ " 0[any] " , " 1[utf8] " , " 2[utf8] " , " 3[utf8] " , " 5[utf8] " , " 6[utf8] " ,
1232
+ " 7[utf8] " , " 8[utf8] "
1233
+ ]
1234
+ expectEqual ( str. unicodeScalars. indices. map { " \( $0) " } , scalarIndices)
1235
+
1236
+ let characterIndices = [
1237
+ " 0[any] " , " 1[utf8] " , " 2[utf8] " , " 5[utf8] " , " 6[utf8] " , " 7[utf8] " , " 8[utf8] "
1238
+ ]
1239
+ expectEqual ( str. indices. map { " \( $0) " } , characterIndices)
1240
+ }
1241
+ }
1242
+
1243
+ suite. test ( " String index debugDescription backdeployment " ) {
1244
+ // Note: no availability check
1245
+ let str = " i \u{308} "
1246
+ expectEqual ( str. startIndex. debugDescription, " 0[any] " )
1247
+ expectEqual ( str. endIndex. debugDescription, " 3[utf8] " )
1248
+ }
1249
+
1250
+
1251
+ #if _runtime(_ObjC)
1252
+ if #available( SwiftStdlib 6 . 1 , * ) {
1253
+ suite. test ( " String index printing (bridged Cocoa) " ) {
1254
+ let utf16 = Array ( " nai \u{308} ve 🪻 " . utf16)
1255
+ let nsstr = NSString ( characters: utf16, length: utf16. count)
1256
+ let str = nsstr as String
1257
+
1258
+ let utf8Indices = [
1259
+ " 0[any] " , " 1[utf16] " , " 2[utf16] " , " 3[utf16] " , " 3[utf16]+1 " , " 4[utf16] " ,
1260
+ " 5[utf16] " , " 6[utf16] " , " 7[utf16] " , " 7[utf16]+1 " , " 7[utf16]+2 " ,
1261
+ " 7[utf16]+3 "
1262
+ ]
1263
+ expectEqual ( str. utf8. indices. map { " \( $0) " } , utf8Indices)
1264
+
1265
+ let utf16Indices = [
1266
+ " 0[any] " , " 1[utf16] " , " 2[utf16] " , " 3[utf16] " , " 4[utf16] " , " 5[utf16] " ,
1267
+ " 6[utf16] " , " 7[utf16] " , " 8[utf16] "
1268
+ ]
1269
+ expectEqual ( str. utf16. indices. map { " \( $0) " } , utf16Indices)
1270
+
1271
+ let scalarIndices = [
1272
+ " 0[any] " , " 1[utf16] " , " 2[utf16] " , " 3[utf16] " , " 4[utf16] " , " 5[utf16] " ,
1273
+ " 6[utf16] " , " 7[utf16] "
1274
+ ]
1275
+ expectEqual ( str. unicodeScalars. indices. map { " \( $0) " } , scalarIndices)
1276
+
1277
+ let characterIndices = [
1278
+ " 0[any] " , " 1[utf16] " , " 2[utf16] " , " 4[utf16] " , " 5[utf16] " , " 6[utf16] " ,
1279
+ " 7[utf16] "
1280
+ ]
1281
+ expectEqual ( str. indices. map { " \( $0) " } , characterIndices)
1282
+ }
1283
+ }
1284
+ #endif
0 commit comments