support multiple setFormat inside setCellProperties rust
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 27 Dec 2025 01:20:33 +0000 (17:20 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 27 Dec 2025 01:20:33 +0000 (17:20 -0800)
rust/pspp/src/spv/read/legacy_xml.rs
rust/pspp/src/spv/read/tests.rs

index e9e1d9c1058b94251701ab330f738fbc38129455..c7fda83c11782b095b6b64dc7ad3b43be95d25ca 100644 (file)
@@ -798,8 +798,6 @@ impl Visualization {
 
             #[derive(Default, Debug)]
             struct Target<'a> {
-                labeling: Option<&'a Style>,
-                major_ticks: Option<&'a Style>,
                 format: Option<(&'a SetFormat, Option<TargetType>)>,
             }
             impl<'a> Target<'a> {
@@ -928,24 +926,15 @@ impl Visualization {
                     }
                 }
             }
-            let mut target = Target::default();
+            let mut targets = Vec::new();
             for set in &scp.sets {
                 match set {
-                    Set::SetStyle(set_style) => {
-                        if let Some(style) = set_style.style.get(&styles) {
-                            match TargetType::from_id(&set_style.target, graph, &major_ticks) {
-                                Some(TargetType::Labeling) => target.labeling = Some(style),
-                                Some(TargetType::MajorTicks) => target.major_ticks = Some(style),
-                                Some(TargetType::Interval) | Some(TargetType::Graph) | None => (),
-                            }
-                        }
-                    }
+                    Set::SetStyle(_) => (),
                     Set::SetFormat(sf) => {
                         let target_type = TargetType::from_id(&sf.target, graph, &major_ticks);
-                        if target.format.is_some() {
-                            dbg!();
-                        }
-                        target.format = Some((sf, target_type))
+                        targets.push(Target {
+                            format: Some((sf, target_type)),
+                        });
                     }
                     Set::SetFrameStyle(_) => (),
                     Set::SetMetaData(_) => (),
@@ -958,36 +947,39 @@ impl Visualization {
             ) {
                 (Some(union_), false) => {
                     for intersect in &union_.intersects {
-                        target.decode(
-                            scp,
-                            intersect,
-                            &mut look,
-                            &series,
-                            dims.as_mut_slice(),
-                            &mut data,
-                            &footnotes,
-                            cell_footnotes.is_some(),
-                        );
+                        for target in &targets {
+                            target.decode(
+                                scp,
+                                intersect,
+                                &mut look,
+                                &series,
+                                dims.as_mut_slice(),
+                                &mut data,
+                                &footnotes,
+                                cell_footnotes.is_some(),
+                            );
+                        }
                     }
                 }
                 (Some(_), true) => {
                     // Not implemented, not seen in the corpus.
                 }
                 (None, true) => {
-                    if target
-                        .format
-                        .is_some_and(|(_sf, target_type)| target_type == Some(TargetType::Labeling))
-                    {
-                        for value in data.values_mut() {
-                            Style::apply_to_value(
-                                value,
-                                target.format.map(|(sf, _target_type)| sf),
-                                None,
-                                None,
-                                &look.areas[Area::Data(RowParity::Even)],
-                                &footnotes,
-                                cell_footnotes.is_some(),
-                            );
+                    for target in &targets {
+                        if target.format.is_some_and(|(_sf, target_type)| {
+                            target_type == Some(TargetType::Labeling)
+                        }) {
+                            for value in data.values_mut() {
+                                Style::apply_to_value(
+                                    value,
+                                    target.format.map(|(sf, _target_type)| sf),
+                                    None,
+                                    None,
+                                    &look.areas[Area::Data(RowParity::Even)],
+                                    &footnotes,
+                                    cell_footnotes.is_some(),
+                                );
+                            }
                         }
                     }
                 }
index b850bca2268b9fe6cd8440994c170f90f6211020..fb7456b1d0bbd44f12e8afa8ba40fb3a4b3fc678 100644 (file)
@@ -82,6 +82,13 @@ fn legacy12() {
     test_raw_spvfile("legacy12");
 }
 
+/// Checks that we support multiple `<setFormat>` elements within a single
+/// `<setCellProperties>`.
+#[test]
+fn legacy13() {
+    test_raw_spvfile("legacy13");
+}
+
 fn test_raw_spvfile(name: &str) {
     let input_filename = Path::new("src/spv/testdata")
         .join(name)