mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-07-02 18:49:36 +03:00
c47ecb859e
To avoid always having to create arrays to do array-like methods I have created a util that recreates some of those simple yet useful methods that will act on any iterable or iterator. This should make it easier to work with Set and Map. Change-Id: Iec868fda4c9d018f813e824ea197ef914436fee3
69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
describe('Iterables', function() {
|
|
const Iterables = shaka.util.Iterables;
|
|
|
|
describe('map', function() {
|
|
const map = Iterables.map;
|
|
|
|
it('works with no items', function() {
|
|
const input = new Set([]);
|
|
const output = Array.from(map(input, (x) => -x));
|
|
|
|
expect(output).toEqual([]);
|
|
});
|
|
|
|
it('works with items', function() {
|
|
const input = new Set([1, 2, 3]);
|
|
const output = Array.from(map(input, (x) => -x));
|
|
|
|
expect(output).toEqual([-1, -2, -3]);
|
|
});
|
|
});
|
|
|
|
describe('every', function() {
|
|
const every = Iterables.every;
|
|
|
|
it('works with no items', function() {
|
|
const input = new Set([]);
|
|
expect(every(input, (x) => x >= 0)).toBeTruthy();
|
|
});
|
|
|
|
it('works with items', function() {
|
|
const input = new Set([0, 1, 2, 3]);
|
|
expect(every(input, (x) => x >= 0)).toBeTruthy();
|
|
expect(every(input, (x) => x > 0)).toBeFalsy();
|
|
});
|
|
});
|
|
|
|
describe('some', function() {
|
|
const some = Iterables.some;
|
|
|
|
it('works with no items', function() {
|
|
const input = new Set([]);
|
|
expect(some(input, (x) => x >= 2)).toBeFalsy();
|
|
});
|
|
|
|
it('works with items', function() {
|
|
const input = new Set([0, 1, 2, 3]);
|
|
expect(some(input, (x) => x > 2)).toBeTruthy();
|
|
expect(some(input, (x) => x < 0)).toBeFalsy();
|
|
});
|
|
});
|
|
});
|