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.
Zig › std/ › Io/ › Writer.zig › testSplatBytePreserve
testSplatBytePreserve
Writer.testSplatBytePreserve
fn testSplatBytePreserve (options : struct
File
Code
fn testSplatBytePreserve (options : struct { buf_len : u4 , fill_len : u4 , preserve : u4 , splat_len : u8 }) !void {
assert (options .fill_len <= options .buf_len );
assert (options .preserve <= options .buf_len );
const fill_buf = "abcdefghijklmno" ;
const fill = fill_buf [0 ..options .fill_len ];
var expected_out_buf : [256 ]u8 = @splat ('X' );
@memcpy (expected_out_buf [0 ..options .fill_len ], fill );
const expected_out = expected_out_buf [0 .. options .fill_len + options .splat_len ];
const expected_preserved = expected_out [expected_out .len -| options .preserve ..];
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 w .writeAll (fill );
try w .splatBytePreserve (options .preserve , 'X' , options .splat_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 .buffer [0 ..fw .end ]);
}