Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/comment_rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,42 @@ impl Callback for CommentRm {
Ok(())
}
}

#[cfg(test)]
mod tests {
use std::path::PathBuf;

use crate::{CcommentParser, ParserTrait};

use super::rm_comments;

const SOURCE_CODE: &str = "/* Remove this code block */\n\
int a = 42; // Remove this comment\n\
// Remove this comment\n\
int b = 42;\n\
/* Remove\n\
* this\n\
* comment\n\
*/";

const SOURCE_CODE_NO_COMMENTS: &str = "\n\
int a = 42; \n\
\n\
int b = 42;\n\
\n\
\n\
\n\
\n";

#[test]
fn ccomment_remove_comments() {
let path = PathBuf::from("foo.c");
let mut trimmed_bytes = SOURCE_CODE.as_bytes().to_vec();
trimmed_bytes.push(b'\n');
let parser = CcommentParser::new(trimmed_bytes, &path, None);

let no_comments = rm_comments(&parser).unwrap();

assert_eq!(no_comments.as_slice(), SOURCE_CODE_NO_COMMENTS.as_bytes());
}
}