@@ -17,7 +17,7 @@ StringTraps.test("startIndex/predecessor")
17
17
{ _isFastAssertConfiguration ( ) } ,
18
18
reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
19
19
. code {
20
- var s = " abc "
20
+ let s = " abc "
21
21
var i = s. startIndex
22
22
i = s. index ( after: i)
23
23
i = s. index ( before: i)
@@ -30,7 +30,7 @@ StringTraps.test("endIndex/successor")
30
30
{ _isFastAssertConfiguration ( ) } ,
31
31
reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
32
32
. code {
33
- var s = " abc "
33
+ let s = " abc "
34
34
var i = s. startIndex
35
35
i = s. index ( after: i)
36
36
i = s. index ( after: i)
@@ -44,21 +44,21 @@ StringTraps.test("subscript(_:)/endIndex")
44
44
{ _isFastAssertConfiguration ( ) } ,
45
45
reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
46
46
. code {
47
- var s = " abc "
47
+ let s = " abc "
48
48
var i = s. startIndex
49
49
i = s. index ( after: i)
50
50
i = s. index ( after: i)
51
51
i = s. index ( after: i)
52
52
expectCrashLater ( )
53
- s [ i]
53
+ _ = s [ i]
54
54
}
55
55
56
56
StringTraps . test ( " UTF8ViewEndIndexSuccessor " )
57
57
. skip ( . custom(
58
58
{ _isFastAssertConfiguration ( ) } ,
59
59
reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
60
60
. code {
61
- var s = " abc "
61
+ let s = " abc "
62
62
var i = s. utf8. startIndex
63
63
i = s. utf8. index ( after: i)
64
64
i = s. utf8. index ( after: i)
@@ -72,25 +72,25 @@ StringTraps.test("UTF8ViewSubscript/endIndex")
72
72
{ _isFastAssertConfiguration ( ) } ,
73
73
reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
74
74
. code {
75
- var s = " abc "
75
+ let s = " abc "
76
76
var i = s. utf8. startIndex
77
77
i = s. utf8. index ( after: i)
78
78
i = s. utf8. index ( after: i)
79
79
i = s. utf8. index ( after: i)
80
80
expectCrashLater ( )
81
- s. utf8 [ i]
81
+ _ = s. utf8 [ i]
82
82
}
83
83
84
84
StringTraps . test ( " UTF16ViewSubscript/DecrementedStartIndex " )
85
85
. skip ( . custom(
86
86
{ _isFastAssertConfiguration ( ) } ,
87
87
reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
88
88
. code {
89
- var s = " abc "
89
+ let s = " abc "
90
90
var i = s. utf16. startIndex
91
91
expectCrashLater ( )
92
92
i = s. utf16. index ( before: i)
93
- s. utf16 [ i]
93
+ _ = s. utf16 [ i]
94
94
}
95
95
96
96
StringTraps . test ( " UTF16ViewSubscript/endIndex " )
@@ -104,7 +104,36 @@ StringTraps.test("UTF16ViewSubscript/endIndex")
104
104
i = s. utf16. index ( after: i)
105
105
i = s. utf16. index ( after: i)
106
106
expectCrashLater ( )
107
- s. utf16 [ i]
107
+ _ = s. utf16 [ i]
108
+ }
109
+
110
+ StringTraps . test ( " UTF16ViewIndex/offsetLimited " )
111
+ . code {
112
+ let sa = " foo "
113
+ let u16a = sa. utf16
114
+ let s16 = sa + " 🤦🏻♀️ "
115
+ let u16 = s16. utf16
116
+
117
+ let iaBegin = u16a. index ( sa. startIndex, offsetBy: 99 , limitedBy: sa. endIndex)
118
+ expectNil ( iaBegin)
119
+ let iaEnd = u16a. index ( sa. endIndex, offsetBy: 99 , limitedBy: sa. endIndex)
120
+ expectNil ( iaEnd)
121
+ let i16Begin = u16. index ( u16. startIndex, offsetBy: 99 , limitedBy: u16. endIndex)
122
+ expectNil ( i16Begin)
123
+ let i16End = u16. index ( u16. startIndex, offsetBy: 99 , limitedBy: u16. endIndex)
124
+ expectNil ( i16End)
125
+ }
126
+
127
+ StringTraps . test ( " UTF16ViewIndex/offsetCrash " )
128
+ . skip ( . custom(
129
+ { _isFastAssertConfiguration ( ) } ,
130
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
131
+ . code {
132
+ let s16 = " foo🤦🏻♀️ "
133
+ let u16 = s16. utf16
134
+ expectCrashLater ( )
135
+ let i = u16. index ( u16. startIndex, offsetBy: 99 )
136
+ _ = s16. utf16 [ i]
108
137
}
109
138
110
139
runAllTests ( )
0 commit comments