~alva/zig-bare

0fccd0963c5bf8dc971912c192495842bcaa5a38 — Alva 2 months ago 9536ed4
Test non-slice pointers
2 files changed, 24 insertions(+), 1 deletions(-)

M src/bare.zig
M src/test.zig
M src/bare.zig => src/bare.zig +1 -1
@@ 312,7 312,7 @@ pub const Writer = struct {
        const ti = @typeInfo(@TypeOf(value)).Pointer;

        if (ti.size != .Slice)
            @compileError("unsupported type");
            @compileError("slices are the only supported pointer type");

        try self.writeVarUint(value.len, stream);


M src/test.zig => src/test.zig +23 -0
@@ 256,6 256,16 @@ test "read unsupported type" {
    );
}

test "read unsupported pointer type" {
    try testCompileError(
        \\pub fn main() void {
        \\  var fbs = io.fixedBufferStream("lol");
        \\  _ = try Reader.init(testing.allocator).read(*u8, fbs.inStream());
        \\}
        , "slices are the only supported pointer type"
    );
}

test "write variable uint" {
    var buf: [4]u8 = undefined;
    var fbs = io.fixedBufferStream(&buf);


@@ 512,6 522,19 @@ test "write unsupported type" {
    );
}

test "write unsupported pointer type" {
    try testCompileError(
        \\pub fn main() void {
        \\  var buf: [0x100]u8 = undefined;
        \\  var fbs = io.fixedBufferStream(&buf);
        \\  const x: u8 = 2;
        \\  const foo: *const u8 = &x;
        \\  try Writer.init().write(foo, fbs.outStream());
        \\}
        , "slices are the only supported pointer type"
    );
}

test "round trip variable uint" {
    var buf: [4]u8 = undefined;
    var fbs = io.fixedBufferStream(&buf);