| author | |
| committer | |
| log | 9dbbd77fe92435e810bf1da88ba964c1b6852823 |
| tree | 2a4e865f7f81f7e6041e0345443128b298c274fc |
| parent | 72d70b47cc7314371eb65c106a06b01f70b3abde |
6 files changed, 64 insertions(+), 5 deletions(-)
src/expectSimilarType.zig+14| ... | @@ -74,3 +74,17 @@ test { | ... | @@ -74,3 +74,17 @@ test { |
| 74 | struct { a: u32, b: u8, c: u16 }, | 74 | struct { a: u32, b: u8, c: u16 }, |
| 75 | ); | 75 | ); |
| 76 | } | 76 | } |
| 77 | |||
| 78 | test { | ||
| 79 | try expectSimilarType( | ||
| 80 | union(enum) { a: u32, b: u8, c: u16 }, | ||
| 81 | union(enum) { a: u32, b: u8, c: u16 }, | ||
| 82 | ); | ||
| 83 | } | ||
| 84 | |||
| 85 | test { | ||
| 86 | try expectSimilarType( | ||
| 87 | enum { a, b, c, d }, | ||
| 88 | enum { a, b, c, d }, | ||
| 89 | ); | ||
| 90 | } |
src/hashFile.zig-1| ... | @@ -2,7 +2,6 @@ const std = @import("std"); | ... | @@ -2,7 +2,6 @@ const std = @import("std"); |
| 2 | const string = []const u8; | 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); | 3 | const extras = @import("./lib.zig"); |
| 4 | const pipe = extras.pipe; | 4 | const pipe = extras.pipe; |
| 5 | const rawInt = extras.rawInt; | ||
| 6 | 5 | ||
| 7 | pub fn hashFile(dir: std.fs.Dir, sub_path: string, comptime Algo: type) ![Algo.digest_length * 2]u8 { | 6 | pub fn hashFile(dir: std.fs.Dir, sub_path: string, comptime Algo: type) ![Algo.digest_length * 2]u8 { |
| 8 | const file = try dir.openFile(sub_path, .{}); | 7 | const file = try dir.openFile(sub_path, .{}); |
src/joinPartial.zig+21| ... | @@ -1,6 +1,7 @@ | ... | @@ -1,6 +1,7 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const string = []const u8; | 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); | 3 | const extras = @import("./lib.zig"); |
| 4 | const Partial = extras.Partial; | ||
| 4 | 5 | ||
| 5 | pub fn joinPartial(comptime P: type, a: P, b: P) P { | 6 | pub fn joinPartial(comptime P: type, a: P, b: P) P { |
| 6 | var temp = a; | 7 | var temp = a; |
| ... | @@ -9,3 +10,23 @@ pub fn joinPartial(comptime P: type, a: P, b: P) P { | ... | @@ -9,3 +10,23 @@ pub fn joinPartial(comptime P: type, a: P, b: P) P { |
| 9 | } | 10 | } |
| 10 | return temp; | 11 | return temp; |
| 11 | } | 12 | } |
| 13 | |||
| 14 | test { | ||
| 15 | const S = struct { | ||
| 16 | a: u8 = 4, | ||
| 17 | b: u8 = 7, | ||
| 18 | c: u8 = 1, | ||
| 19 | }; | ||
| 20 | try std.testing.expect(std.meta.eql( | ||
| 21 | joinPartial( | ||
| 22 | Partial(S), | ||
| 23 | .{ .a = 5 }, | ||
| 24 | .{ .b = 9 }, | ||
| 25 | ), | ||
| 26 | .{ | ||
| 27 | .a = 5, | ||
| 28 | .b = 9, | ||
| 29 | .c = 1, | ||
| 30 | }, | ||
| 31 | )); | ||
| 32 | } |
src/readBytes.zig+14-2| ... | @@ -5,10 +5,22 @@ const assert = std.debug.assert; | ... | @@ -5,10 +5,22 @@ const assert = std.debug.assert; |
| 5 | 5 | ||
| 6 | pub fn readBytes(reader: anytype, comptime len: usize) ![len]u8 { | 6 | pub fn readBytes(reader: anytype, comptime len: usize) ![len]u8 { |
| 7 | var bytes: [len]u8 = undefined; | 7 | var bytes: [len]u8 = undefined; |
| 8 | assert(try reader.readAll(&bytes) == len); | 8 | if (try reader.readAll(&bytes) != len) return error.EndOfStream; |
| 9 | return bytes; | 9 | return bytes; |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | test { | 12 | test { |
| 13 | std.testing.refAllDecls(@This()); | 13 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; |
| 14 | var fba = std.io.fixedBufferStream(&array); | ||
| 15 | const reader = fba.reader(); | ||
| 16 | const res = try readBytes(reader, 2); | ||
| 17 | try std.testing.expect(res.len == 2); | ||
| 18 | try std.testing.expect(std.mem.eql(u8, &res, &.{ 9, 8 })); | ||
| 19 | } | ||
| 20 | |||
| 21 | test { | ||
| 22 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; | ||
| 23 | var fba = std.io.fixedBufferStream(&array); | ||
| 24 | const reader = fba.reader(); | ||
| 25 | try std.testing.expect(readBytes(reader, 13) == error.EndOfStream); | ||
| 14 | } | 26 | } |
src/readBytesAlloc.zig-1| ... | @@ -4,7 +4,6 @@ const extras = @import("./lib.zig"); | ... | @@ -4,7 +4,6 @@ const extras = @import("./lib.zig"); |
| 4 | 4 | ||
| 5 | pub fn readBytesAlloc(reader: anytype, alloc: std.mem.Allocator, len: usize) ![]u8 { | 5 | pub fn readBytesAlloc(reader: anytype, alloc: std.mem.Allocator, len: usize) ![]u8 { |
| 6 | var list = try std.ArrayListUnmanaged(u8).initCapacity(alloc, len); | 6 | var list = try std.ArrayListUnmanaged(u8).initCapacity(alloc, len); |
| 7 | try list.ensureTotalCapacityPrecise(alloc, len); | ||
| 8 | errdefer list.deinit(alloc); | 7 | errdefer list.deinit(alloc); |
| 9 | list.appendNTimesAssumeCapacity(0, len); | 8 | list.appendNTimesAssumeCapacity(0, len); |
| 10 | try reader.readNoEof(list.items[0..len]); | 9 | try reader.readNoEof(list.items[0..len]); |
src/readExpected.zig+15-1| ... | @@ -13,5 +13,19 @@ pub fn readExpected(reader: anytype, expected: []const u8) !bool { | ... | @@ -13,5 +13,19 @@ pub fn readExpected(reader: anytype, expected: []const u8) !bool { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | test { | 15 | test { |
| 16 | std.testing.refAllDecls(@This()); | 16 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; |
| 17 | var fba = std.io.fixedBufferStream(&array); | ||
| 18 | try std.testing.expect(try readExpected(fba.reader(), &.{ 9, 8, 7, 6 })); | ||
| 19 | } | ||
| 20 | |||
| 21 | test { | ||
| 22 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; | ||
| 23 | var fba = std.io.fixedBufferStream(&array); | ||
| 24 | try std.testing.expect(!try readExpected(fba.reader(), &.{ 1, 2, 3 })); | ||
| 25 | } | ||
| 26 | |||
| 27 | test { | ||
| 28 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; | ||
| 29 | var fba = std.io.fixedBufferStream(&array); | ||
| 30 | try std.testing.expect(try readExpected(fba.reader(), &.{})); | ||
| 17 | } | 31 | } |