mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[test] stdlib/StringTraps: Add some test coverage for String.index(before:) traps
This commit is contained in:
@@ -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() },
|
||||
|
||||
Reference in New Issue
Block a user