config: add background-opacity and float parsing for config

This commit is contained in:
Mitchell Hashimoto
2023-07-03 17:50:45 -07:00
parent 68b57f1001
commit 8756090266
2 changed files with 25 additions and 0 deletions

View File

@@ -144,6 +144,11 @@ fn parseIntoField(
0,
),
f64 => try std.fmt.parseFloat(
f64,
value orelse return error.ValueRequired,
),
else => unreachable,
};
@@ -298,6 +303,20 @@ test "parseIntoField: unsigned numbers" {
try testing.expectEqual(@as(u8, 1), data.u8);
}
test "parseIntoField: floats" {
const testing = std.testing;
var arena = ArenaAllocator.init(testing.allocator);
defer arena.deinit();
const alloc = arena.allocator();
var data: struct {
f64: f64,
} = undefined;
try parseIntoField(@TypeOf(data), alloc, &data, "f64", "1");
try testing.expectEqual(@as(f64, 1.0), data.f64);
}
test "parseIntoField: optional field" {
const testing = std.testing;
var arena = ArenaAllocator.init(testing.allocator);