Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add various list + base tests. #390

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions tests/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,150 @@ describe('other toRDF tests', () => {
done();
});
});

it.only('should handle list good @context @base', async () => {
const doc = {
"@context": {
"@base": "ex:",
"list": {
"@id": "foo:bar",
"@container": "@list",
"@type": "@id"
}
},
"list": [
"test"
]
};
const rdf = await jsonld.toRDF(doc, {
format: 'application/n-quads'
});
assert.equal(
rdf,
'_:b0 <foo:bar> _:b1 .\n' +
'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <ex:test> .\n' +
'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .\n');
});

it.only('should handle list bad @context @base', async () => {
const doc = {
"@context": {
"@base": "::",
"list": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't invalid, as ':' is a valid char, which is a component of segment-nz. When expanding relative to the document base, it becomes https://w3c.github.io/json-ld-api/tests/toRdf/::, which is valid.

I'll pick something else.

"@id": "foo:bar",
"@container": "@list",
"@type": "@id"
}
},
"list": [
"test"
]
};
const rdf = await jsonld.toRDF(doc, {
format: 'application/n-quads'
});
assert.equal(
rdf,
'_:b0 <foo:bar> _:b1 .\n' +
//'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <test> .\n' +
'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .\n');
});

it.only('should handle list empty base option', async () => {
const doc = {
"@context": {
"list": {
"@id": "foo:bar",
"@container": "@list",
"@type": "@id"
}
},
"list": [
"test"
]
};
const rdf = await jsonld.toRDF(doc, {
base: '',
format: 'application/n-quads'
});
assert.equal(
rdf,
'_:b0 <foo:bar> _:b1 .\n' +
//'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <test> .\n' +
'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .\n');
});

it.only('should handle list null base option', async () => {
const doc = {
"@context": {
"list": {
"@id": "foo:bar",
"@container": "@list",
"@type": "@id"
}
},
"list": [
"test"
]
};
const rdf = await jsonld.toRDF(doc, {
base: null,
format: 'application/n-quads'
});
assert.equal(
rdf,
'_:b0 <foo:bar> _:b1 .\n' +
//'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <test> .\n' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, and others, might be controversial. Certainly, the spec says that the base option overrides the input document's IRI, but this would correspond to the RFC3986 5.1.2 Base URI from the Encapsulating Entity, and following their hierarchy, an empty value would typically be made absolute by resaving against the Retrieval URI or the default base URI. It could be that it's just that the spec wording is muddy. Does it make sense to set the base option to anything other than an absolute URL?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, arguably, the API should ignore a base option which is not a valid IRI (meaning absolute). The option is described as setting the base IRI, and base IRI is described as an IRI, meaning absolute:

The base IRI is an IRI established in the context, or is based on the JSON-LD document location. The base IRI is used to turn relative IRI references into IRIs.

We don't describe what to do for invalid options, so it's a bit of a gray area.

'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .\n');
});

it.only('should handle list empty @context @base', async () => {
const doc = {
"@context": {
"@base": "",
"list": {
"@id": "foo:bar",
"@container": "@list",
"@type": "@id"
}
},
"list": [
"test"
]
};
const rdf = await jsonld.toRDF(doc, {
format: 'application/n-quads'
});
assert.equal(
rdf,
'_:b0 <foo:bar> _:b1 .\n' +
//'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <test> .\n' +
'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .\n');
});

it.only('should handle list null @context @base', async () => {
const doc = {
"@context": {
"@base": null,
"list": {
"@id": "foo:bar",
"@container": "@list",
"@type": "@id"
}
},
"list": [
"test"
]
};
const rdf = await jsonld.toRDF(doc, {
format: 'application/n-quads'
});
assert.equal(
rdf,
'_:b0 <foo:bar> _:b1 .\n' +
//'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <test> .\n' +
'_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .\n');
});
});

describe('other fromRDF tests', () => {
Expand Down