From eac1604b12c9534695912237352e8c9b74c286ae Mon Sep 17 00:00:00 2001 From: Jason Fan Date: Mon, 19 Aug 2024 14:55:32 -0400 Subject: [PATCH] refactor: move test and make idiomatic --- src/lib/samples.rs | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/lib/samples.rs b/src/lib/samples.rs index 5ee00e1..cf5b345 100644 --- a/src/lib/samples.rs +++ b/src/lib/samples.rs @@ -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![ @@ -230,6 +207,27 @@ mod tests { let _sample = Sample::new(ordinal, name, barcode); } + #[test] + fn test_tsv_file_delim_error() { + let lines: Vec = ["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 // ############################################################################################