@@ -118,13 +118,43 @@ suite('JSON - edits', () => {
118118 assertEdit ( content , edits , '{\n "x": "y"\n}' ) ;
119119 } ) ;
120120
121- test ( 'insert item to empty array' , ( ) => {
121+ test ( 'insert item at 0' , ( ) => {
122+ let content = '[\n 2,\n 3\n]' ;
123+ let edits = setProperty ( content , [ 0 ] , 1 , formatterOptions ) ;
124+ assertEdit ( content , edits , '[\n 1,\n 2,\n 3\n]' ) ;
125+ } ) ;
126+
127+ test ( 'insert item at 0 in empty array' , ( ) => {
128+ let content = '[\n]' ;
129+ let edits = setProperty ( content , [ 0 ] , 1 , formatterOptions ) ;
130+ assertEdit ( content , edits , '[\n 1\n]' ) ;
131+ } ) ;
132+
133+ test ( 'insert item at an index' , ( ) => {
134+ let content = '[\n 1,\n 3\n]' ;
135+ let edits = setProperty ( content , [ 1 ] , 2 , formatterOptions ) ;
136+ assertEdit ( content , edits , '[\n 1,\n 2,\n 3\n]' ) ;
137+ } ) ;
138+
139+ test ( 'insert item at an index im empty array' , ( ) => {
140+ let content = '[\n]' ;
141+ let edits = setProperty ( content , [ 1 ] , 1 , formatterOptions ) ;
142+ assertEdit ( content , edits , '[\n 1\n]' ) ;
143+ } ) ;
144+
145+ test ( 'insert item at end index' , ( ) => {
146+ let content = '[\n 1,\n 2\n]' ;
147+ let edits = setProperty ( content , [ 2 ] , 3 , formatterOptions ) ;
148+ assertEdit ( content , edits , '[\n 1,\n 2,\n 3\n]' ) ;
149+ } ) ;
150+
151+ test ( 'insert item at end to empty array' , ( ) => {
122152 let content = '[\n]' ;
123153 let edits = setProperty ( content , [ - 1 ] , 'bar' , formatterOptions ) ;
124154 assertEdit ( content , edits , '[\n "bar"\n]' ) ;
125155 } ) ;
126156
127- test ( 'insert item' , ( ) => {
157+ test ( 'insert item at end ' , ( ) => {
128158 let content = '[\n 1,\n 2\n]' ;
129159 let edits = setProperty ( content , [ - 1 ] , 'bar' , formatterOptions ) ;
130160 assertEdit ( content , edits , '[\n 1,\n 2,\n "bar"\n]' ) ;
@@ -160,4 +190,4 @@ suite('JSON - edits', () => {
160190 assertEdit ( content , edits , '// This is a comment\n[\n 1,\n "foo"\n]' ) ;
161191 } ) ;
162192
163- } ) ;
193+ } ) ;
0 commit comments