diff options
| author | tgschultz <tgschultz@gmail.com> | 2018-05-11 21:36:02 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-11 21:36:02 -0500 |
| commit | 8c1872543c8cf76215cc4bf3ced4637bb1065a4e (patch) | |
| tree | 72dfebb643ab61579e3fb8dd58cd4610ffe876fa /std/io_test.zig | |
| parent | 7186e92c86982950d0aa7c0c2deef9ef96bc1264 (diff) | |
| parent | 6e821078f625a03eb8b7794c983da0f7793366ab (diff) | |
| download | zig-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.zig | 18 |
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")); +} |
