Skip to content

Commit 2ec96c6

Browse files
committed
add unit tests
1 parent 5610084 commit 2ec96c6

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

crates/pglt_workspace/src/configuration.rs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,110 @@ pub fn strip_jsonc_comments(jsonc_input: &str) -> String {
265265

266266
json_output
267267
}
268+
269+
#[cfg(test)]
270+
mod tests {
271+
use super::*;
272+
273+
#[test]
274+
fn test_strip_jsonc_comments_line_comments() {
275+
let input = r#"{
276+
"name": "test", // This is a line comment
277+
"value": 42 // Another comment
278+
}"#;
279+
280+
let expected = r#"{
281+
"name": "test",
282+
"value": 42
283+
}
284+
"#;
285+
286+
assert_eq!(strip_jsonc_comments(input), expected);
287+
}
288+
289+
#[test]
290+
fn test_strip_jsonc_comments_block_comments() {
291+
let input = r#"{
292+
/* This is a block comment */
293+
"name": "test",
294+
"value": /* inline comment */ 42
295+
}"#;
296+
297+
let expected = r#"{
298+
299+
"name": "test",
300+
"value": 42
301+
}
302+
"#;
303+
304+
assert_eq!(strip_jsonc_comments(input), expected);
305+
}
306+
307+
#[test]
308+
fn test_strip_jsonc_comments_nested_block_comments() {
309+
let input = r#"{
310+
/* Outer comment /* Nested comment */ still outer */
311+
"name": "test"
312+
}"#;
313+
314+
let expected = r#"{
315+
316+
"name": "test"
317+
}
318+
"#;
319+
320+
assert_eq!(strip_jsonc_comments(input), expected);
321+
}
322+
323+
#[test]
324+
fn test_strip_jsonc_comments_in_strings() {
325+
let input = r#"{
326+
"comment_like": "This is not a // comment",
327+
"another": "This is not a /* block comment */ either"
328+
}"#;
329+
330+
let expected = r#"{
331+
"comment_like": "This is not a // comment",
332+
"another": "This is not a /* block comment */ either"
333+
}
334+
"#;
335+
336+
assert_eq!(strip_jsonc_comments(input), expected);
337+
}
338+
339+
#[test]
340+
fn test_strip_jsonc_comments_escaped_quotes() {
341+
let input = r#"{
342+
"escaped\": \"quote": "value", // Comment after escaped quotes
343+
"normal": "value" // Normal comment
344+
}"#;
345+
346+
let expected = r#"{
347+
"escaped\": \"quote": "value",
348+
"normal": "value"
349+
}
350+
"#;
351+
352+
assert_eq!(strip_jsonc_comments(input), expected);
353+
}
354+
355+
#[test]
356+
fn test_strip_jsonc_comments_multiline_block() {
357+
let input = r#"{
358+
/* This is a
359+
multiline block
360+
comment */
361+
"name": "test"
362+
}"#;
363+
364+
let expected = r#"{
365+
366+
367+
368+
"name": "test"
369+
}
370+
"#;
371+
372+
assert_eq!(strip_jsonc_comments(input), expected);
373+
}
374+
}

0 commit comments

Comments
 (0)