Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

testStreamExactPreserve

Reader.testStreamExactPreserve
fn testStreamExactPreserve(options: struct

File

lib/std/Io/Reader.zig:2324

Code

fn testStreamExactPreserve(options: struct { buf_len: u4, fill_len: u4, preserve: u4, stream_len: u8 }) !void {
    assert(options.fill_len <= options.buf_len);
    assert(options.preserve <= options.buf_len);

    var input: [256]u8 = undefined;
    for (&input, 0..) |*val, i| {
        val.* = @as(u8, @intCast(i % 26)) + 'a';
    }
    const expected_out = input[0 .. options.fill_len + options.stream_len];
    const expected_preserved = expected_out[expected_out.len -| options.preserve..];

    var r: Reader = .fixed(&input);
    var out_buf: [256]u8 = undefined;
    var fw: Writer = .fixed(&out_buf);
    var indirect_buffer: [16]u8 = undefined;
    var twi: std.testing.WriterIndirect = .init(&fw, indirect_buffer[0..options.buf_len]);
    const w = &twi.interface;

    try r.streamExact(w, options.fill_len);
    try r.streamExactPreserve(w, options.preserve, options.stream_len);

    try std.testing.expectEqualStrings(expected_preserved, w.buffer[w.end -| options.preserve..w.end]);

    try w.flush();

    try std.testing.expectEqualStrings(expected_out, fw.buffered());
}