@@ -151,11 +151,7 @@ mod tests {
151
151
use core:: panic;
152
152
153
153
use super :: * ;
154
- use csv:: DeserializeErrorKind as CsvDeserializeErrorEnum ;
155
- use csv:: ErrorKind as CsvErrorEnum ;
156
154
use fgoxide:: { self , io:: Io } ;
157
- use serde:: de:: value:: Error as SerdeError ;
158
- use serde:: de:: Error ;
159
155
use tempfile:: TempDir ;
160
156
161
157
// ############################################################################################
@@ -211,6 +207,27 @@ mod tests {
211
207
let _sample = Sample :: new ( ordinal, name, barcode) ;
212
208
}
213
209
210
+ #[ test]
211
+ fn test_tsv_file_delim_error ( ) {
212
+ let lines: Vec < String > = [ "sample_id,barcode" , "sample1,GATTACA" , "sample2,CATGCTA" ]
213
+ . iter ( )
214
+ . map ( |& s| s. into ( ) )
215
+ . collect ( ) ;
216
+ let tempdir = TempDir :: new ( ) . unwrap ( ) ;
217
+ let f1 = tempdir. path ( ) . join ( "sample_metadata.tsv" ) ;
218
+
219
+ let io = Io :: default ( ) ;
220
+ io. write_lines ( & f1, & lines) . unwrap ( ) ;
221
+ let err = SampleGroup :: from_file ( & f1) . unwrap_err ( ) ;
222
+
223
+ if let fgoxide:: FgError :: DelimFileHeaderError { expected, found } = err {
224
+ assert_eq ! ( expected, Sample :: deserialize_header_line( ) ) ;
225
+ assert_eq ! ( found, "sample_id,barcode" ) ;
226
+ } else {
227
+ panic ! ( )
228
+ }
229
+ }
230
+
214
231
// ############################################################################################
215
232
// Test [`SampleGroup::from_file`] - Expected to panic
216
233
// ############################################################################################
@@ -222,16 +239,14 @@ mod tests {
222
239
223
240
let io = Io :: default ( ) ;
224
241
io. write_lines ( & f1, & lines) . unwrap ( ) ;
225
- let mut to_panic = true ;
226
- if let fgoxide:: FgError :: ConversionError ( csv_e) = SampleGroup :: from_file ( & f1) . unwrap_err ( ) {
227
- if let CsvErrorEnum :: Deserialize { pos : _, err : csv_de_err } = csv_e. into_kind ( ) {
228
- if let CsvDeserializeErrorEnum :: Message ( s) = csv_de_err. kind ( ) {
229
- to_panic = false ;
230
- assert_eq ! ( s, & SerdeError :: missing_field( "sample_id" ) . to_string( ) ) ;
231
- }
232
- }
242
+ if let fgoxide:: FgError :: DelimFileHeaderError { expected, found } =
243
+ SampleGroup :: from_file ( & f1) . unwrap_err ( )
244
+ {
245
+ assert_eq ! ( expected, Sample :: deserialize_header_line( ) ) ;
246
+ assert_eq ! ( found, "sample1\t GATTACA" ) ;
247
+ } else {
248
+ panic ! ( "Different error type than expected reading from headerless file." )
233
249
}
234
- assert ! ( !to_panic, "Different error type than expected reading from headerless file." ) ;
235
250
}
236
251
237
252
#[ test]
0 commit comments