~alva/zig-bare

661dd701bfd6e34300ecbf0c2ff383d0c45787cc — Alva 4 months ago 3195d1a 0.3.0
Test `map[u8]void`
1 files changed, 30 insertions(+), 0 deletions(-)

M src/test.zig
M src/test.zig => src/test.zig +30 -0
@@ 197,6 197,19 @@ test "read map[string]u8" {
    expectEqual((map.get("zomg") orelse unreachable).value, 4);
}

test "read map[u8]void" {
    var r = Reader.init(testing.allocator);
    defer r.deinit();
    const T = std.AutoHashMap(u8, void);
    const map = try r.read(T,
        io.fixedBufferStream("\x02\x01\x02").inStream());
    expectEqual(map.size, 2);
    expectEqual((map.get(1) orelse unreachable).key, 1);
    expectEqual((map.get(2) orelse unreachable).key, 2);
    expectEqual((map.get(1) orelse unreachable).value, {});
    expectEqual((map.get(2) orelse unreachable).value, {});
}

test "read tagged union" {
    const Foo = union(enum) { a: i64, b: bool, c: u8 };
    const res = try Reader.init(testing.allocator).read(Foo,


@@ 351,6 364,23 @@ test "write map[string]u8" {
    expectEqualSlices(u8, fbs.getWritten(), expected[0..]);
}

test "write map[u8]void" {
    var buf: [100]u8 = undefined;
    var fbs = io.fixedBufferStream(&buf);

    var map = std.AutoHashMap(u8, void).init(testing.allocator);

    defer map.deinit();
    _ = try map.put(1, {});
    _ = try map.put(42, {});

    try Writer.init().write(map, fbs.outStream());
    // TODO: Fix this; later versions of std.HashMap preserve insertion order.
    const expected = "\x02\x2a\x01";
    expectEqual(fbs.getWritten().len, 3);
    expectEqualSlices(u8, fbs.getWritten(), expected[0..]);
}

test "write tagged union" {
    var buf: [10]u8 = undefined;
    var fbs = io.fixedBufferStream(&buf);