@@ -220,6 +220,13 @@ StringTests.test("Index/Hashable") {
220220 expectTrue ( t. contains ( s. startIndex) )
221221}
222222
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+
223230StringTests . test ( " ForeignIndexes/Valid " ) {
224231 // It is actually unclear what the correct behavior is. This test is just a
225232 // change detector.
@@ -238,6 +245,10 @@ StringTests.test("ForeignIndexes/Valid") {
238245 let acceptor = " \u{1f601} \u{1f602} \u{1f603} "
239246 expectEqual ( " \u{1f601} " , acceptor [ donor. startIndex] )
240247
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+
241252 // Donor's second index is scalar-aligned in donor, but not acceptor. This
242253 // will trigger a stdlib assertion.
243254 let donorSecondIndex = donor. index ( after: donor. startIndex)
@@ -257,6 +268,10 @@ StringTests.test("ForeignIndexes/UnexpectedCrash") {
257268 // Adjust donor.startIndex to ensure it caches a stride
258269 let start = donor. index ( before: donor. index ( after: donor. startIndex) )
259270
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+
260275 // `start` has a cached stride greater than 1, so subscript will trigger an
261276 // assertion when it makes a multi-grapheme-cluster Character.
262277 if _isStdlibInternalChecksEnabled ( ) {
0 commit comments