mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
118 lines
2.3 KiB
Plaintext
118 lines
2.3 KiB
Plaintext
import compound;
|
|
|
|
{
|
|
//test array concat
|
|
{
|
|
var a = [1, 2, 3];
|
|
var b = [4, 5, 6];
|
|
|
|
var c = a.concat(b).concat(b);
|
|
|
|
assert c == [1, 2, 3, 4, 5, 6, 4, 5, 6], "array.concat() failed";
|
|
}
|
|
|
|
//test dictionary concat
|
|
{
|
|
var a = ["one" : 1, "two": 2, "three": 3];
|
|
var b = ["four" : 4, "five": 5, "six": 6];
|
|
|
|
var c = a.concat(b);
|
|
|
|
assert c.length() == 6, "dictionary.concat().length() failed";
|
|
|
|
assert c == ["one" : 1, "two": 2, "three": 3, "four" : 4, "five": 5, "six": 6], "dictionary.concat() comparison failed";
|
|
}
|
|
|
|
//test string concat
|
|
{
|
|
var a = "foo";
|
|
var b = "bar";
|
|
|
|
var c = a.concat(b);
|
|
|
|
assert c == "foobar", "string.concat() failed";
|
|
}
|
|
}
|
|
|
|
//test getKeys
|
|
{
|
|
var d = ["foo": 1, "bar": 2];
|
|
|
|
var a = d.getKeys();
|
|
|
|
assert a.length() == 2, "_getKeys() length failed";
|
|
|
|
//NOTE: dependant on hash algorithm
|
|
assert a == ["bar", "foo"], "_getKeys() result failed";
|
|
}
|
|
|
|
|
|
//test getValues
|
|
{
|
|
var d = ["foo": 1, "bar": 2];
|
|
|
|
var a = d.getValues();
|
|
|
|
assert a.length() == 2, "_getValues() length failed";
|
|
|
|
//NOTE: dependant on hash algorithm
|
|
assert a == [2, 1], "_getValues() result failed";
|
|
}
|
|
|
|
|
|
//test toLower
|
|
{
|
|
assert "Hello World".toLower() == "hello world", "_toLower() failed";
|
|
}
|
|
|
|
|
|
//test toString
|
|
{
|
|
var a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
|
|
|
|
var s = a.toString();
|
|
|
|
assert s == "[[1,2,3],[4,5,6],[7,8,9]]", "array._toString() failed";
|
|
}
|
|
|
|
|
|
//test toUpper
|
|
{
|
|
assert "Hello World".toUpper() == "HELLO WORLD", "_toUpper() failed";
|
|
}
|
|
|
|
|
|
//test trim defaults
|
|
{
|
|
//test a bunch
|
|
fn test(s, pass) {
|
|
var result = s.trim();
|
|
assert result == pass, "_trim(" + result + ") failed";
|
|
}
|
|
|
|
test("hello world", "hello world");
|
|
test(" hello world", "hello world");
|
|
test("hello world ", "hello world");
|
|
test(" hello world ", "hello world");
|
|
test(" hello world", "hello world");
|
|
test("hello world ", "hello world");
|
|
test(" hello world ", "hello world");
|
|
test(" hello world", "hello world");
|
|
test("hello world ", "hello world");
|
|
test(" hello world ", "hello world");
|
|
|
|
//one for goot luck
|
|
assert " hello world ".trim() == "hello world", "hello world.trim() failed";
|
|
}
|
|
|
|
|
|
//test trim custom values
|
|
{
|
|
var chars = "heilod";
|
|
|
|
assert "hello world".trim(chars) == " wor", "custom _trim() failed";
|
|
}
|
|
|
|
|
|
print "All good";
|