aboutsummaryrefslogtreecommitdiff
path: root/node_modules/es6-map/test/lib
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/es6-map/test/lib
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/es6-map/test/lib')
-rw-r--r--node_modules/es6-map/test/lib/iterator-kinds.js5
-rw-r--r--node_modules/es6-map/test/lib/iterator.js13
-rw-r--r--node_modules/es6-map/test/lib/primitive-iterator.js130
3 files changed, 148 insertions, 0 deletions
diff --git a/node_modules/es6-map/test/lib/iterator-kinds.js b/node_modules/es6-map/test/lib/iterator-kinds.js
new file mode 100644
index 000000000..41ea10c57
--- /dev/null
+++ b/node_modules/es6-map/test/lib/iterator-kinds.js
@@ -0,0 +1,5 @@
+'use strict';
+
+module.exports = function (t, a) {
+ a.deep(t, { key: true, value: true, 'key+value': true });
+};
diff --git a/node_modules/es6-map/test/lib/iterator.js b/node_modules/es6-map/test/lib/iterator.js
new file mode 100644
index 000000000..2688ed26c
--- /dev/null
+++ b/node_modules/es6-map/test/lib/iterator.js
@@ -0,0 +1,13 @@
+'use strict';
+
+var Map = require('../../polyfill')
+ , toArray = require('es5-ext/array/to-array');
+
+module.exports = function (T, a) {
+ var arr = [['raz', 'one'], ['dwa', 'two']], map = new Map(arr);
+
+ a.deep(toArray(new T(map)), arr, "Default");
+ a.deep(toArray(new T(map, 'key+value')), arr, "Key & Value");
+ a.deep(toArray(new T(map, 'value')), ['one', 'two'], "Value");
+ a.deep(toArray(new T(map, 'key')), ['raz', 'dwa'], "Value");
+};
diff --git a/node_modules/es6-map/test/lib/primitive-iterator.js b/node_modules/es6-map/test/lib/primitive-iterator.js
new file mode 100644
index 000000000..ed2790de9
--- /dev/null
+++ b/node_modules/es6-map/test/lib/primitive-iterator.js
@@ -0,0 +1,130 @@
+'use strict';
+
+var iteratorSymbol = require('es6-symbol').iterator
+ , toArray = require('es5-ext/array/to-array')
+ , Map = require('../../primitive')
+
+ , compare, mapToResults;
+
+compare = function (a, b) {
+ if (!a.value) return -1;
+ if (!b.value) return 1;
+ return a.value[0].localeCompare(b.value[0]);
+};
+
+mapToResults = function (arr) {
+ return arr.sort().map(function (value) {
+ return { done: false, value: value };
+ });
+};
+
+module.exports = function (T) {
+ return {
+ "": function (a) {
+ var arr, it, y, z, map, result = [];
+
+ arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
+ ['cztery', 'four'], ['pięć', 'five']];
+ map = new Map(arr);
+
+ it = new T(map);
+ a(it[iteratorSymbol](), it, "@@iterator");
+ y = it.next();
+ result.push(y);
+ z = it.next();
+ a.not(y, z, "Recreate result");
+ result.push(z);
+ result.push(it.next());
+ result.push(it.next());
+ result.push(it.next());
+ a.deep(result.sort(compare), mapToResults(arr));
+ a.deep(y = it.next(), { done: true, value: undefined }, "End");
+ a.not(y, it.next(), "Recreate result on dead");
+ },
+ Emited: function (a) {
+ var arr, it, map, result = [];
+
+ arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
+ ['cztery', 'four'], ['pięć', 'five']];
+ map = new Map(arr);
+
+ it = new T(map);
+ result.push(it.next());
+ result.push(it.next());
+ map.set('sześć', 'six');
+ arr.push(['sześć', 'six']);
+ result.push(it.next());
+ map.delete('pięć');
+ arr.splice(4, 1);
+ result.push(it.next());
+ result.push(it.next());
+ a.deep(result.sort(compare), mapToResults(arr));
+ a.deep(it.next(), { done: true, value: undefined }, "End");
+ },
+ "Emited #2": function (a) {
+ var arr, it, map, result = [];
+
+ arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
+ ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']];
+ map = new Map(arr);
+
+ it = new T(map);
+ result.push(it.next());
+ result.push(it.next());
+ map.set('siedem', 'seven');
+ map.delete('siedem');
+ result.push(it.next());
+ result.push(it.next());
+ map.delete('pięć');
+ arr.splice(4, 1);
+ result.push(it.next());
+ a.deep(result.sort(compare), mapToResults(arr));
+ a.deep(it.next(), { done: true, value: undefined }, "End");
+ },
+ "Emited: Clear #1": function (a) {
+ var arr, it, map, result = [];
+
+ arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
+ ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']];
+ map = new Map(arr);
+
+ it = new T(map);
+ result.push(it.next());
+ result.push(it.next());
+ arr = [['raz', 'one'], ['dwa', 'two']];
+ map.clear();
+ a.deep(result.sort(compare), mapToResults(arr));
+ a.deep(it.next(), { done: true, value: undefined }, "End");
+ },
+ "Emited: Clear #2": function (a) {
+ var arr, it, map, result = [];
+
+ arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
+ ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']];
+ map = new Map(arr);
+
+ it = new T(map);
+ result.push(it.next());
+ result.push(it.next());
+ map.clear();
+ map.set('foo', 'bru');
+ map.set('bar', 'far');
+ arr = [['raz', 'one'], ['dwa', 'two'], ['foo', 'bru'], ['bar', 'far']];
+ result.push(it.next());
+ result.push(it.next());
+ a.deep(result.sort(compare), mapToResults(arr));
+ a.deep(it.next(), { done: true, value: undefined }, "End");
+ },
+ Kinds: function (a) {
+ var arr = [['raz', 'one'], ['dwa', 'two']], map = new Map(arr);
+
+ a.deep(toArray(new T(map)).sort(), arr.sort(), "Default");
+ a.deep(toArray(new T(map, 'key+value')).sort(), arr.sort(),
+ "Key + Value");
+ a.deep(toArray(new T(map, 'value')).sort(), ['one', 'two'].sort(),
+ "Value");
+ a.deep(toArray(new T(map, 'key')).sort(), ['raz', 'dwa'].sort(),
+ "Key");
+ }
+ };
+};