aboutsummaryrefslogtreecommitdiff
path: root/lib/std/mem.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-02-14 09:40:08 -0500
committerGitHub <noreply@github.com>2020-02-14 09:40:08 -0500
commit40b9db7cad6f876bb3e8fa32d7b32bbd4bc983ea (patch)
treeac84f7fcca0d11becb7d459c151782202f3e01c0 /lib/std/mem.zig
parent9206f8a8cde9a8c1eafc606fe6b3f4129e233aef (diff)
parent6ea6d5a4bdcf6f37c43857570522ee1308115de7 (diff)
downloadzig-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.zig44
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" {