@@ -117,7 +117,21 @@ describe('other toRDF tests', () => {
117117 } ) ;
118118 } ) ;
119119
120- it ( 'should handle nquads format' , done => {
120+ it ( 'should handle N-Quads format' , done => {
121+ const doc = {
122+ '@id' : 'https://example.com/' ,
123+ 'https://example.com/test' : 'test'
124+ } ;
125+ jsonld . toRDF ( doc , { format : 'application/n-quads' } , ( err , output ) => {
126+ assert . ifError ( err ) ;
127+ assert . equal (
128+ output ,
129+ '<https://example.com/> <https://example.com/test> "test" .\n' ) ;
130+ done ( ) ;
131+ } ) ;
132+ } ) ;
133+
134+ it ( 'should handle deprecated N-Quads format' , done => {
121135 const doc = {
122136 '@id' : 'https://example.com/' ,
123137 'https://example.com/test' : 'test'
@@ -132,6 +146,119 @@ describe('other toRDF tests', () => {
132146 } ) ;
133147} ) ;
134148
149+ describe ( 'other fromRDF tests' , ( ) => {
150+ const emptyNQuads = '' ;
151+ const emptyRdf = [ ] ;
152+
153+ it ( 'should process with options and callback' , done => {
154+ jsonld . fromRDF ( '' , { } , ( err , output ) => {
155+ assert . ifError ( err ) ;
156+ assert . deepEqual ( output , emptyRdf ) ;
157+ done ( ) ;
158+ } ) ;
159+ } ) ;
160+
161+ it ( 'should process with no options and callback' , done => {
162+ jsonld . fromRDF ( emptyNQuads , ( err , output ) => {
163+ assert . ifError ( err ) ;
164+ assert . deepEqual ( output , emptyRdf ) ;
165+ done ( ) ;
166+ } ) ;
167+ } ) ;
168+
169+ it ( 'should process with options and promise' , done => {
170+ const p = jsonld . fromRDF ( emptyNQuads , { } ) ;
171+ assert ( p instanceof Promise ) ;
172+ p . catch ( e => {
173+ assert . fail ( ) ;
174+ } ) . then ( output => {
175+ assert . deepEqual ( output , emptyRdf ) ;
176+ done ( ) ;
177+ } ) ;
178+ } ) ;
179+
180+ it ( 'should process with no options and promise' , done => {
181+ const p = jsonld . fromRDF ( emptyNQuads ) ;
182+ assert ( p instanceof Promise ) ;
183+ p . catch ( e => {
184+ assert . fail ( ) ;
185+ } ) . then ( output => {
186+ assert . deepEqual ( output , emptyRdf ) ;
187+ done ( ) ;
188+ } ) ;
189+ } ) ;
190+
191+ it ( 'should fail with no args and callback' , done => {
192+ jsonld . fromRDF ( ( err , output ) => {
193+ assert ( err ) ;
194+ done ( ) ;
195+ } ) ;
196+ } ) ;
197+
198+ it ( 'should fail with no args and promise' , done => {
199+ const p = jsonld . fromRDF ( ) ;
200+ assert ( p instanceof Promise ) ;
201+ p . then ( output => {
202+ assert . fail ( ) ;
203+ } ) . catch ( e => {
204+ assert ( e ) ;
205+ done ( ) ;
206+ } )
207+ } ) ;
208+
209+ it ( 'should fail for bad format and callback' , done => {
210+ jsonld . fromRDF ( emptyNQuads , { format : 'bogus' } , ( err , output ) => {
211+ assert ( err ) ;
212+ assert . equal ( err . name , 'jsonld.UnknownFormat' ) ;
213+ done ( ) ;
214+ } ) ;
215+ } ) ;
216+
217+ it ( 'should fail for bad format and promise' , done => {
218+ const p = jsonld . fromRDF ( emptyNQuads , { format : 'bogus' } ) ;
219+ assert ( p instanceof Promise ) ;
220+ p . then ( ( ) => {
221+ assert . fail ( ) ;
222+ } ) . catch ( e => {
223+ assert ( e ) ;
224+ assert . equal ( e . name , 'jsonld.UnknownFormat' ) ;
225+ done ( ) ;
226+ } ) ;
227+ } ) ;
228+
229+ it ( 'should handle N-Quads format' , done => {
230+ const nq = '<https://example.com/> <https://example.com/test> "test" .\n' ;
231+ jsonld . fromRDF ( nq , { format : 'application/n-quads' } , ( err , output ) => {
232+ assert . ifError ( err ) ;
233+ assert . deepEqual (
234+ output ,
235+ [ {
236+ '@id' : 'https://example.com/' ,
237+ 'https://example.com/test' : [ {
238+ '@value' : 'test'
239+ } ]
240+ } ] ) ;
241+ done ( ) ;
242+ } ) ;
243+ } ) ;
244+
245+ it ( 'should handle deprecated N-Quads format' , done => {
246+ const nq = '<https://example.com/> <https://example.com/test> "test" .\n' ;
247+ jsonld . fromRDF ( nq , { format : 'application/nquads' } , ( err , output ) => {
248+ assert . ifError ( err ) ;
249+ assert . deepEqual (
250+ output ,
251+ [ {
252+ '@id' : 'https://example.com/' ,
253+ 'https://example.com/test' : [ {
254+ '@value' : 'test'
255+ } ]
256+ } ] ) ;
257+ done ( ) ;
258+ } ) ;
259+ } ) ;
260+ } ) ;
261+
135262describe ( 'loading multiple levels of contexts' , ( ) => {
136263 const documentLoader = url => {
137264 if ( url === 'https://example.com/context1' ) {
0 commit comments