grrsjstitch/lib.rs
1pub fn find_matches(content: &str, pattern: &str, mut writer: impl std::io::Write) {
2 for line in content.lines() {
3 if line.contains(pattern) {
4 writeln!(writer, "{}", line).expect("Could not write to writer");
5 }
6 }
7}
8
9#[test]
10fn find_a_match() {
11 let mut result = Vec::new();
12 find_matches("lorem ipsum\ndolor sit amet", "lorem", &mut result);
13 assert_eq!(result, b"lorem ipsum\n")
14}