| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | const parse_int = extras.parse_int; |
| 5 | |
| 6 | pub fn parse_bool(s: ?string) bool { |
| 7 | return parse_int(u1, s, 10, 0) > 0; |
| 8 | } |
| 9 | |
| 10 | test { |
| 11 | try std.testing.expect(parse_bool("1")); |
| 12 | } |
| 13 | test { |
| 14 | try std.testing.expect(!parse_bool("0")); |
| 15 | } |
| 16 | test { |
| 17 | try std.testing.expect(!parse_bool("Q")); |
| 18 | } |
| 19 | test { |
| 20 | try std.testing.expect(!parse_bool("")); |
| 21 | } |
| 22 | test { |
| 23 | try std.testing.expect(!parse_bool(null)); |
| 24 | } |