Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/browser/css/parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub const Parser = struct {
}

const c = p.s[p.i];
if (!nameStart(c) or c == '\\') {
if (!(nameStart(c) or c == '\\')) {
return ParseError.ExpectedSelector;
}

Expand Down Expand Up @@ -949,3 +949,36 @@ test "parser.parseString" {
};
}
}

test "parser.parse" {
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
const alloc = arena.allocator();

const testcases = [_]struct {
s: []const u8, // given value
exp: Selector, // expected value
err: bool = false,
}{
.{ .s = "root", .exp = .{ .tag = "root" } },
.{ .s = ".root", .exp = .{ .class = "root" } },
.{ .s = ":root", .exp = .{ .pseudo_class = .root } },
.{ .s = ".\\:bar", .exp = .{ .class = ":bar" } },
.{ .s = ".foo\\:bar", .exp = .{ .class = "foo:bar" } },
};

for (testcases) |tc| {
var p = Parser{ .s = tc.s, .opts = .{} };
const sel = p.parse(alloc) catch |e| {
// if error was expected, continue.
if (tc.err) continue;

std.debug.print("test case {s}\n", .{tc.s});
return e;
};
std.testing.expectEqualDeep(tc.exp, sel) catch |e| {
std.debug.print("test case {s} : {}\n", .{ tc.s, sel });
return e;
};
}
}
3 changes: 3 additions & 0 deletions src/browser/dom/document.zig
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ test "Browser.DOM.Document" {
,
"1",
},

.{ "document.querySelectorAll('.\\\\:popover-open').length", "0" },
.{ "document.querySelectorAll('.foo\\\\:bar').length", "0" },
}, .{});

try runner.testCases(&.{
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/test_primitive_types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,8 @@ test "JS: primitive types" {
.{ "p.returnFloat32()", "1.100000023841858,-200.03500366210938,0.0003000000142492354" },
.{ "p.returnFloat64()", "8881.22284,-4928.3838122,-0.00004" },
}, .{});

try runner.testCases(&.{
.{ "'foo\\\\:bar'", "foo\\:bar" },
}, .{});
}