1 | 'use strict';
|
---|
2 |
|
---|
3 | require('../auto');
|
---|
4 |
|
---|
5 | var test = require('tape');
|
---|
6 | var forEach = require('for-each');
|
---|
7 |
|
---|
8 | var shims = require('../');
|
---|
9 |
|
---|
10 | forEach(shims, function (shim) {
|
---|
11 | var shimTests;
|
---|
12 | try {
|
---|
13 | shimTests = require('./' + shim); // eslint-disable-line global-require
|
---|
14 | } catch (e) {
|
---|
15 | test(shim + ': shimmed', { todo: true });
|
---|
16 | }
|
---|
17 | if (shimTests) {
|
---|
18 | shimTests.shimmed();
|
---|
19 | }
|
---|
20 | });
|
---|
21 |
|
---|
22 | test('integration', function (t) {
|
---|
23 | var seenMapEveryMap = [];
|
---|
24 | var seenMapEveryEvery = [];
|
---|
25 | var mapEveryResult = Iterator.from([1, 2, 3, 4, 5]).map(function (x) {
|
---|
26 | seenMapEveryMap.push(x);
|
---|
27 | return x * x;
|
---|
28 | }).every(function (x) {
|
---|
29 | seenMapEveryEvery.push(x);
|
---|
30 | return x < 10;
|
---|
31 | });
|
---|
32 | t.equal(mapEveryResult, false, 'map + every: every predicate returned false nonzero times');
|
---|
33 | t.deepEqual(seenMapEveryMap, [1, 2, 3, 4], 'map + every, map: all values are seen until after the first one that is > 10 when squared');
|
---|
34 | t.deepEqual(seenMapEveryEvery, [1, 4, 9, 16], 'map + every, every: all values are seen until after the first one that is > 10 when squared');
|
---|
35 |
|
---|
36 | var seenMapSomeMap = [];
|
---|
37 | var seenMapSomeSome = [];
|
---|
38 | var mapSomeResult = Iterator.from([1, 2, 3, 4, 5]).map(function (x) {
|
---|
39 | seenMapSomeMap.push(x);
|
---|
40 | return x * x;
|
---|
41 | }).some(function (x) {
|
---|
42 | seenMapSomeSome.push(x);
|
---|
43 | return x > 10;
|
---|
44 | });
|
---|
45 | t.equal(mapSomeResult, true, 'map + some: some predicate returned true nonzero times');
|
---|
46 | t.deepEqual(seenMapSomeMap, [1, 2, 3, 4], 'map + some, map: all values are seen until after the first one that is > 10 when squared');
|
---|
47 | t.deepEqual(seenMapSomeSome, [1, 4, 9, 16], 'map + some, some: all values are seen until after the first one that is > 10 when squared');
|
---|
48 |
|
---|
49 | var seenMapFind = [];
|
---|
50 | var mapFindResult = Iterator.from([1, 2, 3, 4, 5]).map(function (x) {
|
---|
51 | seenMapFind.push(x);
|
---|
52 | return x * x;
|
---|
53 | }).find(function (x) {
|
---|
54 | return x > 10;
|
---|
55 | });
|
---|
56 | t.equal(mapFindResult, 16, 'map + find: find found the first mapped value over 10');
|
---|
57 | t.deepEqual(seenMapFind, [1, 2, 3, 4], 'map + find: all values are seen until after the first one that is > 10 when squared');
|
---|
58 |
|
---|
59 | var seenFilterEvery = [];
|
---|
60 | var filterEveryResult = Iterator.from([1, 2, 3, 4, 5]).filter(function (x) {
|
---|
61 | seenFilterEvery.push(x);
|
---|
62 | return x;
|
---|
63 | }).every(function (x) {
|
---|
64 | return x <= 3;
|
---|
65 | });
|
---|
66 | t.equal(filterEveryResult, false, 'filter + every: every predicate returned false nonzero times');
|
---|
67 | t.deepEqual(seenMapFind, [1, 2, 3, 4], 'filter + every: all values are seen until after the first one that is > 10 when squared');
|
---|
68 |
|
---|
69 | t.end();
|
---|
70 | });
|
---|