vibe-core/tests/vibe.core.file.d

37 lines
687 B
D
Raw Normal View History

/+ dub.sdl:
2016-10-06 20:06:51 +00:00
name "test"
dependency "vibe-core" path=".."
+/
module test;
import vibe.core.file;
2016-12-19 20:57:52 +00:00
enum ubyte[] bytes(BYTES...) = [BYTES];
2016-10-06 20:06:51 +00:00
void main()
{
auto f = openFile("test.dat", FileMode.createTrunc);
assert(f.size == 0);
assert(f.tell == 0);
2016-12-19 20:57:52 +00:00
f.write(bytes!(1, 2, 3, 4, 5));
2016-10-06 20:06:51 +00:00
assert(f.size == 5);
assert(f.tell == 5);
2016-10-06 20:06:51 +00:00
f.seek(0);
assert(f.tell == 0);
2016-12-19 20:57:52 +00:00
f.write(bytes!(1, 2, 3, 4, 5));
2016-10-06 20:06:51 +00:00
assert(f.size == 5);
assert(f.tell == 5);
2016-12-19 20:57:52 +00:00
f.write(bytes!(6, 7, 8, 9, 10));
2016-10-06 20:06:51 +00:00
assert(f.size == 10);
assert(f.tell == 10);
2016-10-06 20:06:51 +00:00
ubyte[5] dst;
f.seek(2);
assert(f.tell == 2);
2016-10-06 20:06:51 +00:00
f.read(dst);
assert(f.tell == 7);
2016-12-19 20:57:52 +00:00
assert(dst[] == bytes!(3, 4, 5, 6, 7));
f.close();
removeFile("test.dat");
2016-10-06 20:06:51 +00:00
}