@@ -679,6 +679,74 @@ describe('SchemaTree', () => {
679
679
} ) ;
680
680
} ) ;
681
681
682
+ describe ( 'position' , ( ) => {
683
+ let schema : JSONSchema4 ;
684
+
685
+ beforeEach ( ( ) => {
686
+ schema = {
687
+ type : [ 'string' , 'object' ] ,
688
+ properties : {
689
+ ids : {
690
+ type : 'array' ,
691
+ items : {
692
+ type : 'integer' ,
693
+ } ,
694
+ } ,
695
+ tag : {
696
+ type : 'string' ,
697
+ } ,
698
+ uuid : {
699
+ type : 'string' ,
700
+ } ,
701
+ } ,
702
+ } ;
703
+ } ) ;
704
+
705
+ it ( 'given node being the only child, should have correct position info' , ( ) => {
706
+ const tree = new SchemaTree ( schema ) ;
707
+ tree . populate ( ) ;
708
+
709
+ const node = tree . root . children [ 0 ] ;
710
+
711
+ expect ( node . isFirst ) . toBe ( true ) ;
712
+ expect ( node . isLast ) . toBe ( true ) ;
713
+ expect ( node . pos ) . toEqual ( 0 ) ;
714
+ } ) ;
715
+
716
+ it ( 'given node being the first child among other children, should have correct position info' , ( ) => {
717
+ const tree = new SchemaTree ( schema ) ;
718
+ tree . populate ( ) ;
719
+
720
+ const node = ( tree . root . children [ 0 ] as RegularNode ) . children ! [ 0 ] ;
721
+
722
+ expect ( node . isFirst ) . toBe ( true ) ;
723
+ expect ( node . isLast ) . toBe ( false ) ;
724
+ expect ( node . pos ) . toEqual ( 0 ) ;
725
+ } ) ;
726
+
727
+ it ( 'given node being the last child among other children, should have correct position info' , ( ) => {
728
+ const tree = new SchemaTree ( schema ) ;
729
+ tree . populate ( ) ;
730
+
731
+ const node = ( tree . root . children [ 0 ] as RegularNode ) . children ! [ 2 ] ;
732
+
733
+ expect ( node . isFirst ) . toBe ( false ) ;
734
+ expect ( node . isLast ) . toBe ( true ) ;
735
+ expect ( node . pos ) . toEqual ( 2 ) ;
736
+ } ) ;
737
+
738
+ it ( 'given node not being the first nor the child among other children, should have correct position info' , ( ) => {
739
+ const tree = new SchemaTree ( schema ) ;
740
+ tree . populate ( ) ;
741
+
742
+ const node = ( tree . root . children [ 0 ] as RegularNode ) . children ! [ 1 ] ;
743
+
744
+ expect ( node . isFirst ) . toBe ( false ) ;
745
+ expect ( node . isLast ) . toBe ( false ) ;
746
+ expect ( node . pos ) . toEqual ( 1 ) ;
747
+ } ) ;
748
+ } ) ;
749
+
682
750
describe ( 'mirroring' , ( ) => {
683
751
describe ( 'circular references' , ( ) => {
684
752
it ( 'should self expand' , ( ) => {
0 commit comments