So I have this test which fails:
const example = // this is some ini file format
\\ [core]
\\ repositoryformatversion = 0
\\ filemode = true
\\ bare = false
\\ logallrefupdates = true
var fbs = std.io.fixedBufferStream(example);
var parser = parse(std.testing.allocator, fbs.reader());
defer parser.deinit();
const result = try readToStruct(MyStructType, &parser);
try expect(my_struct.some_field.filemode == true); // this fails
In order to parse the example, the code goes through an inline for loop. The loop iterates the fields of the type, and calls a convert function on the key-value pairs:
const truthyAndFalsy = std.ComptimeStringMap(bool, .{ .{ "true", true }, .{ "false", false }});
pub fn convert(comptime T: type, val: []const u8) !T {
return switch (@typeInfo(T)) {
.Bool => truthyAndFalsy.get(val).?,
else => @as(T, val),
};
}
// mid inline loop:
@field(innerStruct, field_name) = try convert(my_type, value);
Aaand I can't figure out why the conversion doesn't actually happen.
- Is there something glaringly wrong about this code?
- How can I print to console during tests? I tried
std.log.warn("\n{any}\n".{myval})but nothing comes out. The debugger's also not really helping