Skip to content

Commit 4d6666c

Browse files
committed
Updated testSuite
1 parent b977ec4 commit 4d6666c

File tree

1,033 files changed

+19429
-9017
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,033 files changed

+19429
-9017
lines changed

src/test/resources/shexTest/LICENSE

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
This work is being provided by the copyright holders under the following license.
2+
3+
License
4+
5+
By obtaining and/or copying this work, you (the licensee) agree that you have
6+
read, understood, and will comply with the following terms and conditions.
7+
8+
Permission to copy, modify, and distribute this work, with or without
9+
modification, for any purpose and without fee or royalty is hereby granted,
10+
provided that you include the following on ALL copies of the work or portions
11+
thereof, including modifications:
12+
13+
* The full text of this NOTICE in a location viewable to users of the
14+
redistributed or derivative work.
15+
16+
* Any pre-existing intellectual property disclaimers, notices, or terms and
17+
conditions. If none exist, the W3C Software and Document Short Notice should be
18+
included.
19+
20+
* Notice of any changes or modifications, through a copyright statement on the
21+
new code or document such as "This software or document includes material
22+
copied from or derived from [title and URI of the W3C document]. Copyright ©
23+
[YEAR] W3C® (MIT, ERCIM, Keio, Beihang)."
24+
25+
Disclaimers
26+
27+
THIS WORK IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
28+
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF
29+
MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE
30+
SOFTWARE OR DOCUMENT WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
31+
TRADEMARKS OR OTHER RIGHTS.
32+
33+
COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR
34+
CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENT.
35+
36+
The name and trademarks of copyright holders may NOT be used in advertising or
37+
publicity pertaining to the work without specific, written prior
38+
permission. Title to copyright in this work will at all times remain with
39+
copyright holders.

src/test/resources/shexTest/Makefile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
test: Manifests ShExTests
2+
3+
Manifests: schemas/manifest.jsonld validation/manifest.jsonld negativeSyntax/manifest.jsonld negativeStructure/manifest.jsonld
4+
5+
schemas/manifest.jsonld: schemas/manifest.ttl
6+
cd schemas && make manifest.jsonld
7+
8+
validation/manifest.jsonld: validation/manifest.ttl
9+
cd validation && make manifest.jsonld
10+
11+
negativeSyntax/manifest.jsonld: negativeSyntax/manifest.ttl
12+
cd negativeSyntax && make manifest.jsonld
13+
14+
negativeStructure/manifest.jsonld: negativeStructure/manifest.ttl
15+
cd negativeStructure && make manifest.jsonld
16+
17+
ShExTests: ShExJTests ShExVTests
18+
19+
ShExJTests: doc/ShExJ.jsg
20+
(ls schemas/*.json | grep -vE '(coverage|representationTests)\.json' | xargs \
21+
`npm bin`/json-grammar doc/ShExJ.jsg)
22+
23+
ShExVTests: doc/ShExV.jsg
24+
`npm bin`/json-grammar doc/ShExV.jsg validation/*.val
25+
`npm bin`/json-grammar doc/ShExV.jsg validation/*.err
26+

src/test/resources/shexTest/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ These tests should raise errors when parsed, noting the rule about nested `Value
2828

2929
### `validation`
3030

31-
* Validation tests in a manifest (Turtle - `manifest.ttl`, [ShExJ][http://shex.io/shex-primer/ShExJ) - `manifest.json`).
31+
* Validation tests in a manifest (Turtle - `manifest.ttl`, [ShExJ](http://shex.io/shex-semantics/#shexj) ([obselete primer](http://shex.io/shex-primer-20170327/ShExJ)) - `manifest.json`).
3232
* Input data in Turtle (`.ttl`).
33-
* [ShEx Results format](http://shex.io/shex-primer/ShExJ) (`.val`).
33+
* Validation returns a [ShapeMap](https://shexspec.github.io/shape-map/) capturing which node/shape pairs conform. The expected conformance or non-conformance is captured in the test format as a `ValidationTest` or `ValidationFailure`.
3434

3535
A ShEx validator is `logic-conformant` when it returns success for the tests of type `ValidationTest` and failure for the tests of type `ValidationFailure`.
3636
A ShEx validator is `result-conformant` (experimental) when it executes as `ValidationTest` and produces the same result structure as produced by this procedure:

src/test/resources/shexTest/bin/genJSON.js

+72-60
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@ function report (msg) {
2929
++errors;
3030
}
3131
}
32+
function jsonLdId (t) {
33+
switch (t.termType) {
34+
case "NamedNode": return t.value;
35+
case "BlankNode": return "_:" + t.value;
36+
default: throw Error(`unknown termType in ${JSON.stringify(t)}`);
37+
}
38+
}
3239

3340
var fs = require('fs');
34-
var path = require("path");
41+
var Path = require("path");
3542
var N3 = require("n3");
36-
var parser = N3.Parser({blankNodePrefix: ""});
43+
var parser = new N3.Parser({blankNodePrefix: ""});
3744
var util = N3.Util;
38-
var store = N3.Store();
45+
var store = new N3.Store();
3946
//var json = fs.readFileSync(args[0]).toString();
4047

4148
var P = {
@@ -46,33 +53,36 @@ var P = {
4653
"sx": "https://shexspec.github.io/shexTest/ns#"
4754
};
4855

49-
var testDir = path.basename(path.dirname(path.resolve(args[0])));
56+
var testDir = Path.basename(Path.dirname(Path.resolve(args[0])));
5057
var basePath = "https://raw.githubusercontent.com/shexSpec/shexTest/master/";
5158
var dirPath = basePath + testDir + '/';
59+
function RelPath (p) {
60+
return Path.relative(dirPath, p);
61+
}
5262
var apparentBase = dirPath + "manifest";
5363

5464
parser.parse(
5565
"@base <" + apparentBase + "> .\n"+
5666
fs.readFileSync(args[0], "utf8"),
57-
function (error, triple, prefixes) {
67+
function (error, quad, prefixes) {
5868
if (error) {
5969
error.message = "Error parsing " + args[0] + ": " + error.message;
6070
throw error;
6171
}
62-
if (triple)
63-
store.addTriple(triple)
72+
if (quad)
73+
store.addQuad(quad)
6474
else
6575
genText();
6676
});
6777

6878
/** expandCollection - N3.js utility to return an rdf collection's elements.
6979
*/
7080
function expandCollection (h) {
71-
if (store.find(h.object, "rdf:first", null).length) {
81+
if (store.getQuads(h.object, P.rdf + "first", null).length) {
7282
var ret = [];
73-
while (h.object !== "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil") {
74-
ret.push(store.find(h.object, "rdf:first", null)[0].object);
75-
h = store.find(h.object, "rdf:rest", null)[0];
83+
while (h.object.value !== "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil") {
84+
ret.push(store.getQuads(h.object, P.rdf + "first", null)[0].object);
85+
h = store.getQuads(h.object, P.rdf + "rest", null)[0];
7686
}
7787
return ret;
7888
} else {
@@ -90,16 +100,14 @@ function genText () {
90100
"@graph": g
91101
};
92102

93-
store.addPrefixes(P);
94-
95-
var manifest = store.find(null, "rdf:type", "mf:Manifest")[0].subject;
96-
var manifestComment = util.getLiteralValue(store.find(manifest, "rdfs:comment", null)[0].object);
103+
var manifest = store.getQuads(null, P.rdf + "type", P.mf + "Manifest")[0].subject;
104+
var manifestComment = store.getQuads(manifest, P.rdfs + "comment", null)[0].object.value;
97105
var entries = [];
98106
var knownMissing = {}; // record missing files.
99-
var head = store.find(manifest, "mf:entries", null)[0].object;
100-
while (head !== P.rdf + "nil") {
101-
entries.push(store.find(head, "rdf:first", null)[0].object);
102-
head = store.find(head, "rdf:rest", null)[0].object;
107+
var head = store.getQuads(manifest, P.mf + "entries", null)[0].object;
108+
while (head.value !== P.rdf + "nil") {
109+
entries.push(store.getQuads(head, P.rdf + "first", null)[0].object.value);
110+
head = store.getQuads(head, P.rdf + "rest", null)[0].object;
103111
}
104112
var unmatched = entries.reduce(function (ret, ent) {
105113
ret[ent] = true;
@@ -113,15 +121,15 @@ function genText () {
113121
"@id": "",
114122
"@type": "mf:Manifest",
115123
"rdfs:comment": manifestComment,
116-
"entries": store.find(null, "rdf:type", null).filter(function (t) {
117-
var ret = expectedTypes.indexOf(t.object) !== -1;
124+
"entries": store.getQuads(null, P.rdf + "type", null).filter(function (t) {
125+
var ret = expectedTypes.indexOf(t.object.value) !== -1;
118126
if (ret === false &&
119-
t.object !== P.mf + "Manifest") {
120-
report("test " + t.subject + " has unexpected type " + t.object);
127+
t.object.value !== P.mf + "Manifest") {
128+
report("test " + t.subject.value + " has unexpected type " + t.object.value);
121129
}
122130
return ret;
123131
}).map(function (t) {
124-
return [t.subject, t.object];
132+
return [t.subject.value, t.object.value];
125133
}).filter(function (t) {
126134
var ret = entries.indexOf(t[0]) !== -1;
127135
if (ret === false) {
@@ -136,18 +144,18 @@ function genText () {
136144
-1;
137145
}).map(function (st) {
138146
var s = st[0], t = st[1];
139-
var testName = util.getLiteralValue(store.find(s, "mf:name", null)[0].object);
140-
var testType = store.find(s, "rdf:type", null)[0].object.replace(P.sht, '');
147+
var testName = store.getQuads(s, P.mf + "name", null)[0].object.value;
148+
var testType = store.getQuads(s, P.rdf + "type", null)[0].object.value.replace(P.sht, '');
141149
var expectedName = s.substr(apparentBase.length+1);
142150
if (WARN && testName !== expectedName) {
143151
report("expected label \"" + expectedName + "\" ; got \"" + testName + "\"");
144152
}
145-
var actionTriples = store.find(s, "mf:action", null);
153+
var actionTriples = store.getQuads(s, P.mf + "action", null);
146154
function exists (filename) {
147-
var filepath = path.join(__dirname, "../" + testDir + '/' + filename);
155+
var filepath = Path.join(__dirname, "../" + testDir + '/' + filename);
148156
if (WARN && !fs.existsSync(filepath) && !(filepath in knownMissing)) {
149-
report("non-existent file: " + filepath.substr(dirPath.length) + " is missing " + path.relative(process.cwd(), filepath));
150-
knownMissing[filepath] = path.relative(process.cwd(), filepath);
157+
report("non-existent file: " + RelPath(filepath) + " is missing " + Path.relative(process.cwd(), filepath));
158+
knownMissing[filepath] = Path.relative(process.cwd(), filepath);
151159
}
152160
return filename;
153161
}
@@ -158,19 +166,23 @@ function genText () {
158166
// Representation/Syntax/Structure tests
159167
return [
160168
// ["rdf" , "type" , function (v) { return v.substr(P.sht.length); }],
161-
[s, "mf" , "name" , function (v) { return util.getLiteralValue(v[0]); }],
169+
[s, "mf" , "name" , function (v) { return v[0].value; }],
162170
[s, "sht", "trait" , function (v) {
163171
return v.map(function (x) {
164-
return x.substr(P.sht.length);;
165-
});
172+
return x.value.substr(P.sht.length);
173+
}).sort();
166174
}],
167-
//[s, "rdfs" , "comment" , function (v) { return util.getLiteralValue(v[0]); }],
168-
[s, "mf", "status" , function (v) { return "mf:"+v[0].substr(P.mf.length); }],
169-
[s, "sx", "shex", function (v) { return exists(v[0].substr(dirPath.length)); }],
170-
[s, "sx", "json", function (v) { return exists(v[0].substr(dirPath.length)); }],
171-
[s, "sx", "ttl", function (v) { return exists(v[0].substr(dirPath.length)); }],
175+
//[s, "rdfs" , "comment" , function (v) { return (v[0].value; }],
176+
[s, "mf", "status" , function (v) { return "mf:"+v[0].value.substr(P.mf.length); }],
177+
[s, "sx", "shex", function (v) { return exists(RelPath(v[0].value)); }],
178+
[s, "sx", "json", function (v) { return exists(RelPath(v[0].value)); }],
179+
[s, "sx", "ttl", function (v) { return exists(RelPath(v[0].value)); }],
180+
[s, "mf", "startRow" , function (v) { return parseInt(v[0].value); }],
181+
[s, "mf", "startColumn", function (v) { return parseInt(v[0].value); }],
182+
[s, "mf", "endRow" , function (v) { return parseInt(v[0].value); }],
183+
[s, "mf", "endColumn" , function (v) { return parseInt(v[0].value); }],
172184
].reduce(function (ret, row) {
173-
var found = store.findByIRI(row[0], P[row[1]]+row[2], null).map(expandCollection);
185+
var found = store.getQuads(row[0], P[row[1]]+row[2], null).map(expandCollection);
174186
var target = ret;
175187
if (found.length)
176188
target[row[2]] = row[3](found);
@@ -180,44 +192,44 @@ function genText () {
180192
var a = actionTriples[0].object;
181193
return [
182194
// ["rdf" , "type" , function (v) { return v.substr(P.sht.length); }],
183-
[s, "mf" , "name" , function (v) { return util.getLiteralValue(v[0]); }],
195+
[s, "mf" , "name" , function (v) { return v[0].value; }],
184196
[s, "sht", "trait" , function (v) {
185197
return v.map(function (x) {
186-
return x.substr(P.sht.length);;
187-
});
198+
return x.value.substr(P.sht.length);;
199+
}).sort();
188200
}],
189-
[s, "rdfs" , "comment" , function (v) { return util.getLiteralValue(v[0]); }],
190-
[s, "mf", "status" , function (v) { return "mf:"+v[0].substr(P.mf.length); }],
191-
[a, "sht", "schema" , function (v) { return exists("../" + v[0].substr(basePath.length)); } ], // could be more judicious in creating a relative path from an absolute path.
192-
[a, "sht", "shape" , function (v) { return v[0].indexOf(dirPath) === 0 ? v[0].substr(dirPath.length) : v[0]; }],
193-
[a, "sht", "data" , function (v) { return exists(v[0].substr(dirPath.length)); }],
194-
[a, "sht", "map" , function (v) { return exists(v[0].substr(dirPath.length)); }],
201+
[s, "rdfs" , "comment" , function (v) { return v[0].value; }],
202+
[s, "mf", "status" , function (v) { return "mf:"+v[0].value.substr(P.mf.length); }],
203+
[a, "sht", "schema" , function (v) { return exists("../" + v[0].value.substr(basePath.length)); } ], // could be more judicious in creating a relative path from an absolute path.
204+
[a, "sht", "shape" , function (v) { return v[0].value.indexOf(dirPath) === 0 ? RelPath(v[0].value) : jsonLdId(v[0]); }],
205+
[a, "sht", "data" , function (v) { return exists(RelPath(v[0].value)); }],
206+
[a, "sht", "map" , function (v) { return exists(RelPath(v[0].value)); }],
195207
[a, "sht", "focus" , function (v) {
196208
// Focus can be a literal
197209
if (util.isLiteral(v[0])) {
198-
var lang = util.getLiteralLanguage(v[0]);
199-
var dt = util.getLiteralType(v[0]);
200-
var res = {'@value': util.getLiteralValue(v[0])};
210+
var lang = v[0].language;
211+
var dt = v[0].datatype.value;
212+
var res = {'@value': v[0].value};
201213
if (lang.length > 0) {res['@language'] = lang}
202214
if (dt.length > 0) {res['@type'] = dt}
203215
return res;
204216
} else {
205-
return (v[0].indexOf(dirPath) === 0 ? v[0].substr(dirPath.length) : v[0]);
217+
return (v[0].value.indexOf(dirPath) === 0 ? RelPath(v[0].value) : jsonLdId(v[0]));
206218
}
207219
}],
208-
[a, "sht", "semActs" , function (v) { return exists("../" + v[0].substr(basePath.length)); }], // could be more judicious in creating a relative path from an absolute path.
209-
[a, "sht", "shapeExterns" , function (v) { return exists("../" + v[0].substr(basePath.length)); }], // could be more judicious in creating a relative path from an absolute path.
210-
[s, "mf", "result" , function (v) { return exists(v[0].substr(dirPath.length)); }],
220+
[a, "sht", "semActs" , function (v) { return exists("../" + v[0].value.substr(basePath.length)); }], // could be more judicious in creating a relative path from an absolute path.
221+
[a, "sht", "shapeExterns" , function (v) { return exists("../" + v[0].value.substr(basePath.length)); }], // could be more judicious in creating a relative path from an absolute path.
222+
[s, "mf", "result" , function (v) { return exists(RelPath(v[0].value)); }],
211223
[s, "mf", "extensionResults" , function (v) {
212224
return v[0].map(function (x) {
213225
return {
214-
extension: store.find(x, "mf:extension", null)[0].object,
215-
prints: util.getLiteralValue(store.find(x, "mf:prints", null)[0].object)
226+
extension: store.getQuads(x, P.mf + "extension", null)[0].object.value,
227+
prints: store.getQuads(x, P.mf + "prints", null)[0].object.value
216228
};
217229
});
218230
}]
219231
].reduce(function (ret, row) {
220-
var found = store.findByIRI(row[0], P[row[1]]+row[2], null).map(expandCollection);
232+
var found = store.getQuads(row[0], P[row[1]]+row[2], null).map(expandCollection);
221233
var target = row[0] === s ? ret : row[0] === a ? ret.action : ret.extensionResults;
222234
if (found.length)
223235
target[row[2]] = row[3](found);
@@ -231,9 +243,9 @@ function genText () {
231243
}
232244
if (!errors) {
233245
if (OUTFILE) {
234-
fs.writeFileSync(OUTFILE, JSON.stringify(ret, null, " "));
246+
fs.writeFileSync(OUTFILE, JSON.stringify(ret, null, " ") + "\n");
235247
} else {
236-
console.log(JSON.stringify(ret, null, " "));
248+
console.log(JSON.stringify(ret, null, " ") + "\n");
237249
}
238250
process.exit(0);
239251
} else {

0 commit comments

Comments
 (0)