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

chore: test regex behavior #278

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions __test_utils__/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DataFactory, Parser, Store } from 'n3';
import { data, dataStar, query, queryAll, result } from '../data/socrates';
import { n3reasoner } from '../dist';
import { data as blogicData, result as blogicResult } from '../data/blogic';
import { data as regexData, result as regexResult } from '../data/regex';

const parser = new Parser({ format: 'text/n3' });
// Workaround for https://github.com/rdfjs/N3.js/issues/324
Expand All @@ -17,6 +18,8 @@ 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 regexQuads = parser.parse(regexData);
export const regexResultQuads = parser.parse(regexResult);

export function mockFetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {
switch (args[0]) {
Expand Down Expand Up @@ -175,6 +178,12 @@ export function universalTests() {
expect(store.size).toEqual(2 + 4);
});

it('should execute the n3reasoner on a query string requiring regex',
() => expect(n3reasoner(regexData)).resolves.toEqual(regexResult));

it('should execute the n3reasoner on a query string requiring regex using RDFJS quads',
() => expect(n3reasoner(regexQuads)).resolves.toBeRdfIsomorphic(regexResultQuads));

it('should reject n3reasoner on invalid query', async () => {
const res = n3reasoner(dataQuads, 'invalid');

Expand Down
15 changes: 15 additions & 0 deletions data/regex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const data = `
@prefix : <urn:example:> .
@prefix string: <http://www.w3.org/2000/10/swap/string#>.

{"abracadabra" string:matches "(a|b|r|c|d)+"} => {:test1 :is :ok}.
{"2023" string:matches "[0-9]{4}"} => {:test2 :is :ok}.
`;

export const result = `
@prefix : <urn:example:>.
@prefix string: <http://www.w3.org/2000/10/swap/string#>.

<urn:example:test1> <urn:example:is> <urn:example:ok>.
<urn:example:test2> <urn:example:is> <urn:example:ok>.
`;