import compound; //test concat { //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 dictionary concat with clashing keys { var a = ["one" : 1, "two": 2, "three": 3, "random": 1]; var b = ["four" : 4, "five": 5, "six": 6, "random": 2]; var c = a.concat(b); assert c["random"] == 1, "dictionary.concat() clashing keys failed"; } //test string concat { var a = "foo"; var b = "bar"; var c = a.concat(b); assert c == "foobar", "string.concat() failed"; } } //test forEach { var counter = 0; fn p(k, v) { counter++; print string k + ": " + string v; } var a = ["a", "b"]; var d = ["foo": 1, "bar": 2, "bazz": 3, "fizz": 4]; a.forEach(p); assert counter == 2, "forEach ran an unusual number of times"; counter = 0; d.forEach(p); assert counter == 4, "forEach ran an unusual number of times"; } //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 map { //test map with toy functions { fn increment(k, v) { return v + 1; } var a = [1, 2, 3]; var d = ["four": 4, "five": 5, "six": 6]; assert a.map(increment).map(increment).map(increment) == [4,5,6], "array.map() failed"; assert d.map(increment).map(increment).map(increment) == [8,9,7], "dictionary.map() failed"; } //test map with native functions { //TODO: write some native functions for use with map } } //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"; } //test trimBegin() assert " foo ".trimBegin() == "foo ", "string.trimBegin() failed"; assert " foo ".trimEnd() == " foo", "string.trimBegin() failed"; } print "All good";