Skip to content

Commit

Permalink
Add a failing test case for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stefnotch committed Apr 25, 2024
1 parent 33e57e4 commit cab736a
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/compose/comment_strip_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,67 @@ impl<'a> CommentReplaceExt<'a> for Lines<'a> {
}
}

#[test]
fn multiline_comment_test() {
let test_cases = [
(
// Basic test
r"/*
hoho
*/",
r"
",
),
(
// Testing the commenting-out of multiline comments
r"///*
hehe
//*/",
r"
hehe
",
),
(
// Testing the commenting-out of single-line comments
r"/* // */ code goes here /*
Still a comment // */
/* dummy */",
r" code goes here
",
),
(
// A comment with a nested multiline comment
// Notice how the "//" inside the multiline comment doesn't take effect
r"/*
//*
*/commented
*/not commented",
r"
not commented",
),
];

for &(input, expected) in test_cases.iter() {
for (output_line, expected_line) in input.lines().replace_comments().zip(expected.lines()) {
assert_eq!(output_line.as_ref(), expected_line);
}
}
}

#[test]
fn test_comment_becomes_spaces() {
let test_cases = [("let a/**/b =3u;", "let a b =3u;")];
for &(input, expected) in test_cases.iter() {
for (output_line, expected_line) in input.lines().replace_comments().zip(expected.lines()) {
assert_eq!(output_line.as_ref(), expected_line);
}
}
}

#[test]
fn comment_test() {
const INPUT: &str = r"
Expand Down

0 comments on commit cab736a

Please sign in to comment.