From e997f8317e468f5e39e9daa8a6cd23ae93d91d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Thu, 19 Mar 2026 12:25:02 +0900 Subject: [PATCH] SemanticTree: add tests for backendDOMNodeId and maxDepth --- src/SemanticTree.zig | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/SemanticTree.zig b/src/SemanticTree.zig index 45785e1b..7927a10f 100644 --- a/src/SemanticTree.zig +++ b/src/SemanticTree.zig @@ -479,3 +479,56 @@ const TextVisitor = struct { } } }; + +const testing = @import("testing.zig"); + +test "SemanticTree backendDOMNodeId" { + var registry: CDPNode.Registry = .init(testing.allocator); + defer registry.deinit(); + + var page = try testing.pageTest("cdp/registry1.html"); + defer testing.reset(); + defer page._session.removePage(); + + const st: Self = .{ + .dom_node = page.window._document.asNode(), + .registry = ®istry, + .page = page, + .arena = testing.arena_allocator, + .prune = false, + .interactive_only = false, + .max_depth = null, + }; + + const json_str = try std.json.Stringify.valueAlloc(testing.allocator, st, .{}); + defer testing.allocator.free(json_str); + + try testing.expect(std.mem.indexOf(u8, json_str, "\"backendDOMNodeId\":") != null); +} + +test "SemanticTree max_depth" { + var registry: CDPNode.Registry = .init(testing.allocator); + defer registry.deinit(); + + var page = try testing.pageTest("cdp/registry1.html"); + defer testing.reset(); + defer page._session.removePage(); + + const st: Self = .{ + .dom_node = page.window._document.asNode(), + .registry = ®istry, + .page = page, + .arena = testing.arena_allocator, + .prune = false, + .interactive_only = false, + .max_depth = 1, + }; + + var aw: std.Io.Writer.Allocating = .init(testing.allocator); + defer aw.deinit(); + + try st.textStringify(&aw.writer); + const text_str = aw.written(); + + try testing.expect(std.mem.indexOf(u8, text_str, "other") == null); +}