mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
added accessors, write and additional tests
This commit is contained in:
@@ -1,18 +1,55 @@
|
||||
import fileio;
|
||||
|
||||
// test open
|
||||
// test global constants
|
||||
{
|
||||
assert MAX_FILENAME_SIZE > 0, "MAX_FILENAME_SIZE failed";
|
||||
assert MAX_FILES_OPEN > 0, "MAX_FILES_OPEN failed";
|
||||
assert END_OF_FILE == -1, "END_OF_FILE failed";
|
||||
}
|
||||
|
||||
// test open and close
|
||||
{
|
||||
var file = open("scripts:/lib/file/fileio.txt", "r");
|
||||
assert file != null, "open failed";
|
||||
|
||||
var wrong = open("scripts:/doesNotExist", "r");
|
||||
assert wrong == null, "open failed";
|
||||
|
||||
assert file.close() == true, "close failed";
|
||||
}
|
||||
|
||||
// test accessors
|
||||
{
|
||||
var file = open("scripts:/lib/file/fileio.txt", "r");
|
||||
|
||||
// file.read(string);
|
||||
|
||||
// TODO:
|
||||
// file.write(12, ",", 12);
|
||||
// file.size();
|
||||
// file.isOpened();
|
||||
// file.getrror();
|
||||
// file.position();
|
||||
// file.mode();
|
||||
|
||||
print file.close();
|
||||
}
|
||||
print file.error();
|
||||
print file.completed();
|
||||
print file.position();
|
||||
print file.size();
|
||||
print file.mode();
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
// test output
|
||||
{
|
||||
// assert output.write(8), "write int failed";
|
||||
// assert output.write("\n"), "write string failed";
|
||||
// assert output.write(12.5), "write float failed";
|
||||
}
|
||||
|
||||
// test input
|
||||
{
|
||||
// // enter 8
|
||||
// assert input.read(int) == 8, "read int failed";
|
||||
|
||||
// // enter 12.5
|
||||
// assert input.read(float) == 12.5, "read float failed";
|
||||
|
||||
// // enter test
|
||||
// assert input.read(string) == "test\n", "read string failed";
|
||||
|
||||
// // invaild types
|
||||
// assert input.read(type) == null, "type failed";
|
||||
// assert input.read(any) == null, "any failed";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user