Skip to content

Commit

Permalink
test(rstream): add pubsub equivmap generics
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 29, 2019
1 parent f4dd663 commit feac18d
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions packages/rstream/test/pubsub.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { EquivMap } from "@thi.ng/associative";
import * as tx from "@thi.ng/transducers";
import * as assert from "assert";

import * as rs from "../src/index";

describe("PubSub", () => {
Expand All @@ -21,18 +20,32 @@ describe("PubSub", () => {
});

it("complex keys", () => {
const acc = new EquivMap();
const collect = { next: (x) => { let v = acc.get(x); v ? v.push(x) : acc.set(x, [x]) } };
const acc = new EquivMap<[string, number], [string, number][]>();
const collect = {
next: (x) => {
let v = acc.get(x);
v ? v.push(x) : acc.set(x, [x]);
}
};
pub = rs.pubsub({ topic: (x) => x });
pub.subscribeTopic(["a", 0], collect);
pub.subscribeTopic(["a", 1], collect);
pub.subscribeTopic(["b", 2], collect);
rs.fromIterableSync([["a", 0], ["a", 1], ["b", 2], ["a", 0], ["c", 3]]).subscribe(pub);
assert.deepEqual([...acc], [
[["a", 0], [["a", 0], ["a", 0]]],
[["a", 1], [["a", 1]]],
[["b", 2], [["b", 2]]],
]);
rs.fromIterableSync([
["a", 0],
["a", 1],
["b", 2],
["a", 0],
["c", 3]
]).subscribe(pub);
assert.deepEqual(
[...acc],
[
[["a", 0], [["a", 0], ["a", 0]]],
[["a", 1], [["a", 1]]],
[["b", 2], [["b", 2]]]
]
);
assert.equal(pub.getState(), rs.State.DONE);
});

Expand All @@ -46,7 +59,12 @@ describe("PubSub", () => {
pub.subscribeTopic("a", collect);
pub.subscribeTopic("b", collect);
rs.fromIterableSync("abcbd").subscribe(pub);
assert.deepEqual(acc, { a: [["a", 0]], b: [["b", 1], ["b", 3]], c: [], d: [] });
assert.deepEqual(acc, {
a: [["a", 0]],
b: [["b", 1], ["b", 3]],
c: [],
d: []
});
assert.equal(pub.getState(), rs.State.DONE);
});

Expand All @@ -64,5 +82,4 @@ describe("PubSub", () => {
done();
}, 40);
});

});
});

0 comments on commit feac18d

Please sign in to comment.