Created
March 21, 2022 06:57
-
-
Save BruJu/120776916dbca5eb63477c5fde66a5f9 to your computer and use it in GitHub Desktop.
Test from manifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Test parser from the W3C test suite manifest | |
describe("Tests from manifest", () => { | |
// const manifestUrl = "https://www.w3.org/2013/rdf-mt-tests/manifest.ttl"; | |
const manifestContent = fs.readFileSync(path.join(__dirname, "w3c-test-manifest.ttl"), "utf8"); | |
const manifestQuads = new n3.Parser().parse(manifestContent); | |
let tests = new TermMap<RDF.Quad_Subject, ManifestedTest>(); | |
function getManifest(subject: RDF.Quad_Subject) { | |
return getWithDefault(tests, subject, () => ({ | |
name: "???", | |
entailmentRegime: "???", | |
action: null, | |
shouldBeExecuted: false | |
})); | |
} | |
const mfPrefix = "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#"; | |
const mfAction = n3.DataFactory.namedNode(mfPrefix + "action"); | |
const mfName = n3.DataFactory.namedNode(mfPrefix + "name"); | |
const mfResult = n3.DataFactory.namedNode(mfPrefix + "result"); | |
if (manifestQuads === undefined) console.log("ettooo"); | |
for (const quad of manifestQuads) { | |
if (quad.predicate.equals(mfResult)) { | |
if (quad.object.termType !== "Literal") { | |
getManifest(quad.subject).shouldBeExecuted = true; | |
} | |
} else if (quad.predicate.equals(mfAction)) { | |
getManifest(quad.subject).action = quad.object; | |
} else if (quad.predicate.equals(mfName)) { | |
getManifest(quad.subject).name = quad.object.value; | |
} | |
} | |
let ran = 2; | |
for (const manifest of tests.values()) { | |
if (manifest.action !== null && manifest.shouldBeExecuted) { | |
//console.log("do", manifest); | |
--ran; | |
//console.log(manifest.action!.value); | |
//console.log(content); | |
it(manifest.name, async () => { | |
const content = (await axios.get("https://www.w3.org/2013/rdf-mt-tests/" + manifest.action!.value)).data; | |
const byN3 = new n3.Parser().parse(content); | |
const byST = parseFullDocument(content); | |
const areIsomorphic = isomorphic(byN3, byST); | |
if (!areIsomorphic) { | |
console.log("================"); | |
console.log("================"); | |
console.log(content); | |
console.log("================"); | |
} | |
assert.ok(areIsomorphic); | |
}); | |
} | |
} | |
}); | |
type ManifestedTest = { | |
name: string; | |
action: RDF.Quad_Object | null; | |
shouldBeExecuted: boolean; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment