Skip to content

Commit

Permalink
wip: test line count
Browse files Browse the repository at this point in the history
  • Loading branch information
markxoe committed Jun 3, 2024
1 parent 5aba90f commit 6e3ba02
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/data/parsers/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,62 @@ mod test {
sync::{Arc, Mutex},
};

mod line_count {
#[allow(unused_imports)]
use std::{env::temp_dir, io::Write};

#[test]
fn empty_file() {
let dir = temp_dir();
let file_path = dir.join("test1.txt");

// create file
{
let _file = std::fs::File::create(&file_path).expect("Unable to create file");
}

let count = super::super::get_file_line_count(file_path.to_str().unwrap());

assert_eq!(count, 0);
}

#[test]
fn single_line() {
let dir = temp_dir();
let file_path = dir.join("test2.txt");

// create file
{
let mut file = std::fs::File::create(&file_path).expect("Unable to create file");
writeln!(file, "test").expect("Unable to write to file");
}

let count = super::super::get_file_line_count(file_path.to_str().unwrap());

assert_eq!(count, 1);
}

#[test]
fn multiple_lines() {
let dir = temp_dir();
let file_path = dir.join("test3.txt");

// create file
{
let file = std::fs::File::create(&file_path).expect("Unable to create file");
let mut file = std::io::BufWriter::new(file);
for _ in 0..1000 {
writeln!(file, "Test").expect("Unable to write to file");
}
file.flush().expect("Unable to flush file");
}

let count = super::super::get_file_line_count(file_path.to_str().unwrap());

assert_eq!(count, 1000);
}
}

#[test]
fn all_lines_are_read() {
let dir = temp_dir();
Expand Down

0 comments on commit 6e3ba02

Please sign in to comment.