Skip to content

Commit fafd8c4

Browse files
committed
Improve format and re-add docstrings
Implements RP suggestions.
1 parent 3d66758 commit fafd8c4

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

src/browser/dump.zig

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,25 @@ fn writeEscapedAttributeValue(writer: anytype, value: []const u8) !void {
157157

158158
const testing = std.testing;
159159
test "dump.writeHTML" {
160-
try testWriteHTML("<div id=\"content\">Over 9000!</div>", "<div id=\"content\">Over 9000!</div>");
161-
162-
try testWriteHTML("<root><!-- a comment --></root>", "<root><!-- a comment --></root>");
163-
164-
try testWriteHTML("<p>&lt; &gt; &amp;</p>", "<p>&lt; &gt; &amp;</p>");
165-
166-
try testWriteHTML("<p id=\"&quot;&gt;&lt;&amp;&quot;''\">wat?</p>", "<p id='\">&lt;&amp;&quot;&#39;&apos;'>wat?</p>");
160+
try testWriteHTML(
161+
"<div id=\"content\">Over 9000!</div>",
162+
"<div id=\"content\">Over 9000!</div>",
163+
);
164+
165+
try testWriteHTML(
166+
"<root><!-- a comment --></root>",
167+
"<root><!-- a comment --></root>",
168+
);
169+
170+
try testWriteHTML(
171+
"<p>&lt; &gt; &amp;</p>",
172+
"<p>&lt; &gt; &amp;</p>",
173+
);
174+
175+
try testWriteHTML(
176+
"<p id=\"&quot;&gt;&lt;&amp;&quot;''\">wat?</p>",
177+
"<p id='\">&lt;&amp;&quot;&#39;&apos;'>wat?</p>",
178+
);
167179

168180
try testWriteFullHTML(
169181
\\<!DOCTYPE html>
@@ -173,8 +185,12 @@ test "dump.writeHTML" {
173185
, "<html><title>It's over what?</title><meta name=a value=\"b\">\n<body>9000");
174186
}
175187

176-
fn testWriteHTML(comptime expected: []const u8, src: []const u8) !void {
177-
return testWriteFullHTML("<!DOCTYPE html>\n<html><head></head><body>" ++ expected ++ "</body></html>\n", src);
188+
fn testWriteHTML(comptime expected_body: []const u8, src: []const u8) !void {
189+
const expected =
190+
"<!DOCTYPE html>\n<html><head></head><body>" ++
191+
expected_body ++
192+
"</body></html>\n";
193+
return testWriteFullHTML(expected, src);
178194
}
179195

180196
fn testWriteFullHTML(comptime expected: []const u8, src: []const u8) !void {

src/generate.zig

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

1919
const std = @import("std");
20+
21+
// ----
2022
const Type = std.builtin.Type;
2123

24+
// Union
25+
// -----
26+
27+
// Generate a flatten tagged Union from a Tuple
2228
pub fn Union(interfaces: anytype) type {
2329
// @setEvalBranchQuota(10000);
2430
const tuple = Tuple(interfaces){};
@@ -57,7 +63,7 @@ pub fn Union(interfaces: anytype) type {
5763
.decls = &.{},
5864
.is_exhaustive = true,
5965
};
60-
const enum_T = @Type(std.builtin.Type{ .Enum = enum_info });
66+
const enum_T = @Type(.{ .Enum = enum_info });
6167

6268
// third iteration to generate union type
6369
var union_fields: [fields.len]Type.UnionField = undefined;
@@ -81,6 +87,12 @@ pub fn Union(interfaces: anytype) type {
8187
} });
8288
}
8389

90+
// Tuple
91+
// -----
92+
93+
// Flattens and depuplicates a list of nested tuples. For example
94+
// input: {A, B, {C, B, D}, {A, E}}
95+
// output {A, B, C, D, E}
8496
pub fn Tuple(args: anytype) type {
8597
@setEvalBranchQuota(100000);
8698

0 commit comments

Comments
 (0)