Skip to content

Commit 34776e8

Browse files
committed
Add test coverage for more generator methods
1 parent c51b359 commit 34776e8

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

test/generators/generators-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { test } from "tap";
2+
import filter from "../../src/generators/filter";
3+
import map from "../../src/generators/map";
4+
import range from "../../src/generators/range";
5+
import valueAt from "../../src/generators/valueAt";
6+
7+
test("filter(value, fn) filters", t => {
8+
function* input() {
9+
yield* [1, 2, 3, 4];
10+
}
11+
t.deepEqual(Array.from(filter(input(), i => i % 2 === 0)), [2, 4]);
12+
t.end();
13+
});
14+
15+
test("map(value, fn) maps", t => {
16+
function* input() {
17+
yield* [1, 2, 3, 4];
18+
}
19+
t.deepEqual(Array.from(map(input(), i => i * 2)), [2, 4, 6, 8]);
20+
t.end();
21+
});
22+
23+
test("range(start, stop) generates a range", t => {
24+
t.deepEqual(Array.from(range(1, 4)), [1, 2, 3]);
25+
t.deepEqual(Array.from(range(1, 5, 2)), [1, 3]);
26+
t.deepEqual(Array.from(range(3)), [0, 1, 2]);
27+
t.end();
28+
});
29+
30+
test("valueAt(generator, i) picks a value", t => {
31+
function* input() {
32+
yield* [1, 2, 3, 4];
33+
}
34+
t.equal(valueAt(input(), 2), 3);
35+
t.equal(valueAt(input()), undefined);
36+
t.end();
37+
});

test/index-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test } from "tap";
2-
import {Library, FileAttachments} from "../src";
2+
import { Library, FileAttachments } from "../src";
33

44
test("new Library returns a library with the expected keys", async t => {
55
t.deepEqual(Object.keys(new Library()).sort(), [

0 commit comments

Comments
 (0)