~alva/zig-bare

1a435243ce0e04de99a9ac50b99c32b8c74013e9 — Jonathan Halmen 6 months ago 994bca3
Fix for union error message change and `HashMap` API changes

Signed-off-by: ugla <ugla@u8.is>
2 files changed, 7 insertions(+), 10 deletions(-)

M src/bare.zig
M src/test.zig
M src/bare.zig => src/bare.zig +1 -1
@@ 385,7 385,7 @@ fn isHashMap(comptime T: type) bool {
            // `HashMapKeyType` and `HashMapValueType` add further constraints.
            const has1 = @hasDecl(T, "iterator");
            const has2 = @hasDecl(T, "putAssumeCapacity");
            const has3 = @hasDecl(T, "ensureCapacity");
            const has3 = @hasDecl(T, "ensureUnusedCapacity");
            const has4 = @hasDecl(T, "Size");
            return has1 and has2 and has3 and has4;
        },

M src/test.zig => src/test.zig +6 -9
@@ 489,8 489,8 @@ test "write map[u8]u8" {
    var fbs = io.fixedBufferStream(&buf);

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

    defer map.deinit();

    _ = try map.put(1, 2);
    _ = try map.put(3, 4);



@@ 506,8 506,8 @@ test "write map[string]u8" {
    var fbs = io.fixedBufferStream(&buf);

    var map = std.StringHashMap(u8).init(testing.allocator);

    defer map.deinit();

    _ = try map.put("lol", 2);
    _ = try map.put("zomg", 4);



@@ 801,30 801,28 @@ test "invariant: structs must have at least 1 field (write)" {
}

test "invariant: unions must have at least 1 field (read)" {
    if (true) return;
    try testCompileError(
        \\pub fn main() !void {
        \\  const Foo = union(enum) {};
        \\  var fbs = io.fixedBufferStream("lol");
        \\  var gpa = std.heap.GeneralPurposeAllocator(.{}){};
        \\  var d = Decoder.init(gpa.allocator());
        \\  _ = try d.decode(Foo, fbs.reader());
        \\  _ = try d.decode(Foo{}, fbs.reader());
        \\}
    , "union declarations must have at least one tag");
    , "union initializer must initialize one field");
}

test "invariant: unions must have at least 1 field (write)" {
    if (true) return;
    try testCompileError(
        \\pub fn main() !void {
        \\  const Foo = union(enum) {};
        \\  var buf: [0x100]u8 = undefined;
        \\  var fbs = io.fixedBufferStream(&buf);
        \\  var e = Encoder.init();
        \\  const foo: Foo = .{};
        \\  const foo = Foo{};
        \\  _ = try e.encode(foo, fbs.writer());
        \\}
    , "union declarations must have at least one tag");
    , "union initializer must initialize one field");
}

test "invariant: hashmap keys must be of primitive type" {


@@ 841,7 839,6 @@ test "invariant: hashmap keys must be of primitive type" {
}

test "invariant: enum values must be unique" {
    if (true) return;
    try testCompileError(
        \\pub fn main() !void {
        \\  const Foo = enum(u8) {