From e4860d5bae8b358edf9ce83d3a0c96f3388844c0 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Wed, 10 Sep 2025 08:31:33 +0200 Subject: [PATCH 1/3] css: move libdom_test into libdom To be added by the test_runner as part of used files. --- src/browser/css/libdom.zig | 315 ++++++++++++++++++++++++++++++ src/browser/css/libdom_test.zig | 330 -------------------------------- 2 files changed, 315 insertions(+), 330 deletions(-) delete mode 100644 src/browser/css/libdom_test.zig diff --git a/src/browser/css/libdom.zig b/src/browser/css/libdom.zig index 44307c638..60689e956 100644 --- a/src/browser/css/libdom.zig +++ b/src/browser/css/libdom.zig @@ -19,6 +19,8 @@ const std = @import("std"); const parser = @import("../netsurf.zig"); +const css = @import("css.zig"); +const Allocator = std.mem.Allocator; // Node implementation with Netsurf Libdom C lib. pub const Node = struct { @@ -100,3 +102,316 @@ pub const Node = struct { return a.node == b.node; } }; + +const MatcherTest = struct { + const Nodes = std.ArrayListUnmanaged(Node); + + nodes: Nodes, + allocator: Allocator, + + fn init(allocator: Allocator) MatcherTest { + return .{ + .nodes = .empty, + .allocator = allocator, + }; + } + + fn deinit(m: *MatcherTest) void { + m.nodes.deinit(m.allocator); + } + + fn reset(m: *MatcherTest) void { + m.nodes.clearRetainingCapacity(); + } + + pub fn match(m: *MatcherTest, n: Node) !void { + try m.nodes.append(m.allocator, n); + } +}; + +test "Browser.CSS.Libdom: matchFirst" { + const alloc = std.testing.allocator; + + try parser.init(); + defer parser.deinit(); + + var matcher = MatcherTest.init(alloc); + defer matcher.deinit(); + + const testcases = [_]struct { + q: []const u8, + html: []const u8, + exp: usize, + }{ + .{ .q = "address", .html = "
This address...
", .exp = 1 }, + .{ .q = "*", .html = "text", .exp = 1 }, + .{ .q = "*", .html = "", .exp = 1 }, + .{ .q = "#foo", .html = "

", .exp = 1 }, + .{ .q = "li#t1", .html = "