Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Private Function

testStreamExactPreserve

Private Function
std.Io.Reader.testStreamExactPreserve
fn testStreamExactPreserve(options: struct

Params

  • options: struct { buf_len: u4, fill_len: u4, preserve: u4, stream_len: u8 }

File

Io/Reader.zig:2323
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
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());
}