11import "jest-rdf" ;
2+ import { RdfParser } from "../lib/RdfParser" ;
3+
4+ import { rdfParser } from ".." ;
5+
26const stringToStream = require ( 'streamify-string' ) ;
37const arrayifyStream = require ( 'arrayify-stream' ) ;
48const quad = require ( 'rdf-quad' ) ;
5- import { RdfParser } from "../lib/RdfParser" ;
6-
7- import parser from ".." ;
89
910describe ( 'parser' , ( ) => {
1011 it ( 'should be an RdfParser instance' , ( ) => {
11- expect ( parser ) . toBeInstanceOf ( RdfParser ) ;
12+ expect ( rdfParser ) . toBeInstanceOf ( RdfParser ) ;
1213 } ) ;
1314
1415 it ( 'should get all content types' , async ( ) => {
15- expect ( ( await parser . getContentTypes ( ) ) . sort ( ) ) . toEqual ( [
16+ expect ( ( await rdfParser . getContentTypes ( ) ) . sort ( ) ) . toEqual ( [
1617 'application/ld+json' ,
1718 'application/json' ,
1819 'text/html' ,
@@ -32,7 +33,7 @@ describe('parser', () => {
3233 } ) ;
3334
3435 it ( 'should get all prioritized content types' , async ( ) => {
35- expect ( await parser . getContentTypesPrioritized ( ) ) . toEqual ( {
36+ expect ( await rdfParser . getContentTypesPrioritized ( ) ) . toEqual ( {
3637 'application/json' : 0.45 ,
3738 'application/ld+json' : 0.9 ,
3839 'application/n-quads' : 1 ,
@@ -55,31 +56,31 @@ describe('parser', () => {
5556 const stream = stringToStream ( `
5657<http://ex.org/s> <http://ex.org/p> <http://ex.org/o1>, <http://ex.org/o2>.
5758` ) ;
58- return expect ( ( ) => parser . parse ( stream , < any > { } ) )
59+ return expect ( ( ) => rdfParser . parse ( stream , < any > { } ) )
5960 . toThrow ( new Error ( 'Missing \'contentType\' or \'path\' option while parsing.' ) ) ;
6061 } ) ;
6162
6263 it ( 'should fail to parse with path without extension' , ( ) => {
6364 const stream = stringToStream ( `
6465<http://ex.org/s> <http://ex.org/p> <http://ex.org/o1>, <http://ex.org/o2>.
6566` ) ;
66- return expect ( ( ) => parser . parse ( stream , { path : 'abc' } ) )
67+ return expect ( ( ) => rdfParser . parse ( stream , { path : 'abc' } ) )
6768 . toThrow ( new Error ( 'No valid extension could be detected from the given \'path\' option: \'abc\'' ) ) ;
6869 } ) ;
6970
7071 it ( 'should fail to parse with path with unknown extension' , ( ) => {
7172 const stream = stringToStream ( `
7273<http://ex.org/s> <http://ex.org/p> <http://ex.org/o1>, <http://ex.org/o2>.
7374` ) ;
74- return expect ( ( ) => parser . parse ( stream , { path : 'abc.unknown' } ) )
75+ return expect ( ( ) => rdfParser . parse ( stream , { path : 'abc.unknown' } ) )
7576 . toThrow ( new Error ( 'No valid extension could be detected from the given \'path\' option: \'abc.unknown\'' ) ) ;
7677 } ) ;
7778
7879 it ( 'should parse text/turtle without baseIRI' , ( ) => {
7980 const stream = stringToStream ( `
8081<http://ex.org/s> <http://ex.org/p> <http://ex.org/o1>, <http://ex.org/o2>.
8182` ) ;
82- return expect ( arrayifyStream ( parser . parse ( stream , { contentType : 'text/turtle' } ) ) ) . resolves . toBeRdfIsomorphic ( [
83+ return expect ( arrayifyStream ( rdfParser . parse ( stream , { contentType : 'text/turtle' } ) ) ) . resolves . toBeRdfIsomorphic ( [
8384 quad ( 'http://ex.org/s' , 'http://ex.org/p' , 'http://ex.org/o1' ) ,
8485 quad ( 'http://ex.org/s' , 'http://ex.org/p' , 'http://ex.org/o2' ) ,
8586 ] ) ;
@@ -89,7 +90,7 @@ describe('parser', () => {
8990 const stream = stringToStream ( `
9091<http://ex.org/s> <http://ex.org/p> <http://ex.org/o1>, <http://ex.org/o2>.
9192` ) ;
92- return expect ( arrayifyStream ( parser . parse ( stream , { path : 'myfile.ttl' } ) ) ) . resolves . toBeRdfIsomorphic ( [
93+ return expect ( arrayifyStream ( rdfParser . parse ( stream , { path : 'myfile.ttl' } ) ) ) . resolves . toBeRdfIsomorphic ( [
9394 quad ( 'http://ex.org/s' , 'http://ex.org/p' , 'http://ex.org/o1' ) ,
9495 quad ( 'http://ex.org/s' , 'http://ex.org/p' , 'http://ex.org/o2' ) ,
9596 ] ) ;
@@ -99,7 +100,7 @@ describe('parser', () => {
99100 const stream = stringToStream ( `
100101<s> <p> <o1>, <o2>.
101102` ) ;
102- return expect ( arrayifyStream ( parser . parse ( stream , { contentType : 'text/turtle' , baseIRI : 'http://ex.org/' } ) ) )
103+ return expect ( arrayifyStream ( rdfParser . parse ( stream , { contentType : 'text/turtle' , baseIRI : 'http://ex.org/' } ) ) )
103104 . resolves . toBeRdfIsomorphic ( [
104105 quad ( 'http://ex.org/s' , 'http://ex.org/p' , 'http://ex.org/o1' ) ,
105106 quad ( 'http://ex.org/s' , 'http://ex.org/p' , 'http://ex.org/o2' ) ,
@@ -110,7 +111,7 @@ describe('parser', () => {
110111 const stream = stringToStream ( `
111112<s> <p> <o1>,
112113` ) ;
113- return expect ( arrayifyStream ( parser . parse ( stream , { contentType : 'text/turtle' } ) ) )
114+ return expect ( arrayifyStream ( rdfParser . parse ( stream , { contentType : 'text/turtle' } ) ) )
114115 . rejects . toThrow ( new Error ( 'Expected entity but got eof on line 3.' ) ) ;
115116 } ) ;
116117
@@ -125,7 +126,7 @@ describe('parser', () => {
125126}
126127` ) ;
127128 const contexts : string [ ] = [ ] ;
128- const result = await arrayifyStream ( parser . parse ( stream , { contentType : 'application/ld+json' } )
129+ const result = await arrayifyStream ( rdfParser . parse ( stream , { contentType : 'application/ld+json' } )
129130 . on ( 'context' , ( context => contexts . push ( context ) ) ) ) ;
130131
131132 expect ( result ) . toBeRdfIsomorphic ( [ ] ) ;
@@ -142,7 +143,7 @@ describe('parser', () => {
142143 "url": ""
143144}
144145` ) ;
145- return expect ( arrayifyStream ( parser . parse ( stream , { contentType : 'application/ld+json' } ) ) ) . resolves
146+ return expect ( arrayifyStream ( rdfParser . parse ( stream , { contentType : 'application/ld+json' } ) ) ) . resolves
146147 . toBeRdfIsomorphic ( [ ] ) ;
147148 } ) ;
148149
@@ -157,8 +158,8 @@ describe('parser', () => {
157158 "url": ""
158159}
159160` ) ;
160- return expect ( arrayifyStream ( parser
161- . parse ( stream , { contentType : 'application/ld+json' , baseIRI : 'http://ex.org/' } ) ) )
161+ return expect ( arrayifyStream ( rdfParser
162+ . parse ( stream , { contentType : 'application/ld+json' , baseIRI : 'http://ex.org/' } ) ) )
162163 . resolves . toBeRdfIsomorphic ( [
163164 quad ( 'http://ex.org/' , 'http://schema.org/name' , '"Jane Doe"' ) ,
164165 quad ( 'http://ex.org/' , 'http://schema.org/url' , 'http://ex.org/' ) ,
@@ -176,8 +177,8 @@ describe('parser', () => {
176177 "url": ""
177178}
178179` ) ;
179- return expect ( arrayifyStream ( parser
180- . parse ( stream , { path : 'myfile.json' , baseIRI : 'http://ex.org/' } ) ) )
180+ return expect ( arrayifyStream ( rdfParser
181+ . parse ( stream , { path : 'myfile.json' , baseIRI : 'http://ex.org/' } ) ) )
181182 . resolves . toBeRdfIsomorphic ( [
182183 quad ( 'http://ex.org/' , 'http://schema.org/name' , '"Jane Doe"' ) ,
183184 quad ( 'http://ex.org/' , 'http://schema.org/url' , 'http://ex.org/' ) ,
@@ -189,13 +190,13 @@ describe('parser', () => {
189190 const stream = stringToStream ( `
190191<s> <p> <o1>,
191192` ) ;
192- return expect ( arrayifyStream ( parser . parse ( stream , { contentType : 'application/ld+json' } ) ) )
193+ return expect ( arrayifyStream ( rdfParser . parse ( stream , { contentType : 'application/ld+json' } ) ) )
193194 . rejects . toThrow ( new Error ( 'Unexpected "s" at position 2 in state STOP' ) ) ;
194195 } ) ;
195196
196197 it ( 'should fail to parse an unknown content type' , ( ) => {
197198 const stream = stringToStream ( `` ) ;
198- return expect ( arrayifyStream ( parser . parse ( stream , { contentType : 'unknown' } ) ) )
199+ return expect ( arrayifyStream ( rdfParser . parse ( stream , { contentType : 'unknown' } ) ) )
199200 . rejects . toBeTruthy ( ) ;
200201 } ) ;
201202
@@ -207,8 +208,8 @@ describe('parser', () => {
207208</head>
208209</html>
209210` ) ;
210- return expect ( arrayifyStream ( parser
211- . parse ( stream , { contentType : 'text/html' , baseIRI : 'http://ex.org/' } ) ) )
211+ return expect ( arrayifyStream ( rdfParser
212+ . parse ( stream , { contentType : 'text/html' , baseIRI : 'http://ex.org/' } ) ) )
212213 . resolves . toBeRdfIsomorphic ( [
213214 quad ( 'http://ex.org/' , 'http://schema.org/name' , '"Title"' ) ,
214215 ] ) ;
@@ -233,7 +234,7 @@ describe('parser', () => {
233234 foaf:name "Spiderman", "Человек-паук"@ru .`
234235 const stream = stringToStream ( turtle ) ;
235236 const prefixes : Record < string , string > = { } ;
236- const result = await arrayifyStream ( parser . parse ( stream , { path : 'myfile.ttl' } )
237+ const result = await arrayifyStream ( rdfParser . parse ( stream , { path : 'myfile.ttl' } )
237238 . on ( 'prefix' , ( prefix , iri ) => prefixes [ prefix ] = iri . value ) ) ;
238239 expect ( result ) . toBeRdfIsomorphic ( [
239240 quad ( 'http://example.org/#green-goblin' , 'http://www.perceive.net/schemas/relationship/enemyOf' , 'http://example.org/#spiderman' ) ,
@@ -259,7 +260,7 @@ describe('parser', () => {
259260 const stream = stringToStream ( `
260261 <s> <p> <o1>, <o2>.
261262 ` ) ;
262- return expect ( arrayifyStream ( parser . parse ( stream , { contentType : 'text/turtle' , baseIRI : 'http://ex.org/' } ) ) )
263+ return expect ( arrayifyStream ( rdfParser . parse ( stream , { contentType : 'text/turtle' , baseIRI : 'http://ex.org/' } ) ) )
263264 . resolves . toBeRdfIsomorphic ( [
264265 quad ( 'http://ex.org/s' , 'http://ex.org/p' , 'http://ex.org/o1' ) ,
265266 quad ( 'http://ex.org/s' , 'http://ex.org/p' , 'http://ex.org/o2' ) ,
@@ -273,7 +274,7 @@ describe('parser', () => {
273274
274275 shape cont:ContactsShape {}
275276 ` ) ;
276- return expect ( arrayifyStream ( parser . parse ( stream , { contentType : 'text/shaclc' } ) ) )
277+ return expect ( arrayifyStream ( rdfParser . parse ( stream , { contentType : 'text/shaclc' } ) ) )
277278 . resolves . toBeRdfIsomorphic ( [
278279 quad ( "http://localhost:3002/ContactsShape#ContactsShape" , "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" , "http://www.w3.org/ns/shacl#NodeShape" ) ,
279280 quad ( "http://localhost:3002/ContactsShape" , "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" , "http://www.w3.org/2002/07/owl#Ontology" ) ,
0 commit comments