mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
zig fmt
This commit is contained in:
@@ -123,7 +123,7 @@ fn isVoid(elem: *parser.Element) !bool {
|
|||||||
fn writeEscapedTextNode(writer: anytype, value: []const u8) !void {
|
fn writeEscapedTextNode(writer: anytype, value: []const u8) !void {
|
||||||
var v = value;
|
var v = value;
|
||||||
while (v.len > 0) {
|
while (v.len > 0) {
|
||||||
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{'&', '<', '>'}) orelse {
|
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{ '&', '<', '>' }) orelse {
|
||||||
return writer.writeAll(v);
|
return writer.writeAll(v);
|
||||||
};
|
};
|
||||||
try writer.writeAll(v[0..index]);
|
try writer.writeAll(v[0..index]);
|
||||||
@@ -133,14 +133,14 @@ fn writeEscapedTextNode(writer: anytype, value: []const u8) !void {
|
|||||||
'>' => try writer.writeAll(">"),
|
'>' => try writer.writeAll(">"),
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
}
|
}
|
||||||
v = v[index+1..];
|
v = v[index + 1 ..];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn writeEscapedAttributeValue(writer: anytype, value: []const u8) !void {
|
fn writeEscapedAttributeValue(writer: anytype, value: []const u8) !void {
|
||||||
var v = value;
|
var v = value;
|
||||||
while (v.len > 0) {
|
while (v.len > 0) {
|
||||||
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{'&', '<', '>', '"'}) orelse {
|
const index = std.mem.indexOfAnyPos(u8, v, 0, &.{ '&', '<', '>', '"' }) orelse {
|
||||||
return writer.writeAll(v);
|
return writer.writeAll(v);
|
||||||
};
|
};
|
||||||
try writer.writeAll(v[0..index]);
|
try writer.writeAll(v[0..index]);
|
||||||
@@ -151,40 +151,26 @@ fn writeEscapedAttributeValue(writer: anytype, value: []const u8) !void {
|
|||||||
'"' => try writer.writeAll("""),
|
'"' => try writer.writeAll("""),
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
}
|
}
|
||||||
v = v[index+1..];
|
v = v[index + 1 ..];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
test "dump.writeHTML" {
|
test "dump.writeHTML" {
|
||||||
try testWriteHTML(
|
try testWriteHTML("<div id=\"content\">Over 9000!</div>", "<div id=\"content\">Over 9000!</div>");
|
||||||
"<div id=\"content\">Over 9000!</div>",
|
|
||||||
"<div id=\"content\">Over 9000!</div>"
|
|
||||||
);
|
|
||||||
|
|
||||||
try testWriteHTML(
|
try testWriteHTML("<root><!-- a comment --></root>", "<root><!-- a comment --></root>");
|
||||||
"<root><!-- a comment --></root>",
|
|
||||||
"<root><!-- a comment --></root>"
|
|
||||||
);
|
|
||||||
|
|
||||||
try testWriteHTML(
|
try testWriteHTML("<p>< > &</p>", "<p>< > &</p>");
|
||||||
"<p>< > &</p>",
|
|
||||||
"<p>< > &</p>"
|
|
||||||
);
|
|
||||||
|
|
||||||
try testWriteHTML(
|
try testWriteHTML("<p id=\""><&"''\">wat?</p>", "<p id='\"><&"'''>wat?</p>");
|
||||||
"<p id=\""><&"''\">wat?</p>",
|
|
||||||
"<p id='\"><&"'''>wat?</p>"
|
|
||||||
);
|
|
||||||
|
|
||||||
try testWriteFullHTML(
|
try testWriteFullHTML(
|
||||||
\\<!DOCTYPE html>
|
\\<!DOCTYPE html>
|
||||||
\\<html><head><title>It's over what?</title><meta name="a" value="b">
|
\\<html><head><title>It's over what?</title><meta name="a" value="b">
|
||||||
\\</head><body>9000</body></html>
|
\\</head><body>9000</body></html>
|
||||||
\\
|
\\
|
||||||
,
|
, "<html><title>It's over what?</title><meta name=a value=\"b\">\n<body>9000");
|
||||||
"<html><title>It's over what?</title><meta name=a value=\"b\">\n<body>9000"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn testWriteHTML(comptime expected: []const u8, src: []const u8) !void {
|
fn testWriteHTML(comptime expected: []const u8, src: []const u8) !void {
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ test "generate.Union" {
|
|||||||
value: u8 = 0,
|
value: u8 = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
const value = Union(.{ Astruct, Bstruct, .{ Cstruct } });
|
const value = Union(.{ Astruct, Bstruct, .{Cstruct} });
|
||||||
const ti = @typeInfo(value).Union;
|
const ti = @typeInfo(value).Union;
|
||||||
try std.testing.expectEqual(3, ti.fields.len);
|
try std.testing.expectEqual(3, ti.fields.len);
|
||||||
try std.testing.expectEqualStrings("*generate.test.generate.Union.Astruct.Other", @typeName(ti.fields[0].type));
|
try std.testing.expectEqualStrings("*generate.test.generate.Union.Astruct.Other", @typeName(ti.fields[0].type));
|
||||||
@@ -185,8 +185,7 @@ test "generate.Union" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "generate.Tuple" {
|
test "generate.Tuple" {
|
||||||
const Astruct = struct {
|
const Astruct = struct {};
|
||||||
};
|
|
||||||
|
|
||||||
const Bstruct = struct {
|
const Bstruct = struct {
|
||||||
value: u8 = 0,
|
value: u8 = 0,
|
||||||
@@ -207,7 +206,7 @@ test "generate.Tuple" {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// dedupe
|
// dedupe
|
||||||
const tuple = Tuple(.{ Cstruct, Astruct, .{ Astruct }, Bstruct, .{ Astruct, .{ Astruct, Bstruct } } }){};
|
const tuple = Tuple(.{ Cstruct, Astruct, .{Astruct}, Bstruct, .{ Astruct, .{ Astruct, Bstruct } } }){};
|
||||||
const ti = @typeInfo(@TypeOf(tuple)).Struct;
|
const ti = @typeInfo(@TypeOf(tuple)).Struct;
|
||||||
try std.testing.expectEqual(true, ti.is_tuple);
|
try std.testing.expectEqual(true, ti.is_tuple);
|
||||||
try std.testing.expectEqual(3, ti.fields.len);
|
try std.testing.expectEqual(3, ti.fields.len);
|
||||||
|
|||||||
Reference in New Issue
Block a user