mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] Backward-compatible String.UTF8View slicing
When slicing String.UTF8View in Swift 3 mode, in the absence of type context, produce String.UTF8View.
This commit is contained in:
committed by
Joe Shajrawi
parent
3f308b7a99
commit
05ff40d125
@@ -336,6 +336,19 @@ Tests.test("LosslessStringConvertible/generic/\(swift)") {
|
||||
f(String.self)
|
||||
}
|
||||
|
||||
#if swift(>=4)
|
||||
public typealias ExpectedUTF8ViewSlice = String.UTF8View.SubSequence
|
||||
#else
|
||||
public typealias ExpectedUTF8ViewSlice = String.UTF8View
|
||||
#endif
|
||||
|
||||
Tests.test("UTF8ViewSlicing") {
|
||||
let s = "Hello, String.UTF8View slicing world!".utf8
|
||||
var slice = s[s.startIndex..<s.endIndex]
|
||||
expectType(ExpectedUTF8ViewSlice.self, &slice)
|
||||
_ = s[s.startIndex..<s.endIndex] as String.UTF8View.SubSequence
|
||||
}
|
||||
|
||||
#if !swift(>=4)
|
||||
Tests.test("LosslessStringConvertible/force unwrap/\(swift)") {
|
||||
// Force unwrap should still work in Swift 3 mode
|
||||
|
||||
Reference in New Issue
Block a user