@@ -1013,23 +1013,22 @@ suite.test("UTF-16 breadcrumbs") {
10131013 c̵̛̘̥̮̙̥̟̘̝͙̤̮͉͔̭̺̺̅̀̽̒̽̏̊̆͒͌̂͌̌̓̈́̐̔̿̂͑͠͝͝ͅ\#
10141014 """#
10151015
1016- print ( string. utf16. count)
10171016 let indices = Array ( string. utf16. indices) + [ string. utf16. endIndex]
10181017 for i in 0 ..< indices. count {
10191018 for j in 0 ..< indices. count {
10201019 let distance = string. utf16. distance ( from: indices [ i] , to: indices [ j] )
10211020 expectEqual ( distance, j - i,
10221021 """
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] )
10251024 """ )
10261025
10271026 let target = string. utf16. index ( indices [ i] , offsetBy: j - i)
10281027 expectEqual ( target, indices [ j] ,
10291028 """
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)
10331032 """ )
10341033 }
10351034 }
@@ -1136,9 +1135,9 @@ if #available(SwiftStdlib 5.8, *) {
11361135 let actual = string. _index ( roundingDown: index)
11371136 expectEqual ( actual, expected,
11381137 """
1139- index: \( index. _description )
1140- actual: \( actual. _description )
1141- expected: \( expected. _description )
1138+ index: \( index)
1139+ actual: \( actual)
1140+ expected: \( expected)
11421141 """ )
11431142 }
11441143 }
@@ -1154,9 +1153,9 @@ suite.test("String index rounding/Scalars")
11541153 let actual = string. unicodeScalars. _index ( roundingDown: index)
11551154 expectEqual ( actual, expected,
11561155 """
1157- index: \( index. _description )
1158- actual: \( actual. _description )
1159- expected: \( expected. _description )
1156+ index: \( index)
1157+ actual: \( actual)
1158+ expected: \( expected)
11601159 """ )
11611160 }
11621161}
@@ -1180,9 +1179,9 @@ suite.test("String index rounding/UTF-16")
11801179 let actual = string. utf16. _index ( roundingDown: index)
11811180 expectEqual ( actual, expected,
11821181 """
1183- index: \( index. _description )
1184- actual: \( actual. _description )
1185- expected: \( expected. _description )
1182+ index: \( index)
1183+ actual: \( actual)
1184+ expected: \( expected)
11861185 """ )
11871186 }
11881187}
@@ -1205,9 +1204,81 @@ suite.test("String index rounding/UTF-8")
12051204 let actual = string. utf8. _index ( roundingDown: index)
12061205 expectEqual ( actual, expected,
12071206 """
1208- index: \( index. _description )
1209- actual: \( actual. _description )
1210- expected: \( expected. _description )
1207+ index: \( index)
1208+ actual: \( actual)
1209+ expected: \( expected)
12111210 """ )
12121211 }
12131212}
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 description backdeployment " ) {
1244+ // Note: no availability check
1245+ let str = " i \u{308} "
1246+ expectEqual ( str. startIndex. description, " 0[any] " )
1247+ expectEqual ( str. endIndex. description, " 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