wallet-core/node_modules/es6-iterator/test/array.js

68 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-12-10 21:51:33 +01:00
"use strict";
2017-08-14 05:01:11 +02:00
2017-12-10 21:51:33 +01:00
var iteratorSymbol = require("es6-symbol").iterator;
2017-08-14 05:01:11 +02:00
module.exports = function (T) {
return {
2017-12-10 21:51:33 +01:00
"Values": function (a) {
var x = ["raz", "dwa", "trzy", "cztery", "pięć", "sześć"], it;
2017-08-14 05:01:11 +02:00
it = new T(x);
a(it[iteratorSymbol](), it, "@@iterator");
2017-12-10 21:51:33 +01:00
a.deep(it.next(), { done: false, value: "raz" }, "#1");
a.deep(it.next(), { done: false, value: "dwa" }, "#2");
x.splice(1, 0, "elo");
a.deep(it.next(), { done: false, value: "dwa" }, "Insert");
a.deep(it.next(), { done: false, value: "trzy" }, "#3");
a.deep(it.next(), { done: false, value: "cztery" }, "#4");
2017-08-14 05:01:11 +02:00
x.pop();
2017-12-10 21:51:33 +01:00
a.deep(it.next(), { done: false, value: "pięć" }, "#5");
2017-08-14 05:01:11 +02:00
a.deep(it.next(), { done: true, value: undefined }, "End");
},
"Keys & Values": function (a) {
2017-12-10 21:51:33 +01:00
var x = ["raz", "dwa", "trzy", "cztery", "pięć", "sześć"], it;
2017-08-14 05:01:11 +02:00
2017-12-10 21:51:33 +01:00
it = new T(x, "key+value");
2017-08-14 05:01:11 +02:00
a(it[iteratorSymbol](), it, "@@iterator");
2017-12-10 21:51:33 +01:00
a.deep(it.next(), { done: false, value: [0, "raz"] }, "#1");
a.deep(it.next(), { done: false, value: [1, "dwa"] }, "#2");
x.splice(1, 0, "elo");
a.deep(it.next(), { done: false, value: [2, "dwa"] }, "Insert");
a.deep(it.next(), { done: false, value: [3, "trzy"] }, "#3");
a.deep(it.next(), { done: false, value: [4, "cztery"] }, "#4");
2017-08-14 05:01:11 +02:00
x.pop();
2017-12-10 21:51:33 +01:00
a.deep(it.next(), { done: false, value: [5, "pięć"] }, "#5");
2017-08-14 05:01:11 +02:00
a.deep(it.next(), { done: true, value: undefined }, "End");
},
2017-12-10 21:51:33 +01:00
"Keys": function (a) {
var x = ["raz", "dwa", "trzy", "cztery", "pięć", "sześć"], it;
2017-08-14 05:01:11 +02:00
2017-12-10 21:51:33 +01:00
it = new T(x, "key");
2017-08-14 05:01:11 +02:00
a(it[iteratorSymbol](), it, "@@iterator");
a.deep(it.next(), { done: false, value: 0 }, "#1");
a.deep(it.next(), { done: false, value: 1 }, "#2");
2017-12-10 21:51:33 +01:00
x.splice(1, 0, "elo");
2017-08-14 05:01:11 +02:00
a.deep(it.next(), { done: false, value: 2 }, "Insert");
a.deep(it.next(), { done: false, value: 3 }, "#3");
a.deep(it.next(), { done: false, value: 4 }, "#4");
x.pop();
a.deep(it.next(), { done: false, value: 5 }, "#5");
a.deep(it.next(), { done: true, value: undefined }, "End");
},
2017-12-10 21:51:33 +01:00
"Sparse": function (a) {
2017-08-14 05:01:11 +02:00
var x = new Array(6), it;
2017-12-10 21:51:33 +01:00
x[2] = "raz";
x[4] = "dwa";
2017-08-14 05:01:11 +02:00
it = new T(x);
a.deep(it.next(), { done: false, value: undefined }, "#1");
a.deep(it.next(), { done: false, value: undefined }, "#2");
2017-12-10 21:51:33 +01:00
a.deep(it.next(), { done: false, value: "raz" }, "#3");
2017-08-14 05:01:11 +02:00
a.deep(it.next(), { done: false, value: undefined }, "#4");
2017-12-10 21:51:33 +01:00
a.deep(it.next(), { done: false, value: "dwa" }, "#5");
2017-08-14 05:01:11 +02:00
a.deep(it.next(), { done: false, value: undefined }, "#6");
a.deep(it.next(), { done: true, value: undefined }, "End");
}
};
};