import Testing @testable import PureXML /// HTML serialization must not recurse on a tree's depth (#350). The serializer /// walked an element's children recursively, so it overflowed the stack on a /// deeply-nested tree (as shallow as a couple of thousand deep on the Swift Task /// stack these tests run on). It now drives a deferred-close work stack; these /// tests reach depths the recursive form could not survive, and pin the /// raw-text, void, and escaping semantics the refactor must preserve. @Suite("HTML serialize depth safety") struct HTMLSerializeDepthSafetyTests { private func deepTree(_ depth: Int, leaf: String) -> PureXML.Model.Node { var node: PureXML.Model.Node = .text(leaf) for _ in 0 ..< depth { node = .element(.init("div", children: [node])) } return node } @Test("serialize on a 50k-deep tree emits balanced tags without overflowing") func test_deepSerializeIsBounded() { let depth = 50000 let html = PureXML.HTML.serialize(deepTree(depth, leaf: "leaf")) #expect(html.hasPrefix(String(repeating: "