mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Added _every() and _some()
This commit is contained in:
@@ -45,6 +45,34 @@ import compound;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//test every
|
||||
{
|
||||
var a = [1, 2, 3];
|
||||
var d = ["one": 1, "two": 2];
|
||||
|
||||
var counter = 0;
|
||||
fn f(k, v) {
|
||||
counter++;
|
||||
return v;
|
||||
}
|
||||
|
||||
assert a.every(f) == true, "array.every() == true failed";
|
||||
assert d.every(f) == true, "dictionary.every() == true failed";
|
||||
|
||||
assert counter == 5, "Unexpected number of calls for _every() == true";
|
||||
|
||||
counter = 0;
|
||||
a[1] = false;
|
||||
d["two"] = false;
|
||||
|
||||
assert a.every(f) == false, "array.every() == false failed";
|
||||
assert d.every(f) == false, "dictionary.every() == false failed";
|
||||
|
||||
assert counter == 4, "Unexpected number of calls for _every() == false";
|
||||
}
|
||||
|
||||
|
||||
//test forEach
|
||||
{
|
||||
var counter = 0;
|
||||
@@ -65,6 +93,7 @@ import compound;
|
||||
assert counter == 4, "forEach ran an unusual number of times";
|
||||
}
|
||||
|
||||
|
||||
//test getKeys
|
||||
{
|
||||
var d = ["foo": 1, "bar": 2];
|
||||
@@ -127,6 +156,33 @@ import compound;
|
||||
}
|
||||
|
||||
|
||||
//test some
|
||||
{
|
||||
var a = [false, false, false];
|
||||
var d = ["one": false, "two": false];
|
||||
|
||||
var counter = 0;
|
||||
fn f(k, v) {
|
||||
counter++;
|
||||
return v;
|
||||
}
|
||||
|
||||
assert a.some(f) == false, "array.some() == false failed";
|
||||
assert d.some(f) == false, "dictionary.some() == false failed";
|
||||
|
||||
assert counter == 5, "Unexpected number of calls for _some() == false";
|
||||
|
||||
counter = 0;
|
||||
a[1] = true;
|
||||
d["two"] = true;
|
||||
|
||||
assert a.some(f) == true, "array.some() == true failed";
|
||||
assert d.some(f) == true, "dictionary.some() == true failed";
|
||||
|
||||
assert counter == 4, "Unexpected number of calls for _some() == true";
|
||||
}
|
||||
|
||||
|
||||
//test toLower
|
||||
{
|
||||
assert "Hello World".toLower() == "hello world", "_toLower() failed";
|
||||
|
||||
Reference in New Issue
Block a user