1
0
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:
Sebastian Malton 2023-01-11 09:58:04 -05:00
parent 84cbc50717
commit 66c005657f
2 changed files with 32 additions and 8 deletions

View File

@ -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 });
});
});
}); });

View File

@ -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;
} }
} }