diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-02-14 09:40:08 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-14 09:40:08 -0500 |
| commit | 40b9db7cad6f876bb3e8fa32d7b32bbd4bc983ea (patch) | |
| tree | ac84f7fcca0d11becb7d459c151782202f3e01c0 /lib/std/mem.zig | |
| parent | 9206f8a8cde9a8c1eafc606fe6b3f4129e233aef (diff) | |
| parent | 6ea6d5a4bdcf6f37c43857570522ee1308115de7 (diff) | |
| download | zig-40b9db7cad6f876bb3e8fa32d7b32bbd4bc983ea.tar.gz zig-40b9db7cad6f876bb3e8fa32d7b32bbd4bc983ea.zip | |
Merge pull request #4451 from daurnimator/use-testing.allocator
Migrate (more) tests from FixedBufferAllocator to testing.allocator
Diffstat (limited to 'lib/std/mem.zig')
| -rw-r--r-- | lib/std/mem.zig | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/lib/std/mem.zig b/lib/std/mem.zig index 8f4987e0c9..a1b4a3c809 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -1011,11 +1011,21 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons } test "mem.join" { - var buf: [1024]u8 = undefined; - const a = &std.heap.FixedBufferAllocator.init(&buf).allocator; - testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "b", "c" }), "a,b,c")); - testing.expect(eql(u8, try join(a, ",", &[_][]const u8{"a"}), "a")); - testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c")); + { + const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" }); + defer testing.allocator.free(str); + testing.expect(eql(u8, str, "a,b,c")); + } + { + const str = try join(testing.allocator, ",", &[_][]const u8{"a"}); + defer testing.allocator.free(str); + testing.expect(eql(u8, str, "a")); + } + { + const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" }); + defer testing.allocator.free(str); + testing.expect(eql(u8, str, "a,,b,,c")); + } } /// Copies each T from slices into a new slice that exactly holds all the elements. @@ -1044,15 +1054,21 @@ pub fn concat(allocator: *Allocator, comptime T: type, slices: []const []const T } test "concat" { - var buf: [1024]u8 = undefined; - const a = &std.heap.FixedBufferAllocator.init(&buf).allocator; - testing.expect(eql(u8, try concat(a, u8, &[_][]const u8{ "abc", "def", "ghi" }), "abcdefghi")); - testing.expect(eql(u32, try concat(a, u32, &[_][]const u32{ - &[_]u32{ 0, 1 }, - &[_]u32{ 2, 3, 4 }, - &[_]u32{}, - &[_]u32{5}, - }), &[_]u32{ 0, 1, 2, 3, 4, 5 })); + { + const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" }); + defer testing.allocator.free(str); + testing.expect(eql(u8, str, "abcdefghi")); + } + { + const str = try concat(testing.allocator, u32, &[_][]const u32{ + &[_]u32{ 0, 1 }, + &[_]u32{ 2, 3, 4 }, + &[_]u32{}, + &[_]u32{5}, + }); + defer testing.allocator.free(str); + testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 })); + } } test "testStringEquality" { |
