mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
74 lines
1.8 KiB
Plaintext
74 lines
1.8 KiB
Plaintext
import fileio;
|
|
|
|
var PATH: string const = "scripts:/lib/file/fileio.txt";
|
|
|
|
// 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(PATH, "r");
|
|
assert file != null, "open failed";
|
|
|
|
var wrong = open("scripts:/doesNotExist", "r");
|
|
assert wrong == null, "open failed";
|
|
|
|
assert file.close() == true, "close failed";
|
|
}
|
|
|
|
// test append
|
|
{
|
|
var file = open(PATH, "a");
|
|
assert file.write("appended text") == true, "append failed";
|
|
|
|
file.close();
|
|
}
|
|
|
|
// test accessors
|
|
{
|
|
var file = open(PATH, "r");
|
|
|
|
assert file.error() == false, "error failed";
|
|
assert file.completed() == false, "completed failed";
|
|
assert file.position() == 0, "position failed";
|
|
assert file.size() >= 13, "size failed";
|
|
assert file.mode() == "r", "mode failed";
|
|
|
|
file.read(string);
|
|
|
|
assert file.error() == false, "error failed";
|
|
assert file.completed() == true, "completed failed";
|
|
assert file.position() >= 13, "position failed";
|
|
assert file.size() >= 13, "size failed";
|
|
// assert file.mode() == "r", "mode failed";
|
|
|
|
file.close();
|
|
}
|
|
|
|
// test write
|
|
{
|
|
assert output.write(8), "write int failed";
|
|
assert output.write("\n"), "write string failed";
|
|
assert output.write(12.5), "write float failed";
|
|
}
|
|
|
|
// test read
|
|
{
|
|
// 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";
|
|
}
|