File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,35 @@ StringTraps.test("subscript(_:)/endIndex")
5656 _ = s [ i]
5757}
5858
59+ StringTraps . test ( " String.index(before:) trap on i > endIndex " )
60+ . skip (
61+ . custom( { _isFastAssertConfiguration ( ) } ,
62+ reason: " trap is not guaranteed to happen in -Ounchecked " ) )
63+ . code {
64+ guard #available( SwiftStdlib 5 . 7 , * ) else { return }
65+
66+ let long = String ( repeating: " X " , count: 1024 )
67+ let short = " This is a short string "
68+ expectCrashLater ( )
69+ let i = short. index ( before: long. endIndex)
70+ print ( i)
71+ }
72+
73+ StringTraps . test ( " String.index(before:) trap on i == startIndex after scalar alignment " )
74+ . skip (
75+ . custom( { _isFastAssertConfiguration ( ) } ,
76+ reason: " trap is not guaranteed to happen in -Ounchecked " ) )
77+ . code {
78+ guard #available( SwiftStdlib 5 . 7 , * ) else { return }
79+
80+ let s = " 🥯 Bagel with schmear "
81+ let i = s. utf8. index ( after: s. utf8. startIndex)
82+ expectCrashLater ( )
83+ // `i` is equivalent to `s.startIndex` as far as `String` is concerned
84+ let j = s. index ( before: i)
85+ print ( j)
86+ }
87+
5988StringTraps . test ( " UTF8ViewSubscript/endIndexSuccessor " )
6089 . skip ( . custom(
6190 { _isFastAssertConfiguration ( ) } ,
You can’t perform that action at this time.
0 commit comments