Files
shaka-player/test/util/iterables_unit.js
T
Jacob Trimble 47daf49f31 Use arrow functions for callbacks.
This is an automated change to convert use of "function" functions
to arrow functions.  This doesn't change all uses of bind() that
could be converted.  This also doesn't remove all "function" functions.

Change-Id: I40ac7d086bcef947a1be083359c8fd1d4499a9c3
2019-05-09 16:40:46 +00:00

88 lines
2.4 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', () => {
const Iterables = shaka.util.Iterables;
describe('map', () => {
const map = Iterables.map;
it('works with no items', () => {
const input = new Set([]);
const output = Array.from(map(input, (x) => -x));
expect(output).toEqual([]);
});
it('works with items', () => {
const input = new Set([1, 2, 3]);
const output = Array.from(map(input, (x) => -x));
expect(output).toEqual([-1, -2, -3]);
});
});
describe('every', () => {
const every = Iterables.every;
it('works with no items', () => {
const input = new Set([]);
expect(every(input, (x) => x >= 0)).toBeTruthy();
});
it('works with items', () => {
const input = new Set([0, 1, 2, 3]);
expect(every(input, (x) => x >= 0)).toBeTruthy();
expect(every(input, (x) => x > 0)).toBeFalsy();
});
});
describe('some', () => {
const some = Iterables.some;
it('works with no items', () => {
const input = new Set([]);
expect(some(input, (x) => x >= 2)).toBeFalsy();
});
it('works with items', () => {
const input = new Set([0, 1, 2, 3]);
expect(some(input, (x) => x > 2)).toBeTruthy();
expect(some(input, (x) => x < 0)).toBeFalsy();
});
});
describe('filter', () => {
const filter = Iterables.filter;
it('works with no items', () => {
const input = new Set([]);
expect(filter(input, (x) => x >= 2)).toEqual([]);
});
it('works with items', () => {
const input = new Set([0, 1, 2, 3]);
// Everything
expect(filter(input, (x) => x < 7)).toEqual([0, 1, 2, 3]);
// Some things
expect(filter(input, (x) => x < 2)).toEqual([0, 1]);
// Nothing
expect(filter(input, (x) => x < 0)).toEqual([]);
});
});
});