#How to assert the value of a tagged union in a test?
1 messages · Page 1 of 1 (latest)
1 messages · Page 1 of 1 (latest)
const actions: []Action = ...
try std.testing.expectEqual(1, actions.len);
switch (actions[0]) {
.KeyCodePress => |keycode| try std.testing.expectEqual(keycode, b),
else => unreachable,
}
is this the best way to test the value of the tagged enum at position 0 in actions?
I believe you can just do actions[0].KeyCodePress to get the keycode value
I haven't used unions much...
wow, that just very nice! and very good error messages both when enum type is mismatch and when value is mismatched. Thanks!