Mercurial > code > home > repos > streamed-graph
comparison src/layout/rdf_value.test.ts @ 108:5e6840229a05
rewrite freeStatements rendering to put more planning in layout
author | drewp@bigasterisk.com |
---|---|
date | Fri, 18 Mar 2022 11:57:38 -0700 |
parents | |
children | 8715633f5213 |
comparison
equal
deleted
inserted
replaced
107:042bd3361339 | 108:5e6840229a05 |
---|---|
1 import Immutable from "immutable"; | |
2 import { DataFactory, NamedNode, Term } from "n3"; | |
3 import { EX } from "./namespaces"; | |
4 import { uniqueSortedTerms } from "./rdf_value"; | |
5 const { namedNode, literal } = DataFactory; | |
6 describe("Immutable.Set", () => { | |
7 it("contains", () => { | |
8 const s = Immutable.Set([EX("e1")]); | |
9 expect(s.contains(EX("e1"))).toBeTruthy(); | |
10 expect(s.contains(EX("e2"))).toBeFalsy(); | |
11 }); | |
12 }); | |
13 | |
14 const uri1 = namedNode("http://example.com/1"); | |
15 const uri2 = namedNode("http://example.com/2"); | |
16 const lit1 = literal("lit1"); | |
17 const lit2 = literal("lit2"); | |
18 const lit3 = literal("lit2", namedNode("#othertype")); | |
19 const lit4 = literal("http://example.com/1"); // sic literal (that looks like a URI) | |
20 | |
21 describe("uniqueSortedTerms", () => { | |
22 it("takes Term arrays", () => { | |
23 const actual = uniqueSortedTerms([lit1] as Term[]); | |
24 expect(actual).toEqual([lit1]); | |
25 }); | |
26 it("takes NamedNode arrays", () => { | |
27 const actual = uniqueSortedTerms([uri1] as NamedNode[]); | |
28 expect(actual).toEqual([uri1]); | |
29 }); | |
30 it("dedups URIs", () => { | |
31 expect(uniqueSortedTerms([uri1, uri1, uri2])).toEqual([uri1, uri2]); | |
32 }); | |
33 it("sorts URIs", () => { | |
34 expect(uniqueSortedTerms([uri2, uri1])).toEqual([uri1, uri2]); | |
35 }); | |
36 it("dedups literals", () => { | |
37 expect(uniqueSortedTerms([lit1, lit2, lit2, lit3, lit3])).toEqual([ | |
38 lit1, | |
39 lit2, | |
40 lit3, | |
41 ]); | |
42 }); | |
43 it("sorts literals", () => { | |
44 expect(uniqueSortedTerms([lit3, lit2, lit1])).toEqual([lit1, lit2, lit3]); | |
45 }); | |
46 it("doesn't confuse literal URI strings", () => { | |
47 expect(uniqueSortedTerms([uri1, lit4])).toEqual([lit4, uri1]); | |
48 }); | |
49 }); |