-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
engine.test.ts
75 lines (66 loc) · 2.13 KB
/
engine.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { assertEquals, assertRejects } from "./test_deps.ts";
import { QueryEngine } from "../library/engine/query_engine.ts";
import { type Context } from "../library/rdf.ts";
const engine = new QueryEngine();
const context: Context = { sources: ["https://dbpedia.org/sparql"] };
Deno.test("Boolean query with TRUE outcome", async () => {
const response = await engine.queryBoolean("ASK { ?s ?p ?o }", context);
assertEquals(response, true);
});
Deno.test("Boolean query with FALSE outcome", async () => {
const response = await engine.queryBoolean(
"ASK { ?s <https://probablynonexistentnode> ?o }",
context,
);
console.log("RESPONSE", response);
assertEquals(response, false);
});
Deno.test("Invalid boolean query", async () => {
await assertRejects(() => {
return engine.queryBoolean(
"CONSTRUCT WHERE { ?s ?p ?o } LIMIT 1",
context,
);
}, "Non-boolean query should fail");
});
Deno.test("Bindings query", async () => {
const q = `SELECT ?x ?y WHERE { BIND("x" as ?x) BIND("y" as ?y) }`;
const stream = await engine.queryBindings(
q,
context,
);
const bindings = stream.read();
assertEquals(bindings?.get("x")?.value, "x");
assertEquals(bindings?.get("y")?.value, "y");
assertEquals(bindings?.get("z")?.value, undefined);
assertEquals(stream.read(), null);
});
Deno.test("Invalid bindings query", async () => {
await assertRejects(() => {
return engine.queryBindings(
"ASK { ?s ?p ?o }",
context,
);
}, "Non-bindings query should fail");
});
Deno.test("Quads query", async () => {
const q =
`CONSTRUCT { <https://x/x> <https://x/y> <https://x/z> } WHERE { ?s ?p ?o } LIMIT 1`;
const stream = await engine.queryQuads(
q,
context,
);
const quad = stream.read();
assertEquals(quad?.subject.value, "https://x/x");
assertEquals(quad?.predicate.value, "https://x/y");
assertEquals(quad?.object.value, "https://x/z");
assertEquals(stream.read(), null);
});
Deno.test("Invalid quads query", async () => {
await assertRejects(() => {
return engine.queryQuads(
"ASK { ?s ?p ?o }",
context,
);
}, "Non-quads query should fail");
});