Skip to content

Commit e1fc3dc

Browse files
authored
Merge pull request #14294 from vedantk/test-string-format
2 parents 2e6bda0 + 20f95f9 commit e1fc3dc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

β€Žtest/stdlib/BridgedObjectDebuggerSupport.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ func debugVal<T>(_ x: inout T) -> String {
2828
}
2929
}
3030

31+
// Check if @x uses the small-string or Cocoa representations.
32+
func hasSmallStringOrCocoaVariant(_ x: String) -> Bool {
33+
return x._guts._isCocoa || x._guts._isSmall
34+
}
35+
3136
StringForPrintObjectTests.test("Basic") {
3237
var a = "Hello World" as NSString
3338
let a_printed = printObj(a)
@@ -59,6 +64,19 @@ StringForPrintObjectTests.test("NSStringFromUnsafeBuffer") {
5964
buf.deallocate()
6065
}
6166

67+
StringForPrintObjectTests.test("NSStringUTF8") {
68+
let nsUTF16 = NSString(utf8String: "πŸ‚β˜ƒβ…β†β„οΈŽβ›„οΈβ„οΈ")!
69+
expectTrue(CFStringGetCharactersPtr(unsafeBitCast(nsUTF16, to: CFString.self)) != nil)
70+
var newNSUTF16 = nsUTF16 as String
71+
expectTrue(hasSmallStringOrCocoaVariant(newNSUTF16))
72+
let printed = printObj(newNSUTF16)
73+
let debug = debugVal(&newNSUTF16)
74+
expectEqual("πŸ‚β˜ƒβ…β†β„οΈŽβ›„οΈβ„οΈ", String(reflecting: nsUTF16))
75+
expectEqual("\"πŸ‚β˜ƒβ…β†β„οΈŽβ›„οΈβ„οΈ\"", String(reflecting: newNSUTF16))
76+
expectEqual("\"πŸ‚β˜ƒβ…β†β„οΈŽβ›„οΈβ„οΈ\"\n", printed)
77+
expectEqual(printed, debug)
78+
}
79+
6280
StringForPrintObjectTests.test("ArrayOfStrings") {
6381
var a = ["Hello World" as NSString]
6482
let a_printed = printObj(a)

0 commit comments

Comments
Β (0)