mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Gonna start unit testing to resolve issues
This commit is contained in:
87
scripts/test/native-functions.toy
Normal file
87
scripts/test/native-functions.toy
Normal file
@@ -0,0 +1,87 @@
|
||||
|
||||
{
|
||||
//test arrays without types
|
||||
var array = [];
|
||||
|
||||
_push(array, 1);
|
||||
_push(array, 2);
|
||||
_push(array, 3);
|
||||
_push(array, 4);
|
||||
_push(array, "foo");
|
||||
|
||||
assert _length(array) == 5, "_push or _length failed with array";
|
||||
assert _pop(array) == "foo", "_pop failed with array";
|
||||
|
||||
_set(array, 2, "bar");
|
||||
assert array == [1, 2, "bar", 4], "_set failed with array";
|
||||
assert _get(array, 3) == 4, "_get failed with array";
|
||||
|
||||
|
||||
//test dictionaries without types
|
||||
var dict = [:];
|
||||
|
||||
_set(dict, "key", "value");
|
||||
_set(dict, 1, 2);
|
||||
|
||||
assert dict == ["key":"value", 1:2], "_set failed with dictionaries";
|
||||
assert _get(dict, "key") == "value", "_get failed with dictionaries";
|
||||
|
||||
|
||||
//test _length
|
||||
assert _length(array) == 4 && _length(dict) == 2, "_length failed with array or dictionaries";
|
||||
|
||||
|
||||
//test clear
|
||||
_clear(array);
|
||||
_clear(dict);
|
||||
|
||||
assert _length(array) == 0 && _length(dict) == 0, "_clear failed with array or dictionaries";
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
//test arrays with types
|
||||
var array: [int] = [];
|
||||
|
||||
_push(array, 1);
|
||||
_push(array, 2);
|
||||
_push(array, 3);
|
||||
_push(array, 4);
|
||||
_push(array, 10);
|
||||
|
||||
assert _length(array) == 5, "_push or _length failed with array (+ types)";
|
||||
assert _pop(array) == 10, "_pop failed with array (+ types)";
|
||||
|
||||
_set(array, 2, 70);
|
||||
assert array == [1, 2, 70, 4], "_set failed with array (+ types)";
|
||||
assert _get(array, 3) == 4, "_get failed with array (+ types)";
|
||||
|
||||
|
||||
//test dictionaries with types
|
||||
var dict: [string, string] = [:];
|
||||
|
||||
_set(dict, "key", "value");
|
||||
|
||||
assert dict == ["key":"value"], "_set failed with dictionaries (+ types)";
|
||||
assert _get(dict, "key") == "value", "_get failed with dictionaries (+ types)";
|
||||
|
||||
|
||||
//test length with types
|
||||
assert _length(array) == 4 && _length(dict) == 1, "_length failed with array or dictionaries (+ types)";
|
||||
|
||||
|
||||
//test clear with types
|
||||
_clear(array);
|
||||
_clear(dict);
|
||||
|
||||
assert _length(array) == 0 && _length(dict) == 0, "_clear failed with array or dictionaries (+ types)";
|
||||
}
|
||||
|
||||
{
|
||||
var str = "hello world";
|
||||
|
||||
assert _length(str) == 11, "_length failed with string";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
Reference in New Issue
Block a user