Skip to content

Commit d145212

Browse files
committed
Add a test for the remove comments API
1 parent 02faac5 commit d145212

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

‎src/comment_rm.rs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,42 @@ impl Callback for CommentRm {
9191
Ok(())
9292
}
9393
}
94+
95+
#[cfg(test)]
96+
mod tests {
97+
use std::path::PathBuf;
98+
99+
use crate::{CcommentParser, ParserTrait};
100+
101+
use super::rm_comments;
102+
103+
const SOURCE_CODE: &'static str = "/* Remove this code block */\n\
104+
int a = 42; // Remove this comment\n\
105+
// Remove this comment\n\
106+
int b = 42;\n\
107+
/* Remove\n\
108+
* this\n\
109+
* comment\n\
110+
*/";
111+
112+
const SOURCE_CODE_NO_COMMENTS: &'static str = "\n\
113+
int a = 42; \n\
114+
\n\
115+
int b = 42;\n\
116+
\n\
117+
\n\
118+
\n\
119+
\n";
120+
121+
#[test]
122+
fn ccomment_remove_comments() {
123+
let path = PathBuf::from("foo.c");
124+
let mut trimmed_bytes = SOURCE_CODE.as_bytes().to_vec();
125+
trimmed_bytes.push(b'\n');
126+
let parser = CcommentParser::new(trimmed_bytes, &path, None);
127+
128+
let no_comments = rm_comments(&parser).unwrap();
129+
130+
assert_eq!(no_comments.as_slice(), SOURCE_CODE_NO_COMMENTS.as_bytes());
131+
}
132+
}

0 commit comments

Comments
 (0)