You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
std.Io.Reader.takeDelimiterExclusive() return error.StreamTooLong instead of error.EndOfStream #24950
Returned slice excludes the delimiter. End-of-stream is treated equivalent to a delimiter, unless it would result in a length 0 return value, in which case error.EndOfStream is returned instead.
changed the title [-]std.Io.Reader.takeDelimiterExclusive() return error.StreamTooLonginstead of error.EndOfStream[/-][+]std.Io.Reader.takeDelimiterExclusive() return error.StreamTooLong instead of error.EndOfStream[/+]on Aug 22, 2025
So here is a work around. I hope I have not done anything illegal.
lib/std/Io/Reader.zig
/// Constructs a `Reader` such that it will read from `buffer` and then end./// Its `takeDelimiterExclusive()` will return `error.EndOfStream`/// even if the last byte is not the delimiter.pubfnfixedZ(bufferZ: [:0]constu8) Reader {
varbuffer:[]constu8=bufferZ;
buffer.len+=1;
return .{
.vtable= &.{
.stream=endingStream,
.discard=endingDiscard,
.readVec=endingReadVec,
.rebase=endingRebase,
},
// This cast is safe because all potential writes to it will instead// return `error.EndOfStream`.
.buffer=@constCast(buffer),
.end=bufferZ.len,
.seek=0,
};
}
Now I can test my function against an empty input:
test {
varreader=std.Io.Reader.fixedZ("");
trystd.testing.expectError(
error.EndOfStream,
reader.takeDelimiterExclusive('\n'),
);
}
Activity
[-]std.Io.Reader.takeDelimiterExclusive() return error.StreamTooLonginstead of error.EndOfStream[/-][+]std.Io.Reader.takeDelimiterExclusive() return error.StreamTooLong instead of error.EndOfStream[/+]truly-not-taken commentedon Aug 22, 2025
truly-not-taken commentedon Aug 22, 2025
truly-not-taken commentedon Aug 23, 2025
The behavior of
std.Io.Reader.fixedis different from a file reader. This test does not fail while it is basically the same:But how do I do unit tests now? I need to test my function behavior against empty input.
truly-not-taken commentedon Aug 23, 2025
truly-not-taken commentedon Aug 23, 2025
This is ridiculous! It keeps gaslighting me about long streams while they are empty.
error: '1.test_0' failed: expected error.EndOfStream, found error.StreamTooLong
truly-not-taken commentedon Aug 23, 2025
So here is a work around. I hope I have not done anything illegal.
lib/std/Io/Reader.zig
Now I can test my function against an empty input:
docs, add broken tests when no delimiter
std.Io.Reader: fix delimiter bugs
std.Io.Reader: fix delimiter bugs
std.Io.Reader: fix delimiter bugs