annotate src/tabulate.test.ts @ 94:a5f53d397526

view: pick types to show at top-level
author drewp@bigasterisk.com
date Wed, 12 Jan 2022 22:09:20 -0800
parents ac7ad087d474
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
1 import { groupByRdfType } from "./tabulate";
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
2 import {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
3 Literal,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
4 DataFactory,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
5 Store,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
6 Prefixes,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
7 Parser,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
8 Quad,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
9 NamedNode,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
10 } from "n3";
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
11 import Immutable from "immutable";
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
12 const { namedNode } = DataFactory;
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
13
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
14 describe("equality", () => {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
15 test("investigation of https://github.com/rdfjs/N3.js/issues/265", () => {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
16 const x = namedNode("x");
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
17 const x2 = namedNode("x");
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
18 // (NamedNode.prototype as any).hashCode = () => 0;
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
19 // expect((x as any).hashCode()).toEqual((x2 as any).hashCode())
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
20 expect(x === x2).toBeFalsy();
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
21 expect(x == x2).toBeFalsy();
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
22 expect(x.equals(x2)).toBeTruthy();
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
23 let imap = Immutable.Map();
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
24 imap = imap.set(x, 11);
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
25 imap = imap.set(x, 22);
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
26 imap = imap.set(x2, 33);
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
27 expect(imap.has(x)).toBeTruthy();
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
28 expect(imap.has(x2)).toBeTruthy();
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
29 expect(imap.size).toEqual(1);
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
30 });
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
31 });
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
32
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
33 describe("groupByRdfType", () => {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
34 test("finds multiple graphs", () => {});
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
35 test("works", async () => {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
36 const store = new Store();
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
37
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
38 const parser = new Parser();
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
39 await new Promise((res, rej) => {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
40 parser.parse(
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
41 `PREFIX : <urn:>
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
42 :rs1 a :Foo; :pred1 "obj1" .
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
43 :rs2 a :Foo; :pred1 "obj2" .
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
44 :rs3 a :Bar .
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
45 :rs4 :pred1 "obj4" .
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
46 `,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
47 (error, quad: Quad, prefixes: Prefixes) => {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
48 if (quad) {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
49 store.addQuad(quad);
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
50 } else {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
51 res(undefined);
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
52 }
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
53 }
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
54 );
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
55 });
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
56 const grouped = groupByRdfType(store);
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
57 expect(Array.from(grouped.byType.keys())).toHaveLength(2);
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
58 expect(grouped.byType.get(namedNode("urn:Foo"))).toEqual(
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
59 Immutable.Set([namedNode("urn:rs1"), namedNode("urn:rs2")])
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
60 );
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
61 expect(grouped.byType.get(namedNode("urn:Bar"))).toEqual(
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
62 Immutable.Set([namedNode("urn:rs3")])
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
63 );
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
64 expect(grouped.untypedSubjs).toEqual([namedNode("urn:rs4")]);
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
65 });
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff changeset
66 });