I am not sure if there is already an issue for this. But I usually just switch expected with actual in the arguments. As you mentioned, reading the failing test output is then harder obviously.
this post was submitted on 08 Jul 2023
5 points (100.0% liked)
Ziglang
64 readers
1 users here now
founded 2 years ago
MODERATORS
Should work if "10" is also declared as a variable with type "i64" I think?
Sure, you could do:
const ten: i64 = 10;
try std.testing.expectEqual(ten, add(3, 7));
Is there a way to write an i64
literal?
If we look at the signature expectEqual(expected: anytype, actual: @TypeOf(expected)) !void
, notice that the second arg's type depends on the first arg's type.
To avoid using @as
coercion, we can just swap the passing arguments. comptime_int
can be inferred as i64
, not the other way around. And that makes sense because literal values are unsized.