Skip to content

Commit

Permalink
refactor: move test and make idiomatic
Browse files Browse the repository at this point in the history
  • Loading branch information
theJasonFan committed Aug 19, 2024
1 parent d999943 commit eac1604
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions src/lib/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,6 @@ mod tests {
assert!(samples_metadata.samples[1].barcode == "CATGCTA");
}

#[test]
fn test_tsv_file_delim_error() {
let lines = vec![
// Sample::deserialize_header_line(),
"sample_id,barcode".to_owned(),
"sample1,GATTACA".to_owned(),
"sample2,CATGCTA".to_owned(),
];
let tempdir = TempDir::new().unwrap();
let f1 = tempdir.path().join("sample_metadata.tsv");

let io = Io::default();
io.write_lines(&f1, &lines).unwrap();
let err = SampleGroup::from_file(&f1).unwrap_err();

if let fgoxide::FgError::DelimFileHeaderError { expected, found } = err {
assert_eq!(expected, Sample::deserialize_header_line());
assert_eq!(found, "sample_id,barcode");
} else {
panic!()
}
}

#[test]
fn test_reading_from_file_with_empty_lines_at_end() {
let lines = vec![
Expand Down Expand Up @@ -230,6 +207,27 @@ mod tests {
let _sample = Sample::new(ordinal, name, barcode);
}

#[test]
fn test_tsv_file_delim_error() {
let lines: Vec<String> = ["sample_id,barcode", "sample1,GATTACA", "sample2,CATGCTA"]
.iter()
.map(|&s| s.into())
.collect();
let tempdir = TempDir::new().unwrap();
let f1 = tempdir.path().join("sample_metadata.tsv");

let io = Io::default();
io.write_lines(&f1, &lines).unwrap();
let err = SampleGroup::from_file(&f1).unwrap_err();

if let fgoxide::FgError::DelimFileHeaderError { expected, found } = err {
assert_eq!(expected, Sample::deserialize_header_line());
assert_eq!(found, "sample_id,barcode");
} else {
panic!()
}
}

// ############################################################################################
// Test [`SampleGroup::from_file`] - Expected to panic
// ############################################################################################
Expand Down

0 comments on commit eac1604

Please sign in to comment.