From 6744c6ba52e7fb4afa1e3f55918f90b36c233929 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 5 Jan 2026 16:06:46 -0800 Subject: [PATCH] Add another lightweight test. --- rust/pspp/src/spv/read/light.rs | 33 ++++++++++++++------- rust/pspp/src/spv/read/tests.rs | 8 +++++ rust/pspp/src/spv/testdata/light2.expected | 24 +++++++++++++++ rust/pspp/src/spv/testdata/light2.spv | Bin 0 -> 2290 bytes 4 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 rust/pspp/src/spv/testdata/light2.expected create mode 100644 rust/pspp/src/spv/testdata/light2.spv diff --git a/rust/pspp/src/spv/read/light.rs b/rust/pspp/src/spv/read/light.rs index e603b58988..2a2f4d8692 100644 --- a/rust/pspp/src/spv/read/light.rs +++ b/rust/pspp/src/spv/read/light.rs @@ -14,7 +14,6 @@ use chrono::DateTime; use displaydoc::Display; use encoding_rs::{Encoding, WINDOWS_1252}; use enum_map::{EnumMap, enum_map}; -use itertools::Itertools; use crate::{ data::Datum, @@ -255,7 +254,7 @@ impl LightTable { } }), title: Some(Box::new( - self.titles.title.decode(encoding, &footnotes, warn), + self.titles.user_title.decode(encoding, &footnotes, warn), )), subtype: Some(Box::new( self.titles.subtype.decode(encoding, &footnotes, warn), @@ -1762,7 +1761,6 @@ impl Axes { ) -> Result, (LightWarning, Vec)> { let n = self.layers.len() + self.rows.len() + self.columns.len(); if n != dimensions.len() { - // Warn, then treat all of the dimensions as rows. return Err(( LightWarning::WrongAxisCount { expected: dimensions.len(), @@ -1779,19 +1777,34 @@ impl Axes { dimensions.iter().map(move |d| (axis, *d as usize)) } - let mut axes = vec![None; n]; + let mut dimensions = dimensions.into_iter().map(Some).collect::>(); + let mut output = Vec::with_capacity(n); + for (axis, index) in axis_dims(Axis3::Z, &self.layers) .chain(axis_dims(Axis3::Y, &self.rows)) .chain(axis_dims(Axis3::X, &self.columns)) { - if index >= n { - return Err((LightWarning::InvalidDimensionIndex { index, n }, dimensions)); - } else if axes[index].is_some() { - return Err((LightWarning::DuplicateDimensionIndex(index), dimensions)); + let result = dimensions + .get_mut(index) + .ok_or(LightWarning::InvalidDimensionIndex { index, n }) + .and_then(|dimension| { + dimension + .take() + .ok_or(LightWarning::DuplicateDimensionIndex(index)) + }); + match result { + Ok(dimension) => output.push((axis, dimension)), + Err(error) => { + let dimensions = dimensions + .into_iter() + .flatten() + .chain(output.into_iter().map(|(_axis, dimension)| dimension)) + .collect(); + return Err((error, dimensions)); + } } - axes[index] = Some(axis); } - Ok(axes.into_iter().flatten().zip_eq(dimensions).collect()) + Ok(output) } } diff --git a/rust/pspp/src/spv/read/tests.rs b/rust/pspp/src/spv/read/tests.rs index 57e24a961c..bda6783e94 100644 --- a/rust/pspp/src/spv/read/tests.rs +++ b/rust/pspp/src/spv/read/tests.rs @@ -13,11 +13,19 @@ use crate::{ spv::SpvArchive, }; +/// Checks that reordering categories works properly. #[test] fn light1() { test_raw_spvfile("light1", None); } +/// Checks that dimensions are ordered properly and that the title reflects the +/// user's changes. +#[test] +fn light2() { + test_raw_spvfile("light2", None); +} + #[test] fn legacy1() { test_raw_spvfile("legacy1", None); diff --git a/rust/pspp/src/spv/testdata/light2.expected b/rust/pspp/src/spv/testdata/light2.expected new file mode 100644 index 0000000000..5650a27ede --- /dev/null +++ b/rust/pspp/src/spv/testdata/light2.expected @@ -0,0 +1,24 @@ + Crosstabulation +╭──────────────────────────────┬───────────────────────┬──────╮ +│ │ Variable B │ │ +│ ├──────┬────────┬───────┤ │ +│ │Normal│Marginal│Extreme│ Total│ +├──────────────────────────────┼──────┼────────┼───────┼──────┤ +│Variable A Less Count │ 10│ 7.0│ 45.5%│ 52.6%│ +│ Expected Count│ 18.2%│ 20.0%│ 6.7%│ 22│ +│ % within A │ 15.0%│ 13│ 13.3│ 34.2%│ +│ % within B │ 38.0│ 100.0%│ 63.3%│ 63.3%│ +│ % of Total │100.0%│ 35.0%│ 20│ 20.0│ +│ ╶───────────────────┼──────┼────────┼───────┼──────┤ +│ More Count │ 16.7%│ 8│ 7.7│ 36.4%│ +│ Expected Count│ 22.0│ 100.0%│ 36.7%│ 36.7%│ +│ % within A │ 61.9%│ 21.7%│ 16│ 12.7│ +│ % within B │ 19│ 19.0│ 31.7%│100.0%│ +│ % of Total │ 33.3%│ 100.0%│ 33.3%│ 60│ +├──────────────────────────────┼──────┼────────┼───────┼──────┤ +│Total Count │ 38.1%│ 13.3%│ 4│ 7.3│ +│ Expected Count│ 9│ 12.0│ 23.7%│ 47.4%│ +│ % within A │ 42.1%│ 80.0%│ 26.7%│ 38│ +│ % within B │ 31.7%│ 21│ 21.0│ 35.0%│ +│ % of Total │ 60.0│ 100.0%│ 100.0%│100.0%│ +╰──────────────────────────────┴──────┴────────┴───────┴──────╯ diff --git a/rust/pspp/src/spv/testdata/light2.spv b/rust/pspp/src/spv/testdata/light2.spv new file mode 100644 index 0000000000000000000000000000000000000000..9e9210cb4b260e1a4c9e9d72cf5f38025eb40138 GIT binary patch literal 2290 zcmaKtc|4T+9>*WdWEq#SWGmrBWQ$~*4Cy%284P1ID2=J-cx#HEhixdt4 zctA6J0I;()WuXWXrzAUknu3};RWl57ptY&hZKPzw(LMHPcf!D6i43jZZ=H-|6uOBu zc0ROw(aysj)X3%x{`;KWV|n(7mD6P-r&qlE$}~&YlEQ3`_#Y`@bF!R*VyB^^?uBmR z)W&qvgWo4*y1kNRM?;r?>KR8)9g0{dKhQR?UwhHl5-l#l2yQHhutJ>cI57Q8v}n#) z!~f>}Y17*BV5VqXWoR_1Kq@kNGN^XBbzUOPeXz}lj&7&949X_0UPWHW@t{l|@DT_Y zy&0}|s#_*hp+$RSw(ZXN+br35aQxvB=J?hPodGwgk=%t>Bo(c1_$3Z(PCYW3Xd74L z80MDk+e?k63@X@1A>Q5_(5{)&D=;fr`Je%7vW#(FQb4aI3@+MjJd|v98?aT2%44K= zovk|I_W)B~TZ}fWV_iz#6ira7XV1E1&gEiSUQ~efI0URg(u~Hf2!r%w-n=JXM_ncr z-mNdG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