mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
92 lines
2.1 KiB
Plaintext
92 lines
2.1 KiB
Plaintext
|
|
{
|
|
//test arrays without types
|
|
var array = [];
|
|
|
|
assert _length(array) == 0, "_length failed with array";
|
|
|
|
_push(array, 1);
|
|
_push(array, 2);
|
|
_push(array, 3);
|
|
_push(array, 4);
|
|
_push(array, "foo");
|
|
|
|
assert _length(array) == 5, "_push 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] = [];
|
|
|
|
assert _length(array) == 0, "_length failed with array (+ types)";
|
|
|
|
_push(array, 1);
|
|
_push(array, 2);
|
|
_push(array, 3);
|
|
_push(array, 4);
|
|
_push(array, 10);
|
|
|
|
assert _length(array) == 5, "_push or 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";
|