| author | |
| committer | |
| log | 28ac9f8b704951010a49e33f405c4265bf3077d2 |
| tree | 78f95298d4f743845b8eff8c1b07d7aa35aa80ce |
| parent | 731fd217db4caa6809d153f792157c03179b9b9d |
| parent | 6bd54a1d3ebd8d997158c57057ba742824cf7e0c |
| signature |
std.MultiArrayList: add test coverage for 0-bit structs5 files changed, 82 insertions(+), 3 deletions(-)
lib/std/array_hash_map.zig+29| ... | @@ -2336,6 +2336,35 @@ test "sort" { | ... | @@ -2336,6 +2336,35 @@ test "sort" { |
| 2336 | } | 2336 | } |
| 2337 | } | 2337 | } |
| 2338 | 2338 | ||
| 2339 | test "0 sized key" { | ||
| 2340 | var map = AutoArrayHashMap(u0, i32).init(std.testing.allocator); | ||
| 2341 | defer map.deinit(); | ||
| 2342 | |||
| 2343 | try testing.expectEqual(map.get(0), null); | ||
| 2344 | |||
| 2345 | try map.put(0, 5); | ||
| 2346 | try testing.expectEqual(map.get(0), 5); | ||
| 2347 | |||
| 2348 | try map.put(0, 10); | ||
| 2349 | try testing.expectEqual(map.get(0), 10); | ||
| 2350 | |||
| 2351 | try testing.expectEqual(map.swapRemove(0), true); | ||
| 2352 | try testing.expectEqual(map.get(0), null); | ||
| 2353 | } | ||
| 2354 | |||
| 2355 | test "0 sized key and 0 sized value" { | ||
| 2356 | var map = AutoArrayHashMap(u0, u0).init(std.testing.allocator); | ||
| 2357 | defer map.deinit(); | ||
| 2358 | |||
| 2359 | try testing.expectEqual(map.get(0), null); | ||
| 2360 | |||
| 2361 | try map.put(0, 0); | ||
| 2362 | try testing.expectEqual(map.get(0), 0); | ||
| 2363 | |||
| 2364 | try testing.expectEqual(map.swapRemove(0), true); | ||
| 2365 | try testing.expectEqual(map.get(0), null); | ||
| 2366 | } | ||
| 2367 | |||
| 2339 | pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) { | 2368 | pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) { |
| 2340 | return struct { | 2369 | return struct { |
| 2341 | fn hash(ctx: Context, key: K) u32 { | 2370 | fn hash(ctx: Context, key: K) u32 { |
lib/std/multi_array_list.zig+49| ... | @@ -901,3 +901,52 @@ test "sorting a span" { | ... | @@ -901,3 +901,52 @@ test "sorting a span" { |
| 901 | c += 1; | 901 | c += 1; |
| 902 | } | 902 | } |
| 903 | } | 903 | } |
| 904 | |||
| 905 | test "0 sized struct field" { | ||
| 906 | const ally = testing.allocator; | ||
| 907 | |||
| 908 | const Foo = struct { | ||
| 909 | a: u0, | ||
| 910 | b: f32, | ||
| 911 | }; | ||
| 912 | |||
| 913 | var list = MultiArrayList(Foo){}; | ||
| 914 | defer list.deinit(ally); | ||
| 915 | |||
| 916 | try testing.expectEqualSlices(u0, &[_]u0{}, list.items(.a)); | ||
| 917 | try testing.expectEqualSlices(f32, &[_]f32{}, list.items(.b)); | ||
| 918 | |||
| 919 | try list.append(ally, .{ .a = 0, .b = 42.0 }); | ||
| 920 | try testing.expectEqualSlices(u0, &[_]u0{0}, list.items(.a)); | ||
| 921 | try testing.expectEqualSlices(f32, &[_]f32{42.0}, list.items(.b)); | ||
| 922 | |||
| 923 | try list.insert(ally, 0, .{ .a = 0, .b = -1.0 }); | ||
| 924 | try testing.expectEqualSlices(u0, &[_]u0{ 0, 0 }, list.items(.a)); | ||
| 925 | try testing.expectEqualSlices(f32, &[_]f32{ -1.0, 42.0 }, list.items(.b)); | ||
| 926 | |||
| 927 | list.swapRemove(list.len - 1); | ||
| 928 | try testing.expectEqualSlices(u0, &[_]u0{0}, list.items(.a)); | ||
| 929 | try testing.expectEqualSlices(f32, &[_]f32{-1.0}, list.items(.b)); | ||
| 930 | } | ||
| 931 | |||
| 932 | test "0 sized struct" { | ||
| 933 | const ally = testing.allocator; | ||
| 934 | |||
| 935 | const Foo = struct { | ||
| 936 | a: u0, | ||
| 937 | }; | ||
| 938 | |||
| 939 | var list = MultiArrayList(Foo){}; | ||
| 940 | defer list.deinit(ally); | ||
| 941 | |||
| 942 | try testing.expectEqualSlices(u0, &[_]u0{}, list.items(.a)); | ||
| 943 | |||
| 944 | try list.append(ally, .{ .a = 0 }); | ||
| 945 | try testing.expectEqualSlices(u0, &[_]u0{0}, list.items(.a)); | ||
| 946 | |||
| 947 | try list.insert(ally, 0, .{ .a = 0 }); | ||
| 948 | try testing.expectEqualSlices(u0, &[_]u0{ 0, 0 }, list.items(.a)); | ||
| 949 | |||
| 950 | list.swapRemove(list.len - 1); | ||
| 951 | try testing.expectEqualSlices(u0, &[_]u0{0}, list.items(.a)); | ||
| 952 | } |
src/InternPool.zig+1-3| ... | @@ -54,9 +54,7 @@ string_table: std.HashMapUnmanaged( | ... | @@ -54,9 +54,7 @@ string_table: std.HashMapUnmanaged( |
| 54 | std.hash_map.default_max_load_percentage, | 54 | std.hash_map.default_max_load_percentage, |
| 55 | ) = .{}, | 55 | ) = .{}, |
| 56 | 56 | ||
| 57 | /// TODO: after https://github.com/ziglang/zig/issues/10618 is solved, | 57 | const FieldMap = std.ArrayHashMapUnmanaged(void, void, std.array_hash_map.AutoContext(void), false); |
| 58 | /// change store_hash to false. | ||
| 59 | const FieldMap = std.ArrayHashMapUnmanaged(void, void, std.array_hash_map.AutoContext(void), true); | ||
| 60 | 58 | ||
| 61 | const builtin = @import("builtin"); | 59 | const builtin = @import("builtin"); |
| 62 | const std = @import("std"); | 60 | const std = @import("std"); |
stage1/zig.h+3| ... | @@ -190,10 +190,13 @@ typedef char bool; | ... | @@ -190,10 +190,13 @@ typedef char bool; |
| 190 | 190 | ||
| 191 | #if zig_has_attribute(weak) || defined(zig_gnuc) | 191 | #if zig_has_attribute(weak) || defined(zig_gnuc) |
| 192 | #define zig_weak_linkage __attribute__((weak)) | 192 | #define zig_weak_linkage __attribute__((weak)) |
| 193 | #define zig_weak_linkage_fn __attribute__((weak)) | ||
| 193 | #elif _MSC_VER | 194 | #elif _MSC_VER |
| 194 | #define zig_weak_linkage __declspec(selectany) | 195 | #define zig_weak_linkage __declspec(selectany) |
| 196 | #define zig_weak_linkage_fn | ||
| 195 | #else | 197 | #else |
| 196 | #define zig_weak_linkage zig_weak_linkage_unavailable | 198 | #define zig_weak_linkage zig_weak_linkage_unavailable |
| 199 | #define zig_weak_linkage_fn zig_weak_linkage_unavailable | ||
| 197 | #endif | 200 | #endif |
| 198 | 201 | ||
| 199 | #if zig_has_builtin(trap) | 202 | #if zig_has_builtin(trap) |
stage1/zig1.wasm| Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ | |||