in PlaygroundLogger/PlaygroundLoggerTests/LogEntryTests.swift [129:169]
func testLargeSet() throws {
let set = Set(1...1000)
let logEntry = try LogEntry(describing: set, name: "set", policy: .default)
guard case let .structured(name, _, _, totalChildrenCount, children, disposition) = logEntry else {
XCTFail("Expected a structured log entry")
return
}
XCTAssertEqual(name, "set")
// We expect `totalChildrenCount` to be 1000 because `set` has 1000 elements.
XCTAssertEqual(totalChildrenCount, 1000)
// We expect `children.count` to be 101 due to the default logging policy, which encodes the first 80 and the last 20 children when there's more than 100 children, plus a gap in between to indicate what was elided.
XCTAssertEqual(children.count, 101)
for (index, childEntry) in children.enumerated() {
if index == 80 {
// We expect the 81st child to be a gap based on the default logging policy for containers.
guard case .gap = childEntry else {
XCTFail("Expected this entry to be a gap entry!")
return
}
}
else {
// We expect all other children to be opaque entries representing the Ints in the set.
guard case let .opaque(_, _, _, _, representation) = childEntry else {
XCTFail("Expected this entry to be an opaque entry!")
return
}
// We don't know the precise value, due to hashing in the set.
// But we *do* know that the value should be an Int64, so check that at least.
XCTAssert(representation is Int64)
}
}
XCTAssertEqual(disposition, .membershipContainer)
}