diff --git a/__tests__/Conformance-test.js b/__tests__/Conformance-test.js index f46ebb4..66252c3 100644 --- a/__tests__/Conformance-test.js +++ b/__tests__/Conformance-test.js @@ -29,14 +29,17 @@ describe('Testing each extended conformance file', () => { const shaclc = fs.readFileSync(path.join(__dirname, 'extended', file)).toString(); const ttl = fs.readFileSync(path.join(__dirname, 'extended', file.replace('.shaclc', '.ttl'))).toString(); - expect( - (new Parser()).parse(shaclc, { extendedSyntax: true }) - ).toBeRdfIsomorphic( - (new N3.Parser()).parse(ttl) - ) + const res = (new Parser()).parse(shaclc, { extendedSyntax: true }); - expect( - () => (new Parser()).parse(shaclc) - ).toThrowError(); + expect(res).toBeRdfIsomorphic((new N3.Parser()).parse(ttl)) + expect(res.prefixes).toEqual({ + rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + rdfs: 'http://www.w3.org/2000/01/rdf-schema#', + sh: 'http://www.w3.org/ns/shacl#', + xsd: 'http://www.w3.org/2001/XMLSchema#', + ex: 'http://example.org/test#' + }) + + expect(() => (new Parser()).parse(shaclc)).toThrowError(); }); }); diff --git a/lib/index.d.ts b/lib/index.d.ts index 8111f13..6c327ef 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -4,4 +4,4 @@ export interface ParseOptions { extendedSyntax?: boolean; } -export declare function parse(str: string, options?: ParseOptions): Quad[]; +export declare function parse(str: string, options?: ParseOptions): Quad[] & { prefixes: Record }; diff --git a/lib/index.js b/lib/index.js index 1ff73bb..8cb2c9a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,6 +20,7 @@ class Parser { const arr = [] this._parser.Parser.onQuad = (quad) => { arr.push(quad) }; this._parser.parse(str); + arr.prefixes = this._parser.Parser.prefixes; return arr; } }