[test] stdlib/StringTraps: Add some test coverage for String.index(before:) traps

This commit is contained in:
Karoy Lorentey
2022-02-28 18:07:22 -08:00
parent 5b364c4e2b
commit f528db51c5

View File

@@ -56,6 +56,35 @@ StringTraps.test("subscript(_:)/endIndex")
_ = s[i]
}
StringTraps.test("String.index(before:) trap on i > endIndex")
.skip(
.custom({ _isFastAssertConfiguration() },
reason: "trap is not guaranteed to happen in -Ounchecked"))
.code {
guard #available(SwiftStdlib 5.7, *) else { return }
let long = String(repeating: "X", count: 1024)
let short = "This is a short string"
expectCrashLater()
let i = short.index(before: long.endIndex)
print(i)
}
StringTraps.test("String.index(before:) trap on i == startIndex after scalar alignment")
.skip(
.custom({ _isFastAssertConfiguration() },
reason: "trap is not guaranteed to happen in -Ounchecked"))
.code {
guard #available(SwiftStdlib 5.7, *) else { return }
let s = "🥯 Bagel with schmear"
let i = s.utf8.index(after: s.utf8.startIndex)
expectCrashLater()
// `i` is equivalent to `s.startIndex` as far as `String` is concerned
let j = s.index(before: i)
print(j)
}
StringTraps.test("UTF8ViewSubscript/endIndexSuccessor")
.skip(.custom(
{ _isFastAssertConfiguration() },