From 44c68594acf81e96845a54d273e25ecbed5348cb Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Sun, 30 Apr 2023 18:30:43 +0200 Subject: [PATCH 1/2] chore: test regex behavior --- __test_utils__/util.ts | 6 ++++++ data/regex.ts | 15 +++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 data/regex.ts diff --git a/__test_utils__/util.ts b/__test_utils__/util.ts index fc736688..94964ea7 100644 --- a/__test_utils__/util.ts +++ b/__test_utils__/util.ts @@ -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 @@ -175,6 +176,11 @@ export function universalTests() { expect(store.size).toEqual(2 + 4); }); + it('should execute the n3reasoner on a query string requiring regex', async () => { + const res = await n3reasoner(regexData); + expect(res).toEqual(regexResult); + }); + it('should reject n3reasoner on invalid query', async () => { const res = n3reasoner(dataQuads, 'invalid'); diff --git a/data/regex.ts b/data/regex.ts new file mode 100644 index 00000000..7762ef57 --- /dev/null +++ b/data/regex.ts @@ -0,0 +1,15 @@ +export const data = ` +@prefix : . +@prefix 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 : . +@prefix string: . + + . + . +`; From 0b14782347c3e58f2426c0602db8f5fc65d1caef Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Sun, 30 Apr 2023 18:43:23 +0200 Subject: [PATCH 2/2] chore: add RDFJS regex tests --- __test_utils__/util.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/__test_utils__/util.ts b/__test_utils__/util.ts index 94964ea7..3e6faf5b 100644 --- a/__test_utils__/util.ts +++ b/__test_utils__/util.ts @@ -18,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): ReturnType { switch (args[0]) { @@ -176,10 +178,11 @@ export function universalTests() { expect(store.size).toEqual(2 + 4); }); - it('should execute the n3reasoner on a query string requiring regex', async () => { - const res = await n3reasoner(regexData); - expect(res).toEqual(regexResult); - }); + 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');