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

test log:semantics #314

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 11 additions & 4 deletions __test_utils__/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Quad } from '@rdfjs/types';
import 'jest-rdf';
import { DataFactory, Parser, Store } from 'n3';
import { data, dataStar, query, queryAll, result } from '../data/socrates';
import { querySemantics, dataSemantics, resultSemantics } from '../data/semantics';
import { n3reasoner } from '../dist';
import { data as blogicData, result as blogicResult } from '../data/blogic';
import { data as regexData, result as regexResult } from '../data/regex';
Expand All @@ -18,6 +19,9 @@ export const dataQuads = parser.parse(data);
export const dataStarQuads = parser.parse(dataStar);
export const resultQuads = parser.parse(result);
export const resultBlogicQuads = parser.parse(blogicResult);
export const querySemanticsQuads = parser.parse(querySemantics);
export const dataSemanticsQuads = parser.parse(dataSemantics);
export const resultSemanticsQuads = parser.parse(resultSemantics);

export function mockFetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {
switch (args[0]) {
Expand Down Expand Up @@ -85,6 +89,10 @@ export function universalTests() {
n3reasoner(dataQuads, queryQuads, { output: undefined }),
).resolves.toBeRdfIsomorphic(resultQuads));

it('should execute the n3reasoner with log:semantics [quad input quad output] [output: undefined]', () => expect<Promise<Quad[]>>(
n3reasoner(dataSemanticsQuads, querySemanticsQuads, { output: undefined }),
).resolves.toBeRdfIsomorphic(resultSemanticsQuads));

it('should execute the built-in "log:uuid".', async () => {
const queryString = `@prefix : <urn:example:> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
Expand All @@ -100,10 +108,9 @@ export function universalTests() {
const outputQuads = parser.parse(output);
expect(outputQuads.length).toBe(1);
const createdUUID = outputQuads[0].object.value;
const uuidRegexMatch = createdUUID.match(/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gm)
expect(uuidRegexMatch).not.toBe(null)
expect(uuidRegexMatch![0]).toBe(createdUUID)

const uuidRegexMatch = createdUUID.match(/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gm);
expect(uuidRegexMatch).not.toBe(null);
expect(uuidRegexMatch![0]).toBe(createdUUID);
})

it('should execute the n3reasoner [quad input quad output] [output: deductive_closure]', () => expect<Promise<string>>(
Expand Down
32 changes: 32 additions & 0 deletions data/semantics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const querySemantics = `
@prefix : <http://ex.org/> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .

{ :test :people ?people } => { :test :people ?people } .
`;

export const dataSemantics = `
@prefix : <http://ex.org/> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .

{
<https://raw.githubusercontent.com/w3c/N3/master/tests/N3Tests/people.n3> log:semantics ?people .
}
=>
{
:test :people ?people
}
.
`;

export const resultSemantics = `
@prefix : <http://ex.org/>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix ns1: <http://example.com/>.

:test :people {
ns1:william a ns1:Person.
ns1:doerthe a ns1:Person.
ns1:gregg a ns1:Person.
}.
`;
Loading