-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfrom_buf_map.zig
39 lines (35 loc) · 1.37 KB
/
from_buf_map.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const zignite = @import("../zignite.zig");
const std = @import("std");
const BufMap = std.BufMap;
const BufMapHashMap = std.StringHashMap([]const u8);
const expect = std.testing.expect;
const FromIterable = @import("from_iterable.zig").FromIterable;
test "fromBufMap" {
const allocator = std.testing.allocator;
{
var buf_map = BufMap.init(allocator);
defer buf_map.deinit();
try buf_map.put("key1", "val1");
try buf_map.put("key2", "val2");
try buf_map.put("key3", "val3");
const a = try zignite.fromBufMap(&buf_map).toBoundedArray(10);
for (a.constSlice()) |entry| {
// random order
if (std.mem.eql(u8, entry.key_ptr.*, "key1")) {
try expect(std.mem.eql(u8, entry.value_ptr.*, "val1"));
} else if (std.mem.eql(u8, entry.key_ptr.*, "key2")) {
try expect(std.mem.eql(u8, entry.value_ptr.*, "val2"));
} else if (std.mem.eql(u8, entry.key_ptr.*, "key3")) {
try expect(std.mem.eql(u8, entry.value_ptr.*, "val3"));
} else {
unreachable;
}
}
}
{
var buf_map = BufMap.init(allocator);
defer buf_map.deinit();
try expect(zignite.fromBufMap(&buf_map).isEmpty());
}
}
pub const FromBufMap = FromIterable(*const BufMap, BufMapHashMap.Iterator, BufMapHashMap.Entry);