Skip to content

Commit 6e13db4

Browse files
Test undefined
1 parent 5b4d9e5 commit 6e13db4

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/DatasetWrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { DataFactory, DatasetCore, Quad, Term } from "@rdfjs/types"
2-
import type {ITermWrapperConstructor } from "./type/ITermWrapperConstructor.js"
2+
import type { ITermWrapperConstructor } from "./type/ITermWrapperConstructor.js"
33

44
import { RDF } from "./vocabulary/RDF.js"
55

src/TermWrapper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class TermWrapper {
4444
this.dataset.delete(q)
4545
}
4646

47+
// TODO: TermMapping undefined: Return after deleting quads if undefined
4748
if (value === undefined) {
4849
return
4950
}
@@ -54,6 +55,7 @@ export class TermWrapper {
5455
return // TODO: throw error?
5556
}
5657

58+
// TODO: TermMapping undefined: the term mapping is not invoked if undefined
5759
const o = termMapping(value, this.dataset, this.factory)
5860

5961
if (o === undefined) {

src/mapping/TermMapping.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,30 @@ import { TermWrapper } from "../TermWrapper.js"
99
* Generic Term Wrapper factories
1010
*/
1111
export namespace TermMapping {
12+
// TODO: consider not allowing null value here, should be taken care of upstream
1213
export function stringToLiteral(value: string | undefined, dataset: DatasetCore, factory: DataFactory): TermWrapper | undefined {
13-
// TODO: Check setting of undefined values
14+
// TODO: Check I don't think there's a way to hit this currently
15+
// TODO: Check, this would probably only be hit if the TermWrapper method is bogus (see overwrite nullable)
1416
if (value === undefined) {
1517
return undefined
1618
}
1719

1820
return new TermWrapper(factory.literal(value), dataset, factory)
1921
}
2022

23+
// TODO: consider not allowing null value here, should be taken care of upstream
2124
export function dateToLiteral(value: Date | undefined, dataset: DatasetCore, factory: DataFactory): TermWrapper | undefined {
25+
// TODO: CHeck, this would probably only be hit if the TermWrapper method is bogus (see overwrite nullable)
2226
if (value === undefined) {
2327
return undefined
2428
}
2529

2630
return new TermWrapper(factory.literal(value.toISOString(), factory.namedNode("http://www.w3.org/2001/XMLSchema#date")), dataset, factory)
2731
}
2832

33+
// TODO: consider not allowing null value here, should be taken care of upstream
2934
export function numberToLiteral(value: number | undefined, dataset: DatasetCore, factory: DataFactory): TermWrapper | undefined {
35+
// TODO: CHeck, this would probably only be hit if the TermWrapper method is bogus (see overwrite nullable)
3036
if (value === undefined) {
3137
return undefined
3238
}
@@ -35,7 +41,9 @@ export namespace TermMapping {
3541
return new TermWrapper(factory.literal(value.toString(), factory.namedNode("http://www.w3.org/2001/XMLSchema#double")), dataset, factory)
3642
}
3743

44+
// TODO: consider not allowing null value here, should be taken care of upstream
3845
export function stringToIri(value: string | undefined, dataset: DatasetCore, factory: DataFactory): TermWrapper | undefined {
46+
// TODO: CHeck, this would probably only be hit if the TermWrapper method is bogus (see overwrite nullable)
3947
if (value === undefined) {
4048
return undefined
4149
}

test/unit/term_wrapper.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ describe("Term Wrappers", async () => {
8787
assert.equal(parent.hasString, "o1 edited")
8888
})
8989

90+
it("set single literal to undefined throws", () => {
91+
assert.throws(() => { parent.hasString = undefined as any })
92+
})
93+
9094
it("set single nullable literal to string", () => {
9195
parent.hasNullableString = "o2 edited"
9296
assert.equal(parent.hasNullableString, "o2 edited")

0 commit comments

Comments
 (0)