@@ -151,6 +151,136 @@ describe('Resource', () => {
151151 ] ,
152152 } ) ;
153153 } ) ;
154+
155+ it ( 'with nested list and properties and no max depth' , ( ) => {
156+ const value1 = new Resource ( { term : DF . namedNode ( 'ex:value1' ) } ) ;
157+ const value1_1 = new Resource ( { term : DF . namedNode ( 'ex:value1.1' ) } ) ;
158+ const value1_1_1 = new Resource ( { term : DF . namedNode ( 'ex:value1.1.1' ) } ) ;
159+ value1_1 . properties [ 'ex:a.1.1' ] . push ( value1_1_1 ) ;
160+ value1 . properties [ 'ex:a.1' ] . push ( value1_1 ) ;
161+ resource . properties [ 'ex:a' ] . push ( value1 ) ;
162+ resource . properties [ 'ex:b' ] . push ( new Resource ( { term : DF . literal ( 'value2' ) } ) ) ;
163+ resource . list = [ ] ;
164+ resource . list . push ( value1 ) ;
165+ resource . list . push ( new Resource ( { term : DF . literal ( 'value2' ) } ) ) ;
166+ expect ( resource . toJSON ( ) ) . toEqual ( {
167+ '@id' : 'http://example.org/resource1' ,
168+ properties : {
169+ 'http://example.org/a' : [
170+ {
171+ '@id' : 'ex:value1' ,
172+ properties : {
173+ 'ex:a.1' : [
174+ {
175+ '@id' : 'ex:value1.1' ,
176+ properties : {
177+ 'ex:a.1.1' : [
178+ 'ex:value1.1.1' ,
179+ ] ,
180+ } ,
181+ } ,
182+ ] ,
183+ } ,
184+ } ,
185+ ] ,
186+ 'http://example.org/b' : [
187+ '"value2"' ,
188+ ] ,
189+ } ,
190+ list : [
191+ {
192+ '@id' : 'ex:value1' ,
193+ properties : {
194+ 'ex:a.1' : [
195+ {
196+ '@id' : 'ex:value1.1' ,
197+ properties : {
198+ 'ex:a.1.1' : [
199+ 'ex:value1.1.1' ,
200+ ] ,
201+ } ,
202+ } ,
203+ ] ,
204+ } ,
205+ } ,
206+ '"value2"' ,
207+ ] ,
208+ } ) ;
209+ } ) ;
210+
211+ it ( 'with nested list and properties and a max depth of 1' , ( ) => {
212+ const value1 = new Resource ( { term : DF . namedNode ( 'ex:value1' ) } ) ;
213+ const value1_1 = new Resource ( { term : DF . namedNode ( 'ex:value1.1' ) } ) ;
214+ const value1_1_1 = new Resource ( { term : DF . namedNode ( 'ex:value1.1.1' ) } ) ;
215+ value1_1 . properties [ 'ex:a.1.1' ] . push ( value1_1_1 ) ;
216+ value1 . properties [ 'ex:a.1' ] . push ( value1_1 ) ;
217+ resource . properties [ 'ex:a' ] . push ( value1 ) ;
218+ resource . properties [ 'ex:b' ] . push ( new Resource ( { term : DF . literal ( 'value2' ) } ) ) ;
219+ resource . list = [ ] ;
220+ resource . list . push ( value1 ) ;
221+ resource . list . push ( new Resource ( { term : DF . literal ( 'value2' ) } ) ) ;
222+ expect ( resource . toJSON ( 1 ) ) . toEqual ( {
223+ '@id' : 'http://example.org/resource1' ,
224+ properties : {
225+ 'http://example.org/a' : [
226+ { '@id' : 'ex:value1' } ,
227+ ] ,
228+ 'http://example.org/b' : [
229+ '"value2"' ,
230+ ] ,
231+ } ,
232+ list : [
233+ { '@id' : 'ex:value1' } ,
234+ '"value2"' ,
235+ ] ,
236+ } ) ;
237+ } ) ;
238+
239+ it ( 'with nested list and properties and a max depth of 2' , ( ) => {
240+ const value1 = new Resource ( { term : DF . namedNode ( 'ex:value1' ) } ) ;
241+ const value1_1 = new Resource ( { term : DF . namedNode ( 'ex:value1.1' ) } ) ;
242+ const value1_1_1 = new Resource ( { term : DF . namedNode ( 'ex:value1.1.1' ) } ) ;
243+ value1_1 . properties [ 'ex:a.1.1' ] . push ( value1_1_1 ) ;
244+ value1 . properties [ 'ex:a.1' ] . push ( value1_1 ) ;
245+ resource . properties [ 'ex:a' ] . push ( value1 ) ;
246+ resource . properties [ 'ex:b' ] . push ( new Resource ( { term : DF . literal ( 'value2' ) } ) ) ;
247+ resource . list = [ ] ;
248+ resource . list . push ( value1 ) ;
249+ resource . list . push ( new Resource ( { term : DF . literal ( 'value2' ) } ) ) ;
250+ expect ( resource . toJSON ( 2 ) ) . toEqual ( {
251+ '@id' : 'http://example.org/resource1' ,
252+ properties : {
253+ 'http://example.org/a' : [
254+ {
255+ '@id' : 'ex:value1' ,
256+ properties : {
257+ 'ex:a.1' : [
258+ {
259+ '@id' : 'ex:value1.1' ,
260+ } ,
261+ ] ,
262+ } ,
263+ } ,
264+ ] ,
265+ 'http://example.org/b' : [
266+ '"value2"' ,
267+ ] ,
268+ } ,
269+ list : [
270+ {
271+ '@id' : 'ex:value1' ,
272+ properties : {
273+ 'ex:a.1' : [
274+ {
275+ '@id' : 'ex:value1.1' ,
276+ } ,
277+ ] ,
278+ } ,
279+ } ,
280+ '"value2"' ,
281+ ] ,
282+ } ) ;
283+ } ) ;
154284 } ) ;
155285 } ) ;
156286
0 commit comments