mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add some technical tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
84cbc50717
commit
66c005657f
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { join, nth, reduce } from "../iter";
|
import { join, nth, reduce, concat } from "../iter";
|
||||||
|
|
||||||
describe("iter", () => {
|
describe("iter", () => {
|
||||||
describe("reduce", () => {
|
describe("reduce", () => {
|
||||||
@ -39,4 +39,30 @@ describe("iter", () => {
|
|||||||
expect(nth(["a", "b"], 0)).toBe("a");
|
expect(nth(["a", "b"], 0)).toBe("a");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("concat", () => {
|
||||||
|
it("should yield undefined for empty args", () => {
|
||||||
|
const iter = concat();
|
||||||
|
|
||||||
|
expect(iter.next()).toEqual({ done: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should yield undefined for only empty args", () => {
|
||||||
|
const iter = concat([].values(), [].values(), [].values(), [].values());
|
||||||
|
|
||||||
|
expect(iter.next()).toEqual({ done: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should yield all of the first and then all of the second", () => {
|
||||||
|
const iter = concat([1, 2, 3].values(), [4, 5, 6].values());
|
||||||
|
|
||||||
|
expect(iter.next()).toEqual({ done: false, value: 1 });
|
||||||
|
expect(iter.next()).toEqual({ done: false, value: 2 });
|
||||||
|
expect(iter.next()).toEqual({ done: false, value: 3 });
|
||||||
|
expect(iter.next()).toEqual({ done: false, value: 4 });
|
||||||
|
expect(iter.next()).toEqual({ done: false, value: 5 });
|
||||||
|
expect(iter.next()).toEqual({ done: false, value: 6 });
|
||||||
|
expect(iter.next()).toEqual({ done: true });
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -239,12 +239,10 @@ export function every<T>(src: Iterable<T>, fn: (val: T) => any): boolean {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* concat<T>(src1: IterableIterator<T>, src2: IterableIterator<T>): IterableIterator<T> {
|
export function* concat<T>(...sources: IterableIterator<T>[]): IterableIterator<T> {
|
||||||
for (const val of src1) {
|
for (const source of sources) {
|
||||||
yield val;
|
for (const val of source) {
|
||||||
}
|
yield val;
|
||||||
|
}
|
||||||
for (const val of src2) {
|
|
||||||
yield val;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user