mirror of
https://github.com/servo/servo.git
synced 2025-08-19 12:25:33 +01:00
Implement pair iterators in WebIDL interfaces.
This commit is contained in:
parent
34bb937aee
commit
812a761abf
9 changed files with 390 additions and 13 deletions
|
@ -51,4 +51,45 @@
|
|||
assert_array_equals(entry, expected[i++]);
|
||||
}
|
||||
}, "Iterators iterate over values");
|
||||
|
||||
test(function() {
|
||||
var t = new TestBindingPairIterable();
|
||||
var empty = true;
|
||||
t.forEach(function() { empty = false; });
|
||||
assert_true(empty);
|
||||
}, "Empty pair iterator");
|
||||
|
||||
test(function() {
|
||||
var t = new TestBindingPairIterable();
|
||||
function is_iterator(o) {
|
||||
return o[Symbol.iterator]() === o;
|
||||
}
|
||||
assert_true(is_iterator(t.keys()));
|
||||
assert_true(is_iterator(t.values()));
|
||||
assert_true(is_iterator(t.entries()));
|
||||
}, "Pair iterable iterators are iterators");
|
||||
|
||||
test(function() {
|
||||
var t = new TestBindingPairIterable();
|
||||
t.add("first", 0);
|
||||
t.add("second", 1);
|
||||
t.add("third", 2);
|
||||
assert_array_equals(collect(t.keys()), ["first", "second", "third"]);
|
||||
assert_array_equals(collect(t.values()), [0, 1, 2]);
|
||||
var expected = [["first", 0], ["second", 1], ["third", 2]];
|
||||
var i = 0;
|
||||
for (entry of t.entries()) {
|
||||
assert_array_equals(entry, expected[i++]);
|
||||
}
|
||||
|
||||
t.add("fourth", 3);
|
||||
assert_array_equals(collect(t.keys()), ["first", "second", "third", "fourth"]);
|
||||
assert_array_equals(collect(t.values()), [0, 1, 2, 3]);
|
||||
var expected = [["first", 0], ["second", 1], ["third", 2], ["fourth", 3]];
|
||||
var i = 0;
|
||||
for (entry of t.entries()) {
|
||||
assert_array_equals(entry, expected[i++]);
|
||||
}
|
||||
}, "Pair iterators iterate over key/value pairs");
|
||||
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue