@@ -82,56 +82,49 @@ func TestStripComments(t *testing.T) {
8282 {
8383 name : "Single line comment" ,
8484 input : `{"name": "Alice"} // Comment` ,
85- expected : `{"name": "Alice"} ` ,
85+ expected : `{"name": "Alice"} ` ,
8686 },
8787 {
8888 name : "Multi-line comment" ,
8989 input : `{"name": "Alice" /* Comment */}` ,
90- expected : `{"name": "Alice" }` ,
90+ expected : `{"name": "Alice" }` ,
9191 },
9292 {
9393 name : "Nested comments" ,
9494 input : `{"name": "Alice" /* Comment // Nested comment */}` ,
95- expected : `{"name": "Alice" }` ,
95+ expected : `{"name": "Alice" }` ,
9696 },
9797 {
9898 name : "Comment at the end of file without newline" ,
9999 input : `{"name": "Alice"} // Comment` ,
100- expected : `{"name": "Alice"} ` ,
100+ expected : `{"name": "Alice"} ` ,
101101 },
102102 {
103103 name : "Comment at the end of file with newline" ,
104104 input : `{"name": "Alice"} // Comment
105105` ,
106- expected : `{"name": "Alice"}
107- ` ,
106+ expected : "{\" name\" : \" Alice\" } \n " ,
108107 },
109108 {
110109 name : "Multiple single line comments" ,
111110 input : `// Comment 1
112111 // Comment 2
113112 {"name": "Alice"}` ,
114- expected : `
115-
116- {"name": "Alice"}` ,
113+ expected : "\n \t \t \t \n \t \t \t {\" name\" : \" Alice\" }" ,
117114 },
118115 {
119116 name : "Multiple multi-line comments" ,
120117 input : `/* Comment 1 */
121118 /* Comment 2 */
122119 {"name": "Alice"}` ,
123- expected : `
124-
125- {"name": "Alice"}` ,
120+ expected : "\n \t \t \t \n \t \t \t {\" name\" : \" Alice\" }" ,
126121 },
127122 {
128123 name : "Mixed comments" ,
129124 input : `/* Comment 1 */
130125 // Comment 2
131126 {"name": "Alice"}` ,
132- expected : `
133-
134- {"name": "Alice"}` ,
127+ expected : "\n \t \t \t \n \t \t \t {\" name\" : \" Alice\" }" ,
135128 },
136129 {
137130 name : "No comments" ,
@@ -151,12 +144,12 @@ func TestStripComments(t *testing.T) {
151144 {
152145 name : "Comment slashes inside string followed by actual comment" ,
153146 input : `{"name": "//Alice"} // Comment` ,
154- expected : `{"name": "//Alice"} ` ,
147+ expected : `{"name": "//Alice"} ` ,
155148 },
156149 {
157150 name : "Multi-line comment delimiters inside string" ,
158151 input : `{"name": "/*Alice*/"} /* Comment */` ,
159- expected : `{"name": "/*Alice*/"} ` ,
152+ expected : `{"name": "/*Alice*/"} ` ,
160153 },
161154 {
162155 name : "Empty input" ,
@@ -166,22 +159,22 @@ func TestStripComments(t *testing.T) {
166159 {
167160 name : "Only single line comment" ,
168161 input : `// Comment` ,
169- expected : ` ` ,
162+ expected : `` ,
170163 },
171164 {
172165 name : "Only multi-line comment" ,
173166 input : `/* Comment */` ,
174- expected : ` ` ,
167+ expected : `` ,
175168 },
176169 {
177170 name : "Comment after a comma" ,
178171 input : `{"name": "Alice", /* Comment */ "age": 30}` ,
179- expected : `{"name": "Alice", "age": 30}` ,
172+ expected : `{"name": "Alice", "age": 30}` ,
180173 },
181174 {
182175 name : "Comment inside array" ,
183176 input : `["Alice", /* Comment */ "Bob"]` ,
184- expected : `["Alice", "Bob"]` ,
177+ expected : `["Alice", "Bob"]` ,
185178 },
186179 {
187180 name : "Newline inside string" ,
@@ -195,19 +188,19 @@ func TestStripComments(t *testing.T) {
195188 input : `{"message": "Hello
196189 World"} // Comment` ,
197190 expected : `{"message": "Hello
198- World"} ` ,
191+ World"} ` ,
199192 },
200193 {
201194 name : "Newline inside string with multi-line comment after" ,
202195 input : `{"message": "Hello
203196 World"} /* Comment */` ,
204197 expected : `{"message": "Hello
205- World"} ` ,
198+ World"} ` ,
206199 },
207200 {
208201 name : "Multiple newlines inside string & single comment at the end" ,
209202 input : "{\" message\" : \" Hello\n \n World\" }// " ,
210- expected : "{\" message\" : \" Hello\n \n World\" } " ,
203+ expected : "{\" message\" : \" Hello\n \n World\" }" ,
211204 },
212205 {
213206 name : "Newline inside string with actual newline after" ,
@@ -216,7 +209,7 @@ World"}
216209// Comment` ,
217210 expected : `{"message": "Hello
218211World"}
219- ` ,
212+ ` ,
220213 },
221214 }
222215
0 commit comments