@@ -85,3 +85,55 @@ test('removeBlankLines: should return early if the location does not exist', t =
8585
8686 t . deepEqual ( obj , { foo : 1 } )
8787} )
88+
89+ test ( 'removeBlankLines: should return early when location has no blank lines' , t => {
90+ const obj = parse ( `{
91+ // before foo
92+ "foo": 1
93+ }` )
94+
95+ removeBlankLines ( obj , { where : 'before' , key : 'foo' } )
96+
97+ t . is ( stringify ( obj , null , 2 ) , `{
98+ // before foo
99+ "foo": 1
100+ }` )
101+ } )
102+
103+ test ( 'removeBlankLines: should ignore non-array comment slots' , t => {
104+ const obj = { foo : 1 }
105+
106+ Object . defineProperty ( obj , Symbol . for ( 'before:foo' ) , {
107+ value : 'not-an-array' ,
108+ writable : true ,
109+ configurable : true
110+ } )
111+
112+ removeBlankLines ( obj , { where : 'before' , key : 'foo' } )
113+
114+ t . is ( obj [ Symbol . for ( 'before:foo' ) ] , 'not-an-array' )
115+ } )
116+
117+ test ( 'removeBlankLines: should ignore non-comment symbols during recursive cleanup' , t => {
118+ const obj = parse ( `{
119+ // before foo
120+
121+ "foo": 1
122+ }` )
123+ const marker = Symbol ( 'marker' )
124+
125+ Object . defineProperty ( obj , marker , {
126+ value : [ { type : 'BlankLine' , inline : false } ] ,
127+ writable : true ,
128+ configurable : true
129+ } )
130+
131+ removeBlankLines ( obj )
132+
133+ t . true ( Object . hasOwn ( obj , marker ) )
134+ t . deepEqual ( obj [ marker ] , [ { type : 'BlankLine' , inline : false } ] )
135+ t . is ( stringify ( obj , null , 2 ) , `{
136+ // before foo
137+ "foo": 1
138+ }` )
139+ } )
0 commit comments