Also, you may want to consider looking at functions in the standard library:
std.ascii.toLower
/// Lowercases the character and returns it as-is if already lowercase or not a letter.
pub fn toLower(c: u8) u8 {
const mask = @as(u8, @intFromBool(isUpper(c))) << 5;
return c | mask;
}
Good stuff - I’m going to mark your answer as the solution with a few comments.
if (deinit_status == .leak) std.testing.expect(false) catch @panic("TEST FAIL");
If you’re going to panic, then you can go straight for it:
if (deinit_status == .leak) @panic("TEST FAIL");
In general, I don’t recommend panic during testing. Unless you are testing something that is deeply memory intensive and you’re afraid that you’ll run out of system memory during the course of the test (or there’s some other danger in continuing), then you should just return the error:
try std.testing.expect(deinit_status != .leak);
Alternatively, you can use a more direct function here with std.testing.expectEqual.
Keep in mind that the memory your application is using is automatically freed after the application closes so the panic is unnecessary in most cases.
I’m also going to point out that during tests, you probably want to use the std.testing.allocator instead - it’s built exactly for what you’re trying to do here.