From b537c9f62418965681e2b4ec47015ca8d16af45d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 22 Jul 2021 16:25:23 +0300 Subject: [PATCH] tests: add a separate File.tell() test --- vlib/os/file_test.v | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/vlib/os/file_test.v b/vlib/os/file_test.v index 7927944e7f..7c20af56e8 100644 --- a/vlib/os/file_test.v +++ b/vlib/os/file_test.v @@ -342,23 +342,31 @@ fn test_seek() ? { // println('> ${sizeof(Point)} ${sizeof(byte)} ${sizeof(Color)} ${sizeof(Permissions)}') f = os.open_file(tfile, 'r') ? - defer { - f.close() - } + // f.seek(i64(sizeof(Point)), .start) ? assert f.tell() ? == sizeof(Point) b := f.read_raw() ? + assert b == another_byte f.seek(i64(sizeof(Color)), .current) ? x := f.read_raw() ? - - f.seek(-i64(sizeof(Permissions) + sizeof(Color)), .end) ? - $if !macos { - // TODO: investigate in detail why this behaves differently in macos - assert f.tell() ? == sizeof(Point) + sizeof(byte) - } - cc := f.read_raw() ? - assert b == another_byte assert x == another_permission - assert cc == another_color + // + f.close() +} + +fn test_tell() ? { + for size in 10 .. 30 { + s := 'x'.repeat(size) + os.write_file(tfile, s) ? + fs := os.file_size(tfile) + assert fs == size + // + mut f := os.open_file(tfile, 'r') ? + f.seek(-5, .end) ? + pos := f.tell() ? + f.close() + // dump(pos) + assert pos == size - 5 + } }