diff options
| author | LemonBoy <thatlemon@gmail.com> | 2019-09-25 16:38:25 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-09-25 12:10:58 -0400 |
| commit | 3907e3b675daaa9869732aca6851bd2e0000000a (patch) | |
| tree | 61ce558aa094d7ff47811f495c0659e2b3f799ad /std/io/test.zig | |
| parent | 48c9e17aa1566ca7140d2460f2ed56daa8db7eeb (diff) | |
| download | zig-3907e3b675daaa9869732aca6851bd2e0000000a.tar.gz zig-3907e3b675daaa9869732aca6851bd2e0000000a.zip | |
Fix llseek behavior
Diffstat (limited to 'std/io/test.zig')
| -rw-r--r-- | std/io/test.zig | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/std/io/test.zig b/std/io/test.zig index e624733ba8..8ab18d3499 100644 --- a/std/io/test.zig +++ b/std/io/test.zig @@ -609,3 +609,27 @@ test "c out stream" { const out_stream = &io.COutStream.init(out_file).stream; try out_stream.print("hi: {}\n", i32(123)); } + +test "File seek ops" { + const tmp_file_name = "temp_test_file.txt"; + var file = try File.openWrite(tmp_file_name); + defer { + file.close(); + fs.deleteFile(tmp_file_name) catch {}; + } + + try file.write([_]u8{0x55} ** 8192); + + // Seek to the end + try file.seekFromEnd(0); + std.testing.expect((try file.getPos()) == try file.getEndPos()); + // Negative delta + try file.seekBy(-4096); + std.testing.expect((try file.getPos()) == 4096); + // Positive delta + try file.seekBy(10); + std.testing.expect((try file.getPos()) == 4106); + // Absolute position + try file.seekTo(1234); + std.testing.expect((try file.getPos()) == 1234); +} |
