zig/doc/langref/test_null_terminated_slicing.zig

15 lines
336 B
Zig

const std = @import("std");
const expect = std.testing.expect;
test "0-terminated slicing" {
var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 };
var runtime_length: usize = 3;
_ = &runtime_length;
const slice = array[0..runtime_length :0];
try expect(@TypeOf(slice) == [:0]u8);
try expect(slice.len == 3);
}
// test