~alva/zig-bare

3203eddba7a05bd6c02b38798a9db3da83561f71 — owl a year ago 220e1c3
add go-bare marshal union test
1 files changed, 28 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 +28 -0
@@ 210,3 210,31 @@ test "marshal map" {

    unreachable;
}

test "marshal union" {
    const NameAge = union(enum) {
        name: []const u8,
        age: isize,
    };

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

    {
        const val = NameAge{ .name = "Mary" };
        try e.encode(val);
        const reference = &[_]u8{ 0x00, 0x04, 0x4d, 0x61, 0x72, 0x79 };
        try testing.expectEqualSlices(u8, reference, fbs.getWritten());
    }

    fbs.reset();

    {
        const val = NameAge{ .age = 24 };
        try e.encode(val);
        const reference = &[_]u8{ 0x01, 0x30 };
        try testing.expectEqualSlices(u8, reference, fbs.getWritten());
    }
}