aboutsummaryrefslogtreecommitdiff
path: root/std/io_test.zig
diff options
context:
space:
mode:
authortgschultz <tgschultz@gmail.com>2018-05-11 21:36:02 -0500
committerGitHub <noreply@github.com>2018-05-11 21:36:02 -0500
commit8c1872543c8cf76215cc4bf3ced4637bb1065a4e (patch)
tree72dfebb643ab61579e3fb8dd58cd4610ffe876fa /std/io_test.zig
parent7186e92c86982950d0aa7c0c2deef9ef96bc1264 (diff)
parent6e821078f625a03eb8b7794c983da0f7793366ab (diff)
downloadzig-8c1872543c8cf76215cc4bf3ced4637bb1065a4e.tar.gz
zig-8c1872543c8cf76215cc4bf3ced4637bb1065a4e.zip
Merge pull request #1 from zig-lang/master
Sync with zig-lang/zig master
Diffstat (limited to 'std/io_test.zig')
-rw-r--r--std/io_test.zig18
1 files changed, 17 insertions, 1 deletions
diff --git a/std/io_test.zig b/std/io_test.zig
index 89959b7b54..5f53556785 100644
--- a/std/io_test.zig
+++ b/std/io_test.zig
@@ -1,6 +1,5 @@
const std = @import("index.zig");
const io = std.io;
-const allocator = std.debug.global_allocator;
const DefaultPrng = std.rand.DefaultPrng;
const assert = std.debug.assert;
const mem = std.mem;
@@ -8,6 +7,9 @@ const os = std.os;
const builtin = @import("builtin");
test "write a file, read it, then delete it" {
+ var raw_bytes: [200 * 1024]u8 = undefined;
+ var allocator = &std.heap.FixedBufferAllocator.init(raw_bytes[0..]).allocator;
+
var data: [1024]u8 = undefined;
var prng = DefaultPrng.init(1234);
prng.random.bytes(data[0..]);
@@ -44,3 +46,17 @@ test "write a file, read it, then delete it" {
}
try os.deleteFile(allocator, tmp_file_name);
}
+
+test "BufferOutStream" {
+ var bytes: [100]u8 = undefined;
+ var allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
+
+ var buffer = try std.Buffer.initSize(allocator, 0);
+ var buf_stream = &std.io.BufferOutStream.init(&buffer).stream;
+
+ const x: i32 = 42;
+ const y: i32 = 1234;
+ try buf_stream.print("x: {}\ny: {}\n", x, y);
+
+ assert(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n"));
+}