fix split_rev
This commit is contained in:
parent
0865965762
commit
3872f2af40
@ -61,13 +61,13 @@ pub fn wrapf(self: *ErrCtx, comptime format: []const u8, args: anytype) *ErrCtx
|
||||
|
||||
pub fn iterator(self: *const ErrCtx) mem.SplitIterator(u8) {
|
||||
const slice = self.buf.constSlice();
|
||||
const last_byte = if (slice[slice.len - 1] == '0') slice.len - 1 else slice.len;
|
||||
const last_byte = if (slice[slice.len - 1] == 0) slice.len - 1 else slice.len;
|
||||
return mem.split(u8, slice[0..last_byte], "\x00");
|
||||
}
|
||||
|
||||
pub fn rev(self: *const ErrCtx) SplitIteratorRev(u8) {
|
||||
const slice = self.buf.constSlice();
|
||||
const last_byte = if (slice[slice.len - 1] == '0') slice.len - 1 else slice.len;
|
||||
const last_byte = if (slice[slice.len - 1] == 0) (slice.len - 1) else slice.len;
|
||||
return splitRev(u8, slice[0..last_byte], "\x00");
|
||||
}
|
||||
|
||||
@ -101,17 +101,26 @@ test "almost overflow" {
|
||||
var ctx = ErrCtx{};
|
||||
var wr = ctx.writer();
|
||||
|
||||
try wr.writeAll("0" ** (capacity - 2));
|
||||
try wr.writeAll("0" ** (capacity - 3));
|
||||
try wr.writeAll("11");
|
||||
|
||||
var it = ctx.iterator();
|
||||
try testing.expectEqualSlices(u8, it.next().?, "0" ** (capacity - 2));
|
||||
try testing.expectEqualSlices(u8, it.next().?, "1");
|
||||
try testing.expectEqualSlices(u8, it.next().?, "0" ** (capacity - 3));
|
||||
try testing.expectEqualSlices(u8, it.next().?, "11");
|
||||
try testing.expectEqual(it.next(), null);
|
||||
|
||||
var it_rev = ctx.rev();
|
||||
try testing.expectEqualSlices(u8, it_rev.next().?, "1");
|
||||
try testing.expectEqualSlices(u8, it_rev.next().?, "0" ** (capacity - 2));
|
||||
try testing.expectEqualSlices(u8, it_rev.next().?, "11");
|
||||
try testing.expectEqualSlices(u8, it_rev.next().?, "0" ** (capacity - 3));
|
||||
try testing.expectEqual(it.next(), null);
|
||||
}
|
||||
|
||||
test "rev" {
|
||||
var ctx = ErrCtx{};
|
||||
ctx.print("yadda", .{});
|
||||
|
||||
var it = ctx.rev();
|
||||
try testing.expectEqualSlices(u8, "yadda", it.next().?);
|
||||
try testing.expectEqual(it.next(), null);
|
||||
}
|
||||
|
||||
|
@ -151,13 +151,11 @@ test "trivial error: missing passwd file" {
|
||||
|
||||
const exit_code = execute(allocator, stdout.writer(), stderr.writer(), args[0..]);
|
||||
try testing.expectEqual(@as(u8, 1), exit_code);
|
||||
std.debug.print("stderr: '{s}'\n", .{stderr.items});
|
||||
if (true) return error.SkipZigTest;
|
||||
try testing.expect(mem.startsWith(
|
||||
try testing.expectEqualSlices(
|
||||
u8,
|
||||
stderr.items,
|
||||
"ERROR: FileNotFound: fubar",
|
||||
));
|
||||
"ERROR FileNotFound: ./passwd: open \n",
|
||||
);
|
||||
}
|
||||
|
||||
test "fail" {
|
||||
@ -167,7 +165,11 @@ test "fail" {
|
||||
var stderrw = stderr.writer();
|
||||
const exit_code = fail(errc.wrapf("got 1", .{}), stderrw, error.NotSure);
|
||||
try testing.expectEqual(exit_code, 1);
|
||||
std.debug.print("stderr: '{s}'\n", .{stderr.items});
|
||||
try testing.expectEqualSlices(
|
||||
u8,
|
||||
stderr.items,
|
||||
"ERROR NotSure: got 1\n",
|
||||
);
|
||||
}
|
||||
|
||||
test "smoke test" {
|
||||
|
Loading…
Reference in New Issue
Block a user