@@ -478,3 +478,207 @@ describe('literal JSON', () => {
478
478
} ) ;
479
479
} ) ;
480
480
} ) ;
481
+
482
+ describe ( 'expansionMap' , ( ) => {
483
+ it ( 'should be called on un-mapped term' , async ( ) => {
484
+ const docWithUnMappedTerm = {
485
+ '@context' : {
486
+ 'definedTerm' : 'https://example.com#definedTerm'
487
+ } ,
488
+ definedTerm : "is defined" ,
489
+ testUndefined : "is undefined"
490
+ } ;
491
+
492
+ let expansionMapCalled = false ;
493
+ const expansionMap = info => {
494
+ if ( info . unmappedProperty === 'testUndefined' ) {
495
+ expansionMapCalled = true ;
496
+ }
497
+ } ;
498
+
499
+ await jsonld . expand ( docWithUnMappedTerm , { expansionMap} ) ;
500
+
501
+ assert . equal ( expansionMapCalled , true ) ;
502
+ } ) ;
503
+
504
+ it ( 'should be called on nested un-mapped term' , async ( ) => {
505
+ const docWithUnMappedTerm = {
506
+ '@context' : {
507
+ 'definedTerm' : 'https://example.com#definedTerm'
508
+ } ,
509
+ definedTerm : {
510
+ testUndefined : "is undefined"
511
+ }
512
+ } ;
513
+
514
+ let expansionMapCalled = false ;
515
+ const expansionMap = info => {
516
+ if ( info . unmappedProperty === 'testUndefined' ) {
517
+ expansionMapCalled = true ;
518
+ }
519
+ } ;
520
+
521
+ await jsonld . expand ( docWithUnMappedTerm , { expansionMap} ) ;
522
+
523
+ assert . equal ( expansionMapCalled , true ) ;
524
+ } ) ;
525
+
526
+ it ( 'should be called on relative iri for id term' , async ( ) => {
527
+ const docWithRelativeIriId = {
528
+ '@context' : {
529
+ 'definedTerm' : 'https://example.com#definedTerm'
530
+ } ,
531
+ '@id' : "relativeiri" ,
532
+ definedTerm : "is defined"
533
+ } ;
534
+
535
+ let expansionMapCalled = false ;
536
+ const expansionMap = info => {
537
+ if ( info . relativeIri && info . relativeIri . value === 'relativeiri' ) {
538
+ expansionMapCalled = true ;
539
+ }
540
+ } ;
541
+
542
+ await jsonld . expand ( docWithRelativeIriId , { expansionMap} ) ;
543
+
544
+ assert . equal ( expansionMapCalled , true ) ;
545
+ } ) ;
546
+
547
+ it ( 'should be called on relative iri for id term (nested)' , async ( ) => {
548
+ const docWithRelativeIriId = {
549
+ '@context' : {
550
+ 'definedTerm' : 'https://example.com#definedTerm'
551
+ } ,
552
+ '@id' : "urn:absoluteIri" ,
553
+ definedTerm : {
554
+ '@id' : "relativeiri"
555
+ }
556
+ } ;
557
+
558
+ let expansionMapCalled = false ;
559
+ const expansionMap = info => {
560
+ if ( info . relativeIri && info . relativeIri . value === 'relativeiri' ) {
561
+ expansionMapCalled = true ;
562
+ }
563
+ } ;
564
+
565
+ await jsonld . expand ( docWithRelativeIriId , { expansionMap} ) ;
566
+
567
+ assert . equal ( expansionMapCalled , true ) ;
568
+ } ) ;
569
+
570
+ it ( 'should be called on relative iri for aliased id term' , async ( ) => {
571
+ const docWithRelativeIriId = {
572
+ '@context' : {
573
+ 'id' : '@id' ,
574
+ 'definedTerm' : 'https://example.com#definedTerm'
575
+ } ,
576
+ 'id' : "relativeiri" ,
577
+ definedTerm : "is defined"
578
+ } ;
579
+
580
+ let expansionMapCalled = false ;
581
+ const expansionMap = info => {
582
+ if ( info . relativeIri && info . relativeIri . value === 'relativeiri' ) {
583
+ expansionMapCalled = true ;
584
+ }
585
+ } ;
586
+
587
+ await jsonld . expand ( docWithRelativeIriId , { expansionMap} ) ;
588
+
589
+ assert . equal ( expansionMapCalled , true ) ;
590
+ } ) ;
591
+
592
+ it ( 'should be called on relative iri for type term' , async ( ) => {
593
+ const docWithRelativeIriId = {
594
+ '@context' : {
595
+ 'definedTerm' : 'https://example.com#definedTerm'
596
+ } ,
597
+ 'id' : "urn:absoluteiri" ,
598
+ '@type' : "relativeiri" ,
599
+ definedTerm : "is defined"
600
+ } ;
601
+
602
+ let expansionMapCalled = false ;
603
+ const expansionMap = info => {
604
+ if ( info . relativeIri && info . relativeIri . value === 'relativeiri' ) {
605
+ expansionMapCalled = true ;
606
+ }
607
+ } ;
608
+
609
+ await jsonld . expand ( docWithRelativeIriId , { expansionMap} ) ;
610
+
611
+ assert . equal ( expansionMapCalled , true ) ;
612
+ } ) ;
613
+
614
+ it ( 'should be called on relative iri for \
615
+ type term with multiple relative iri types' , async ( ) => {
616
+ const docWithRelativeIriId = {
617
+ '@context' : {
618
+ 'definedTerm' : 'https://example.com#definedTerm'
619
+ } ,
620
+ 'id' : "urn:absoluteiri" ,
621
+ '@type' : [ "relativeiri" , "anotherRelativeiri" ] ,
622
+ definedTerm : "is defined"
623
+ } ;
624
+
625
+ let expansionMapCalledTimes = 0 ;
626
+ const expansionMap = info => {
627
+ if ( info . relativeIri &&
628
+ ( info . relativeIri . value === 'relativeiri' ||
629
+ info . relativeIri . value === 'anotherRelativeiri' ) ) {
630
+ expansionMapCalledTimes ++ ;
631
+ }
632
+ } ;
633
+
634
+ await jsonld . expand ( docWithRelativeIriId , { expansionMap} ) ;
635
+
636
+ assert . equal ( expansionMapCalledTimes , 2 ) ;
637
+ } ) ;
638
+
639
+ it ( 'should be called on relative iri for \
640
+ type term with multiple types' , async ( ) => {
641
+ const docWithRelativeIriId = {
642
+ '@context' : {
643
+ 'definedTerm' : 'https://example.com#definedTerm'
644
+ } ,
645
+ 'id' : "urn:absoluteiri" ,
646
+ '@type' : [ "relativeiri" , "definedTerm" ] ,
647
+ definedTerm : "is defined"
648
+ } ;
649
+
650
+ let expansionMapCalled = false ;
651
+ const expansionMap = info => {
652
+ if ( info . relativeIri && info . relativeIri . value === 'relativeiri' ) {
653
+ expansionMapCalled = true ;
654
+ }
655
+ } ;
656
+
657
+ await jsonld . expand ( docWithRelativeIriId , { expansionMap} ) ;
658
+
659
+ assert . equal ( expansionMapCalled , true ) ;
660
+ } ) ;
661
+
662
+ it ( 'should be called on relative iri for aliased type term' , async ( ) => {
663
+ const docWithRelativeIriId = {
664
+ '@context' : {
665
+ 'type' : "@type" ,
666
+ 'definedTerm' : 'https://example.com#definedTerm'
667
+ } ,
668
+ 'id' : "urn:absoluteiri" ,
669
+ 'type' : "relativeiri" ,
670
+ definedTerm : "is defined"
671
+ } ;
672
+
673
+ let expansionMapCalled = false ;
674
+ const expansionMap = info => {
675
+ if ( info . relativeIri && info . relativeIri . value === 'relativeiri' ) {
676
+ expansionMapCalled = true ;
677
+ }
678
+ } ;
679
+
680
+ await jsonld . expand ( docWithRelativeIriId , { expansionMap} ) ;
681
+
682
+ assert . equal ( expansionMapCalled , true ) ;
683
+ } ) ;
684
+ } ) ;
0 commit comments