in PlaygroundLogger/PlaygroundLoggerTests/LogPolicyTests.swift [510:565]
func testAggregateChildPolicyHeadTail() throws {
let testPolicy = LogPolicy(aggregateChildPolicy: .headTail(headCount: 2, tailCount: 1))
let logEntry = try LogEntry(describing: TestStruct(), name: "testStruct", policy: testPolicy)
guard case let .structured(name, _, _, totalChildrenCount, children, disposition) = logEntry else {
XCTFail("Expected a structured log entry for a struct")
return
}
XCTAssertEqual(name, "testStruct")
XCTAssertEqual(disposition, .struct)
XCTAssertEqual(totalChildrenCount, 5)
guard children.count == 4 else {
XCTFail("Expected exactly 4 children but have \(children.count)")
return
}
for index in 0..<2 {
let child = children[index]
guard case let .opaque(_, typeName, _, _, representation) = child else {
XCTFail("Expected an opaque log entry for an item in the array")
continue
}
XCTAssertEqual(typeName, "Int")
guard let integer = representation as? Int64 else {
XCTFail("Expected an Int64 as the representation for an Int")
return
}
XCTAssertEqual(integer, Int64(index + 1))
}
guard case .gap = children[2] else {
XCTFail("We expect the child at index 2 to be a gap entry indicating that items were omitted")
return
}
guard case let .opaque(_, typeName, _, _, representation) = children[3] else {
XCTFail("Expected an opaque log entry for the last child")
return
}
XCTAssertEqual(typeName, "Int")
guard let integer = representation as? Int64 else {
XCTFail("Expected an Int64 as the representation for an Int")
return
}
XCTAssertEqual(integer, 5)
}