@@ -198,5 +198,67 @@ StringTraps.test("UTF8ViewIndex/offsetCrash")
198
198
_ = s8. utf8 [ i]
199
199
}
200
200
201
+ StringTraps . test ( " UnicodeScalarView index(before:) trap on startIndex " )
202
+ . skip (
203
+ . custom( { _isFastAssertConfiguration ( ) } ,
204
+ reason: " trap is not guaranteed to happen in -Ounchecked " ) )
205
+ . code {
206
+ guard #available( SwiftStdlib 5 . 7 , * ) else { return }
207
+
208
+ let s = " abc "
209
+ var i = s. unicodeScalars. endIndex
210
+ i = s. unicodeScalars. index ( before: i)
211
+ i = s. unicodeScalars. index ( before: i)
212
+ i = s. unicodeScalars. index ( before: i)
213
+ expectCrashLater ( )
214
+ i = s. unicodeScalars. index ( before: i)
215
+ }
216
+
217
+ StringTraps . test ( " UnicodeScalarView index(before:) trap on startIndex after scalar alignment " )
218
+ . skip (
219
+ . custom( { _isFastAssertConfiguration ( ) } ,
220
+ reason: " trap is not guaranteed to happen in -Ounchecked " ) )
221
+ . code {
222
+ guard #available( SwiftStdlib 5 . 7 , * ) else { return }
223
+
224
+ let s = " 🥦 Floret of broccoli "
225
+ var i = s. utf8. index ( after: s. utf8. startIndex)
226
+ expectCrashLater ( )
227
+ // `i` is equivalent to `s.startIndex` as far as `String.UnicodeScalarView` is
228
+ // concerned
229
+ i = s. unicodeScalars. index ( before: i)
230
+ }
231
+
232
+ StringTraps . test ( " UnicodeScalarView index(after:) trap on endIndex " )
233
+ . skip (
234
+ . custom( { _isFastAssertConfiguration ( ) } ,
235
+ reason: " trap is not guaranteed to happen in -Ounchecked " ) )
236
+ . code {
237
+ guard #available( SwiftStdlib 5 . 7 , * ) else { return }
238
+
239
+ let s = " abc "
240
+ var i = s. unicodeScalars. startIndex
241
+ i = s. unicodeScalars. index ( after: i)
242
+ i = s. unicodeScalars. index ( after: i)
243
+ i = s. unicodeScalars. index ( after: i)
244
+ expectCrashLater ( )
245
+ i = s. unicodeScalars. index ( after: i)
246
+ }
247
+
248
+ StringTraps . test ( " UnicodeScalarView index(after:) trap on i > endIndex " )
249
+ . skip (
250
+ . custom( { _isFastAssertConfiguration ( ) } ,
251
+ reason: " trap is not guaranteed to happen in -Ounchecked " ) )
252
+ . code {
253
+ guard #available( SwiftStdlib 5 . 7 , * ) else { return }
254
+
255
+ let long = " abcd "
256
+ var i = long. unicodeScalars. endIndex
257
+
258
+ let s = " abc "
259
+ expectCrashLater ( )
260
+ i = s. unicodeScalars. index ( after: i)
261
+ }
262
+
201
263
runAllTests ( )
202
264
0 commit comments