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