~alva/zig-bare

12f8ceb8b449e1a51d5ad3ce6de42c9e604f9e78 — owl 11 months ago 9ac4c79
add go-bare marshal optional test
1 files changed, 23 insertions(+), 0 deletions(-)

M src/interop/go-bare/marshal_test.zig
M src/interop/go-bare/marshal_test.zig => src/interop/go-bare/marshal_test.zig +23 -0
@@ 60,3 60,26 @@ test "marshal value" {
        try expectEqualSlices(u8, tuple[0], fbs.getWritten());
    }
}

test "marshal optional" {
    {
        var buf: [0x1_000]u8 = undefined;
        var fbs = io.fixedBufferStream(&buf);
        const writer = fbs.writer();
        var e = encoder(writer);

        const val: ?u32 = null;
        try e.encode(val);
        try expectEqualSlices(u8, &[_]u8{0x00}, fbs.getWritten());
    }
    {
        var buf: [0x1_000]u8 = undefined;
        var fbs = io.fixedBufferStream(&buf);
        const writer = fbs.writer();
        var e = encoder(writer);
        const val: ?u32 = 0xDEADBEEF;

        try e.encode(val);
        try testing.expectEqualSlices(u8, &[_]u8{ 0x01, 0xEF, 0xBE, 0xAD, 0xDE }, fbs.getWritten());
    }
}