milestone 18: collapse duplicated infrastructure into shared listener core, crud list helper, resource shells, transport race, name and line helpers, ui modules
This commit is contained in:
@@ -29,7 +29,10 @@
|
||||
|
||||
const std = @import("std");
|
||||
const http_util = @import("http_util");
|
||||
const smith_encode = @import("smith_encode.zig");
|
||||
|
||||
const sliceInput = smith_encode.sliceInput;
|
||||
const pairInput = smith_encode.pairInput;
|
||||
const Smith = std.testing.Smith;
|
||||
|
||||
/// A target longer than this is a 414 before it reaches any parser
|
||||
@@ -149,9 +152,8 @@ fn expectPrefixOf(result: []const u8, buffer: []const u8) !void {
|
||||
// corpus
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// `Smith` does not consume a corpus entry as raw parser input. It reads a byte
|
||||
// stream in which a slice is a little-endian `u32` length followed by that many
|
||||
// bytes, so every entry below is length-prefixed. The three targets share one
|
||||
// `Smith` does not consume a corpus entry as raw parser input, so every entry
|
||||
// below goes through the `smith_encode.zig` encoders. The three targets share one
|
||||
// corpus: each starts with a slice, and the query target reads a second one that
|
||||
// falls back to empty when an entry carries only the first.
|
||||
|
||||
@@ -169,31 +171,6 @@ const deep_path = "/1/2/3/4/5/6/7/8/9";
|
||||
/// through, and a plus that means different things under the two rules.
|
||||
const bad_escapes = "/%2/%/%zz/a+b";
|
||||
|
||||
/// Encodes `bytes` as a single `Smith.slice` value.
|
||||
fn sliceInput(comptime bytes: []const u8) *const [4 + bytes.len]u8 {
|
||||
return &struct {
|
||||
const value: [4 + bytes.len]u8 = blk: {
|
||||
var buf: [4 + bytes.len]u8 = undefined;
|
||||
std.mem.writeInt(u32, buf[0..4], @intCast(bytes.len), .little);
|
||||
buf[4..].* = bytes[0..bytes.len].*;
|
||||
break :blk buf;
|
||||
};
|
||||
}.value;
|
||||
}
|
||||
|
||||
/// Encodes two `Smith.slice` values back to back, which is what the query target
|
||||
/// reads as its query string and its key.
|
||||
fn pairInput(comptime a: []const u8, comptime b: []const u8) *const [8 + a.len + b.len]u8 {
|
||||
return &struct {
|
||||
const value: [8 + a.len + b.len]u8 = blk: {
|
||||
var buf: [8 + a.len + b.len]u8 = undefined;
|
||||
buf[0 .. 4 + a.len].* = sliceInput(a).*;
|
||||
buf[4 + a.len ..].* = sliceInput(b).*;
|
||||
break :blk buf;
|
||||
};
|
||||
}.value;
|
||||
}
|
||||
|
||||
const corpus = [_][]const u8{
|
||||
sliceInput(api_path),
|
||||
sliceInput(encoded_slash),
|
||||
@@ -207,20 +184,3 @@ const corpus = [_][]const u8{
|
||||
pairInput("domain=" ++ "x" ** 1024, "domain"),
|
||||
pairInput("domain=%zz", "domain"),
|
||||
};
|
||||
|
||||
test "a corpus entry carries its own length" {
|
||||
const encoded = sliceInput(api_path);
|
||||
try std.testing.expectEqual(
|
||||
@as(u32, api_path.len),
|
||||
std.mem.readInt(u32, encoded[0..4], .little),
|
||||
);
|
||||
try std.testing.expectEqualSlices(u8, api_path, encoded[4..]);
|
||||
}
|
||||
|
||||
test "a paired corpus entry carries both lengths" {
|
||||
const encoded = pairInput("a=1", "a");
|
||||
try std.testing.expectEqual(@as(u32, 3), std.mem.readInt(u32, encoded[0..4], .little));
|
||||
try std.testing.expectEqualSlices(u8, "a=1", encoded[4..7]);
|
||||
try std.testing.expectEqual(@as(u32, 1), std.mem.readInt(u32, encoded[7..11], .little));
|
||||
try std.testing.expectEqualSlices(u8, "a", encoded[11..]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user