From 65d4c2d01e1a6c2886227747a569ed4ce32b4dd2 Mon Sep 17 00:00:00 2001 From: Eric Jolibois Date: Sat, 5 Oct 2024 10:50:26 +0200 Subject: [PATCH] refactor: use mutable ref --- src/lib.rs | 2 +- src/xlsx/mod.rs | 8 -------- tests/test.rs | 21 +++++++++++++++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3663040..046190f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -241,7 +241,7 @@ where fn set_options(&mut self, options: Self::Options); /// Set options and return the reader - fn with_options(mut self, options: Self::Options) -> Self { + fn with_options(&mut self, options: Self::Options) -> &mut Self { self.set_options(options); self } diff --git a/src/xlsx/mod.rs b/src/xlsx/mod.rs index 1ebb3a3..e5f608d 100644 --- a/src/xlsx/mod.rs +++ b/src/xlsx/mod.rs @@ -866,14 +866,6 @@ impl Xlsx { } } -impl Xlsx { - /// Set reader options - pub fn with_options(mut self, options: XlsxOptions) -> Self { - self.options = options; - self - } -} - impl Reader for Xlsx { type Error = XlsxError; type Options = XlsxOptions; diff --git a/tests/test.rs b/tests/test.rs index aff6e03..59d40a1 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1813,7 +1813,7 @@ fn test_header_row_xlsx( #[case] expected_first_row: &[Data], #[case] expected_total_cells: usize, ) { - let excel: Xlsx<_> = wb(fixture_path); + let mut excel: Xlsx<_> = wb(fixture_path); assert_eq!( excel.sheets_metadata(), &[Sheet { @@ -1833,7 +1833,20 @@ fn test_header_row_xlsx( assert_eq!(range.cells().count(), expected_total_cells); } -#[rstest] +#[test] +fn test_read_twice_with_different_header_rows() { + let mut xlsx: Xlsx<_> = wb("any_sheets.xlsx"); + let _ = xlsx + .with_options(XlsxOptions::default().with_header_row(2)) + .worksheet_range("Visible") + .unwrap(); + let _ = xlsx + .with_options(XlsxOptions::default().with_header_row(1)) + .worksheet_range("Visible") + .unwrap(); +} + +#[test] fn test_header_row_xlsb() { let mut xlsb: Xlsb<_> = wb("date.xlsb"); assert_eq!( @@ -1877,7 +1890,7 @@ fn test_header_row_xlsb() { assert_eq!(range.rows().next().unwrap(), &second_line); } -#[rstest] +#[test] fn test_header_row_xls() { let mut xls: Xls<_> = wb("date.xls"); assert_eq!( @@ -1921,7 +1934,7 @@ fn test_header_row_xls() { assert_eq!(range.rows().next().unwrap(), &second_line); } -#[rstest] +#[test] fn test_header_row_ods() { let mut ods: Ods<_> = wb("date.ods"); assert_eq!(