func testContainerChildPolicyHead()

in PlaygroundLogger/PlaygroundLoggerTests/LogPolicyTests.swift [305:350]


    func testContainerChildPolicyHead() throws {
        let testPolicy = LogPolicy(containerChildPolicy: .head(count: 10))

        let array = Array(0...1000)

        let logEntry = try LogEntry(describing: array, name: "array", policy: testPolicy)

        guard case let .structured(name, typeName, _, totalChildrenCount, children, disposition) = logEntry else {
            XCTFail("Expected a structured log entry for an array")
            return
        }

        XCTAssertEqual(name, "array")
        XCTAssertEqual(typeName, "Array<Int>")
        XCTAssertEqual(disposition, .indexContainer)
        XCTAssertEqual(totalChildrenCount, 1001)

        guard children.count == 11 else {
            XCTFail("Expected exactly 11 children but have \(children.count)")
            return
        }

        for index in 0..<10 {
            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))
        }

        let lastChild = children[10]
        guard case .gap = lastChild else {
            XCTFail("We expect the last child to be a gap entry indicating that items were omitted")
            return
        }
    }