Skip to content

Commit

Permalink
organize testdata files
Browse files Browse the repository at this point in the history
Make little clanup.
Rename root to flate, prepare for making PR.
  • Loading branch information
ianic committed Feb 10, 2024
1 parent 1c0b729 commit 7ceae3f
Show file tree
Hide file tree
Showing 92 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn build(b: *std.Build) void {
.name = "deflate",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .path = "src/root.zig" },
.root_source_file = .{ .path = "src/flate.zig" },
.target = target,
.optimize = optimize,
});
Expand All @@ -32,7 +32,7 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const lib_unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/root.zig" },
.root_source_file = .{ .path = "src/flate.zig" },
.target = target,
.optimize = optimize,
});
Expand All @@ -43,7 +43,7 @@ pub fn build(b: *std.Build) void {
test_step.dependOn(&run_lib_unit_tests.step);

const flate_module = b.addModule("flate", .{
.root_source_file = .{ .path = "src/root.zig" },
.root_source_file = .{ .path = "src/flate.zig" },
});

const binaries = [_]Binary{
Expand Down
22 changes: 11 additions & 11 deletions src/block_writer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -586,26 +586,26 @@ const fmt = std.fmt;
const testing = std.testing;
const ArrayList = std.ArrayList;

const TestCase = @import("testdata/huffman_bit_writer.zig").TestCase;
const writeBlockTestCases = @import("testdata/huffman_bit_writer.zig").writeBlockTestCases;
const TestCase = @import("testdata/block_writer.zig").TestCase;
const testCases = @import("testdata/block_writer.zig").testCases;

// tests if the writeBlock encoding has changed.
test "writeBlock" {
inline for (0..writeBlockTestCases.len) |i| {
try testBlock(writeBlockTestCases[i], .write_block);
inline for (0..testCases.len) |i| {
try testBlock(testCases[i], .write_block);
}
}

// tests if the writeBlockDynamic encoding has changed.
test "writeBlockDynamic" {
inline for (0..writeBlockTestCases.len) |i| {
try testBlock(writeBlockTestCases[i], .write_dyn_block);
inline for (0..testCases.len) |i| {
try testBlock(testCases[i], .write_dyn_block);
}
}

test "writeBlockHuff" {
inline for (0..writeBlockTestCases.len) |i| {
try testBlock(writeBlockTestCases[i], .write_huffman_block);
inline for (0..testCases.len) |i| {
try testBlock(testCases[i], .write_huffman_block);
}
try testBlock(.{
.tokens = &[_]Token{},
Expand Down Expand Up @@ -661,8 +661,8 @@ const TestFn = enum {
fn testBlock(comptime tc: TestCase, comptime tfn: TestFn) !void {
if (tc.input.len != 0 and tc.want.len != 0) {
const want_name = comptime fmt.comptimePrint(tc.want, .{tfn.to_s()});
const input = @embedFile("testdata/" ++ tc.input);
const want = @embedFile("testdata/" ++ want_name);
const input = @embedFile("testdata/block_writer/" ++ tc.input);
const want = @embedFile("testdata/block_writer/" ++ want_name);
try testWriteBlock(tfn, input, want, tc.tokens);
}

Expand All @@ -671,7 +671,7 @@ fn testBlock(comptime tc: TestCase, comptime tfn: TestFn) !void {
}

const want_name_no_input = comptime fmt.comptimePrint(tc.want_no_input, .{tfn.to_s()});
const want = @embedFile("testdata/" ++ want_name_no_input);
const want = @embedFile("testdata/block_writer/" ++ want_name_no_input);
try testWriteBlock(tfn, null, want, tc.tokens);
}

Expand Down
10 changes: 5 additions & 5 deletions src/deflate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -609,23 +609,23 @@ test "deflate file tokenization" {
},

.{
.data = @embedFile("testdata/huffman-null-max.input"),
.data = @embedFile("testdata/block_writer/huffman-null-max.input"),
.tokens_count = .{ 257, 257, 257, 257, 257, 257 },
},
.{
.data = @embedFile("testdata/huffman-pi.input"),
.data = @embedFile("testdata/block_writer/huffman-pi.input"),
.tokens_count = .{ 2570, 2564, 2564, 2564, 2564, 2564 },
},
.{
.data = @embedFile("testdata/huffman-text.input"),
.data = @embedFile("testdata/block_writer/huffman-text.input"),
.tokens_count = .{ 235, 234, 234, 234, 234, 234 },
},
.{
.data = @embedFile("testdata/fuzzing/roundtrip1"),
.data = @embedFile("testdata/fuzz/roundtrip1"),
.tokens_count = .{ 333, 331, 331, 331, 331, 331 },
},
.{
.data = @embedFile("testdata/fuzzing/roundtrip2"),
.data = @embedFile("testdata/fuzz/roundtrip2"),
.tokens_count = .{ 334, 334, 334, 334, 334, 334 },
},
};
Expand Down
6 changes: 3 additions & 3 deletions src/root.zig → src/flate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,19 @@ test "compress/decompress" {
.store_size = 36967,
},
.{
.data = @embedFile("testdata/fuzzing/roundtrip1"),
.data = @embedFile("testdata/fuzz/roundtrip1"),
.gzip_sizes = [_]usize{ 373, 370, 370, 370, 370, 370 },
.huffman_only_size = 393,
.store_size = 393,
},
.{
.data = @embedFile("testdata/fuzzing/roundtrip2"),
.data = @embedFile("testdata/fuzz/roundtrip2"),
.gzip_sizes = [_]usize{ 373, 373, 373, 373, 373, 373 },
.huffman_only_size = 394,
.store_size = 394,
},
.{
.data = @embedFile("testdata/fuzzing/deflate-stream-out"),
.data = @embedFile("testdata/fuzz/deflate-stream-out"),
.gzip_sizes = [_]usize{ 351, 347, 347, 347, 347, 347 },
.huffman_only_size = 498,
.store_size = 747,
Expand Down
4 changes: 2 additions & 2 deletions src/inflate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ test "fuzzing tests" {
out: []const u8 = "",
err: ?anyerror = null,
}{
.{ .input = "deflate-stream", .out = @embedFile("testdata/fuzzing/deflate-stream-out") },
.{ .input = "deflate-stream", .out = @embedFile("testdata/fuzz/deflate-stream-out") },
.{ .input = "empty-distance-alphabet01" },
.{ .input = "empty-distance-alphabet02" },
.{ .input = "end-of-stream", .err = error.EndOfStream },
Expand Down Expand Up @@ -513,7 +513,7 @@ test "fuzzing tests" {
};

inline for (cases, 0..) |c, case_no| {
var in = std.io.fixedBufferStream(@embedFile("testdata/fuzzing/" ++ c.input));
var in = std.io.fixedBufferStream(@embedFile("testdata/fuzz/" ++ c.input));
var out = std.ArrayList(u8).init(testing.allocator);
defer out.deinit();
errdefer std.debug.print("test case failed {}\n", .{case_no});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub const TestCase = struct {
want_no_input: []const u8 = "", // File name of the expected output when no input is available.
};

pub const writeBlockTestCases = blk: {
pub const testCases = blk: {
@setEvalBranchQuota(4096 * 2);

const L = Token.initLiteral;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7ceae3f

Please sign in to comment.