mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
[Heap] Clean up description
- Don’t print the type name - Include some information identifying the heap instance
This commit is contained in:
2 files changed
+27
-6
No files matched your search
@@ -12,7 +12,17 @@
|
||||
extension Heap: CustomStringConvertible {
|
||||
/// A textual representation of this instance.
|
||||
public var description: String {
|
||||
"Heap<\(Element.self)>(count: \(count))"
|
||||
"<\(count) item\(count == 1 ? "" : "s") @\(_idString)>"
|
||||
}
|
||||
|
||||
internal var _idString: String {
|
||||
// "<32 items @0x2787abcf>"
|
||||
_storage.withUnsafeBytes {
|
||||
guard let p = $0.baseAddress else {
|
||||
return "nil"
|
||||
}
|
||||
return String(UInt(bitPattern: p), radix: 16)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,12 +68,23 @@ final class HeapTests: CollectionTestCase {
|
||||
|
||||
func test_descriptions() {
|
||||
let a: Heap<Int> = []
|
||||
expectEqual(a.description, "Heap<Int>(count: 0)")
|
||||
expectEqual(a.debugDescription, "Heap<Int>(count: 0)")
|
||||
expectTrue(
|
||||
a.description.starts(with: "<0 items @"),
|
||||
"\(a.description)")
|
||||
expectTrue(
|
||||
a.debugDescription.starts(with: "<0 items @"),
|
||||
"\(a.debugDescription)")
|
||||
|
||||
let b: Heap = [1, 2]
|
||||
expectEqual(b.description, "Heap<Int>(count: 2)")
|
||||
expectEqual(b.debugDescription, "Heap<Int>(count: 2)")
|
||||
let b: Heap = [1]
|
||||
expectTrue(
|
||||
b.description.starts(with: "<1 item @"),
|
||||
"\(b.description)")
|
||||
expectTrue(
|
||||
b.debugDescription.starts(with: "<1 item @"))
|
||||
|
||||
let c: Heap = [1, 2]
|
||||
expectTrue(c.description.starts(with: "<2 items @"))
|
||||
expectTrue(c.debugDescription.starts(with: "<2 items @"))
|
||||
}
|
||||
|
||||
func test_unordered() {
|
||||
|
||||
Reference in new issue
Block a user