mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Change unicodescalar to failable
We were using a precondition which crashes the program when invalid input is provided. We want to provide a way to gracefully check and handle invalid input or shutdown the program if necessary. SR-1930
This commit is contained in:
@@ -764,6 +764,7 @@ UnicodeScalarTests.test("init") {
|
||||
expectEqual("g", UnicodeScalar(UInt32(103)))
|
||||
expectEqual("h", UnicodeScalar(UInt16(104)))
|
||||
expectEqual("i", UnicodeScalar(UInt8(105)))
|
||||
expectEqual(nil, UnicodeScalar(UInt32(0xD800)))
|
||||
}
|
||||
|
||||
var UTF8Decoder = TestSuite("UTF8Decoder")
|
||||
@@ -2357,7 +2358,7 @@ StringCookedViews.test("UTF16") {
|
||||
|
||||
StringCookedViews.test("UnicodeScalars") {
|
||||
for test in UTF8TestsSmokeTest {
|
||||
let expectedScalars = test.scalars.map { UnicodeScalar($0) }
|
||||
let expectedScalars = test.scalars.map { UnicodeScalar($0)! }
|
||||
let subject = NonContiguousNSString(test.scalars) as String
|
||||
checkSliceableWithBidirectionalIndex(
|
||||
expectedScalars, subject.unicodeScalars)
|
||||
@@ -2366,7 +2367,7 @@ StringCookedViews.test("UnicodeScalars") {
|
||||
forStringsWithUnpairedSurrogates {
|
||||
(test: UTF16Test, subject: String) -> Void in
|
||||
let expectedScalars = (test.scalarsHead + test.scalarsRepairedTail).map {
|
||||
UnicodeScalar($0)
|
||||
UnicodeScalar($0)!
|
||||
}
|
||||
checkSliceableWithBidirectionalIndex(
|
||||
expectedScalars, subject.unicodeScalars)
|
||||
|
||||
Reference in New Issue
Block a user