pub const SIMPLE_FILE: &str = "line 1\nline 2\nline 3\n";
pub const FILE_WITH_TRAILING_SPACES: &str = "line 1 \nline 2\nline 3 \n";
pub const FILE_WITHOUT_NEWLINE: &str = "line 1\nline 2";
pub const EMPTY_FILE: &str = "";
pub const MIXED_LINE_ENDINGS: &str = "line 1\r\nline 2\nline 3\r\n";
pub fn generate_large_file(lines: usize) -> String {
(0..lines).map(|i| format!("line {i}\n")).collect()
}
pub fn generate_file_with_trailing_spaces(lines: usize, every_nth: usize) -> String {
(0..lines)
.map(|i| {
if i % every_nth == 0 {
format!("line {i} \n")
} else {
format!("line {i}\n")
}
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_generate_large_file() {
let content = generate_large_file(3);
assert_eq!(content, "line 0\nline 1\nline 2\n");
}
#[test]
fn test_generate_file_with_trailing_spaces() {
let content = generate_file_with_trailing_spaces(3, 2);
assert_eq!(content, "line 0 \nline 1\nline 2 \n");
}
}