[String] Use the new value in utf8 setter.

ð
This commit is contained in:
Michael Ilseman
2019-02-06 15:11:17 -08:00
parent 647a29be00
commit a742a62c18
2 changed files with 25 additions and 5 deletions

View File

@@ -241,11 +241,7 @@ extension String {
@inlinable @inlinable
public var utf8: UTF8View { public var utf8: UTF8View {
@inline(__always) get { return UTF8View(self._guts) } @inline(__always) get { return UTF8View(self._guts) }
set { set { self = String(newValue._guts) }
// TODO(String testing): test suite doesn't currenlty exercise this code at
// all, test it.
self = String(utf8._guts)
}
} }
/// A contiguously stored null-terminated UTF-8 representation of the string. /// A contiguously stored null-terminated UTF-8 representation of the string.

View File

@@ -796,4 +796,28 @@ tests.test("String.UTF32View/BidirectionalCollection")
test.unicodeScalars, test.string.unicodeScalars) { $0 == $1 } 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() runAllTests()