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

48 lines
943 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;
2019-08-25 12:09:59 +00:00
import std.exception;
2016-10-06 20:06:51 +00:00
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();
2019-08-25 12:09:59 +00:00
auto fi = getFileInfo("test.dat");
assert(fi.name == "test.dat");
assert(fi.isFile);
assert(!fi.isDirectory);
assert(!fi.isSymlink);
assert(!fi.hidden);
assert(fi.size == 10);
assertThrown(getFileInfo("*impossible:file?"));
removeFile("test.dat");
2016-10-06 20:06:51 +00:00
}