mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Expanded the tests a little
This commit is contained in:
42
scripts/test/lib/interactions.toy
Normal file
42
scripts/test/lib/interactions.toy
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
//test the standard library, under a number of different circumstances
|
||||||
|
|
||||||
|
//test basic import
|
||||||
|
{
|
||||||
|
import standard;
|
||||||
|
|
||||||
|
//this depends on external factors, so only check the length
|
||||||
|
assert clock().length() == 24, "import library failed";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//test import within a function
|
||||||
|
{
|
||||||
|
fn f() {
|
||||||
|
import standard;
|
||||||
|
|
||||||
|
assert clock != null, "import library within function failed";
|
||||||
|
|
||||||
|
return clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
//invoke
|
||||||
|
assert f()().length() == 24, "import library within function and return failed";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//test closing over standard library element
|
||||||
|
{
|
||||||
|
import standard;
|
||||||
|
|
||||||
|
fn f() {
|
||||||
|
assert clock != null, "import library outside function failed";
|
||||||
|
|
||||||
|
return clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
//invoke
|
||||||
|
assert f()().length() == 24, "import library outside function and return failed";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print "All good";
|
||||||
@@ -95,8 +95,9 @@ void runBinary(unsigned char* tb, size_t size) {
|
|||||||
initInterpreter(&interpreter);
|
initInterpreter(&interpreter);
|
||||||
|
|
||||||
//NOTE: supress print output for testing
|
//NOTE: supress print output for testing
|
||||||
// setInterpreterPrint(&interpreter, noPrintFn);
|
setInterpreterPrint(&interpreter, noPrintFn);
|
||||||
|
|
||||||
|
//inject the standard libraries into this interpreter
|
||||||
injectNativeHook(&interpreter, "standard", hookStandard);
|
injectNativeHook(&interpreter, "standard", hookStandard);
|
||||||
|
|
||||||
runInterpreter(&interpreter, tb, size);
|
runInterpreter(&interpreter, tb, size);
|
||||||
@@ -123,6 +124,7 @@ int main() {
|
|||||||
{
|
{
|
||||||
//run each file in ../scripts/test/
|
//run each file in ../scripts/test/
|
||||||
char* filenames[] = {
|
char* filenames[] = {
|
||||||
|
"interactions.toy",
|
||||||
"standard.toy",
|
"standard.toy",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user