diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-09-03 10:05:44 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-09-03 10:05:44 +0800 |
| commit | fb0a9f51c3c719ceda3ada03fa2171b4dc26ea69 (patch) | |
| tree | 3f6f7f39365cbceae455b90fe79b8db327fb5e64 /test.zig | |
| parent | 59df8df7e7b1deeb14f79a1bfb2985f8ce3a13cd (diff) | |
updated
Diffstat (limited to 'test.zig')
| -rw-r--r-- | test.zig | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test.zig b/test.zig new file mode 100644 index 0000000..d59ea17 --- /dev/null +++ b/test.zig @@ -0,0 +1,25 @@ +const std = @import("std"); +const parseInt = std.fmt.parseInt; + +test "parse integers" { + const input = "123 67 89,99"; + const ally = std.testing.allocator; + + var list = std.ArrayList(u32).init(ally); + // Ensure the list is freed at scope exit. + // Try commenting out this line! + defer list.deinit(); + + var it = std.mem.tokenize(u8, input, " ,"); + while (it.next()) |num| { + const n = try parseInt(u32, num, 10); + try list.append(n); + } + + const expected = [_]u32{ 123, 67, 89, 99 }; + + for (expected, list.items) |exp, actual| { + try std.testing.expectEqual(exp, actual); + } +} + |
