@@ -220,6 +220,13 @@ StringTests.test("Index/Hashable") {
220
220
expectTrue ( t. contains ( s. startIndex) )
221
221
}
222
222
223
+ var Swift_5_1_Available : Bool {
224
+ if #available( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * ) {
225
+ return true
226
+ }
227
+ return false
228
+ }
229
+
223
230
StringTests . test ( " ForeignIndexes/Valid " ) {
224
231
// It is actually unclear what the correct behavior is. This test is just a
225
232
// change detector.
@@ -238,6 +245,10 @@ StringTests.test("ForeignIndexes/Valid") {
238
245
let acceptor = " \u{1f601} \u{1f602} \u{1f603} "
239
246
expectEqual ( " \u{1f601} " , acceptor [ donor. startIndex] )
240
247
248
+ // Scalar alignment fixes and checks were added in 5.1, so we don't get the
249
+ // expected behavior on prior runtimes.
250
+ guard Swift_5_1_Available else { return }
251
+
241
252
// Donor's second index is scalar-aligned in donor, but not acceptor. This
242
253
// will trigger a stdlib assertion.
243
254
let donorSecondIndex = donor. index ( after: donor. startIndex)
@@ -257,6 +268,10 @@ StringTests.test("ForeignIndexes/UnexpectedCrash") {
257
268
// Adjust donor.startIndex to ensure it caches a stride
258
269
let start = donor. index ( before: donor. index ( after: donor. startIndex) )
259
270
271
+ // Grapheme stride cache under noop scalar alignment was fixed in 5.1, so we
272
+ // get a different answer prior.
273
+ guard Swift_5_1_Available else { return }
274
+
260
275
// `start` has a cached stride greater than 1, so subscript will trigger an
261
276
// assertion when it makes a multi-grapheme-cluster Character.
262
277
if _isStdlibInternalChecksEnabled ( ) {
0 commit comments