mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[String] Use the new value in utf8 setter.
ð
This commit is contained in:
@@ -241,11 +241,7 @@ extension String {
|
||||
@inlinable
|
||||
public var utf8: UTF8View {
|
||||
@inline(__always) get { return UTF8View(self._guts) }
|
||||
set {
|
||||
// TODO(String testing): test suite doesn't currenlty exercise this code at
|
||||
// all, test it.
|
||||
self = String(utf8._guts)
|
||||
}
|
||||
set { self = String(newValue._guts) }
|
||||
}
|
||||
|
||||
/// A contiguously stored null-terminated UTF-8 representation of the string.
|
||||
|
||||
@@ -796,4 +796,28 @@ tests.test("String.UTF32View/BidirectionalCollection")
|
||||
test.unicodeScalars, test.string.unicodeScalars) { $0 == $1 }
|
||||
}
|
||||
|
||||
tests.test("String View Setters") {
|
||||
var string = "abcd🤠👨👨👦👦efg"
|
||||
|
||||
string.utf8 = winter.utf8
|
||||
expectEqual(winter, string)
|
||||
string.utf8 = summer.utf8
|
||||
expectEqual(summer, string)
|
||||
|
||||
string.utf16 = winter.utf16
|
||||
expectEqual(winter, string)
|
||||
string.utf16 = summer.utf16
|
||||
expectEqual(summer, string)
|
||||
|
||||
string.unicodeScalars = winter.unicodeScalars
|
||||
expectEqual(winter, string)
|
||||
string.unicodeScalars = summer.unicodeScalars
|
||||
expectEqual(summer, string)
|
||||
|
||||
string = winter
|
||||
expectEqual(winter, string)
|
||||
string = summer
|
||||
expectEqual(summer, string)
|
||||
}
|
||||
|
||||
runAllTests()
|
||||
|
||||
Reference in New Issue
Block a user