Skip to content

Commit 574a7a0

Browse files
committed
fuzz: add support for more attribute types to the generator
1 parent 57c5638 commit 574a7a0

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

src/generator/html.zig

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,40 @@ fn renderAttr(
132132
_ = gpa;
133133
try w.print(" {s}", .{named_model.name});
134134
if (!has_value) return;
135-
switch (named_model.model.rule) {
136-
else => {
137-
const len = input.takeByte() catch return;
138-
const value = input.take(len) catch return;
139-
try w.print("=\"{s}\"", .{value});
135+
136+
const rng = input.takeByte() catch return;
137+
const rng_extra = rng >> 6;
138+
switch (rng_extra) {
139+
else => unreachable,
140+
1 => return, // no value
141+
2 => try w.writeAll("=''"),
142+
3 => try w.writeAll("='not_empty'"),
143+
0 => switch (named_model.model.rule) { // apply rule semantically
144+
else => {
145+
const len = input.takeByte() catch return;
146+
const value = input.take(len) catch return;
147+
try w.print("=\"{s}\"", .{value});
148+
},
149+
150+
.list => |list_rule| {
151+
const case = list_rule.completions[rng % list_rule.completions.len];
152+
try w.print("=\"{s}\"", .{case.label});
153+
},
154+
.cors => {
155+
const case: []const []const u8 = &.{
156+
"anonymous", "use-credentials", "arst",
157+
};
158+
159+
try w.print("=\"{s}\"", .{case[rng % case.len]});
160+
},
161+
.non_neg_int => {
162+
const case: []const []const u8 = &.{
163+
"0", "1", "2", "-1", "100", "-99", "101", "-101", "-102",
164+
};
165+
166+
try w.print("=\"{s}\"", .{case[rng % case.len]});
167+
},
140168
},
141-
// .list => {},
142169
}
143170
}
144171

0 commit comments

Comments
 (0)