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 › init/ › src/ › main.zig › testOne
testOne
main.testOne
fn testOne (context : void , smith : *std .testing .Smith ) !void
File
Code
fn testOne (context : void , smith : *std .testing .Smith ) !void {
_ = context ;
const gpa = std .testing .allocator ;
var list : std .ArrayList (u8 ) = .empty ;
defer list .deinit (gpa );
while (!smith .eos ()) switch (smith .value (enum { add_data , dup_data })) {
.add_data => {
const slice = try list .addManyAsSlice (gpa , smith .value (u4 ));
smith .bytes (slice );
},
.dup_data => {
if (list .items .len == 0 ) continue ;
if (list .items .len > std .math .maxInt (u32 )) return error .SkipZigTest ;
const len = smith .valueRangeAtMost (u32 , 1 , @min (32 , list .items .len ));
const off = smith .valueRangeAtMost (u32 , 0 , @intCast (list .items .len - len ));
try list .appendSlice (gpa , list .items [off ..][0 ..len ]);
try std .testing .expectEqualSlices (
u8 ,
list .items [off ..][0 ..len ],
list .items [list .items .len - len ..],
);
},
};
}