1
Fork 0

less error handling

This commit is contained in:
Motiejus Jakštys 2022-02-10 06:11:25 +02:00 committed by Motiejus Jakštys
parent 88d2a0f470
commit 1e084cc3fb
1 changed files with 3 additions and 28 deletions

View File

@ -14,10 +14,8 @@ pub fn main() !void {}
test "simple cmph usage" {
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const arena = arena_instance.allocator();
const stdout = std.io.getStdOut().writer();
const stderr = std.io.getStdErr().writer();
_ = stdout;
var vector = std.ArrayList([*:0]const u8).init(arena);
try vector.appendSlice(&.{
"aaaaaaaaaa",
@ -31,11 +29,10 @@ test "simple cmph usage" {
"iiiiiiiiii",
"jjjjjjjjjj",
});
var vector2 = try vector.clone();
var nkeys = @truncate(c_uint, vector.items.len);
var mphf_fd = c.fopen(tempMph, "w");
var cvector = @ptrCast([*c][*c]u8, vector.toOwnedSlice().ptr);
var cvector = @ptrCast([*c][*c]u8, vector.items.ptr);
var source = c.cmph_io_vector_adapter(cvector, nkeys);
defer c.cmph_io_vector_adapter_destroy(source);
var config: *c.cmph_config_t = c.cmph_config_new(source) orelse return error.OutOfMemory;
@ -50,16 +47,11 @@ test "simple cmph usage" {
mphf_fd = c.fopen(tempMph, "r");
defer _ = c.fclose(mphf_fd);
var got_hash: ?*c.cmph_t = c.cmph_load(mphf_fd);
if (got_hash) |real_hash| {
hash = real_hash;
} else {
try stderr.print("failed to unwrap hash\n", .{});
}
hash = c.cmph_load(mphf_fd) orelse unreachable;
defer c.cmph_destroy(hash);
try stderr.print("\n", .{});
for (vector2.items) |key| {
for (vector.items) |key| {
var id = c.cmph_search(hash, key, @truncate(c_uint, c.strlen(key)));
try stderr.print("key: {s}, id: {d}\n", .{ key, id });
}
@ -71,20 +63,3 @@ fn closeCFile(f: *c.FILE) !void {
return std.os.unexpectedErrno(std.os.errno(close_code));
}
}
const expectEqual = std.testing.expectEqual;
test "char**" {
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const arena = arena_instance.allocator();
var arrl = std.ArrayList([*:0]const u8).init(arena);
try arrl.append("foo");
try arrl.append("bar");
var arr: [*][*:0]const u8 = arrl.toOwnedSlice().ptr;
try expectEqual(@TypeOf(arr[0]), [*:0]const u8);
try expectEqual(arr[0][2], 'o');
try expectEqual(arr[0][3], 0);
}