tests: add a separate File.tell() test

pull/10917/head
Delyan Angelov 2021-07-22 16:25:23 +03:00
parent c4da74dbf6
commit b537c9f624
1 changed files with 20 additions and 12 deletions

View File

@ -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<byte>() ?
assert b == another_byte
f.seek(i64(sizeof(Color)), .current) ?
x := f.read_raw<Permissions>() ?
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<Color>() ?
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
}
}