more footnote tests
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 12 Apr 2025 15:41:10 +0000 (08:41 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 12 Apr 2025 15:41:10 +0000 (08:41 -0700)
rust/pspp/src/output/pivot/mod.rs
rust/pspp/src/output/pivot/output.rs
rust/pspp/src/output/pivot/test.rs

index 0eefb99b16648619a4e4f74a58866961f74aa257..db15eda5cae5dc2229388a8bd62cb85b1a93deb4 100644 (file)
@@ -1408,14 +1408,6 @@ where
 }
 
 impl PivotTable {
-    /*
-    fn new(title: Box<Value>, look: Arc<Look>) -> Self {
-        Self {
-            title: Some(title),
-            look,
-            ..Self::default()
-        }
-    }*/
     pub fn new(title: impl Into<Value>, dimensions_and_axes: Vec<(Axis3, Dimension)>) -> Self {
         let mut dimensions = Vec::new();
         let mut axes = EnumMap::<Axis3, Axis>::default();
index d82fff5ccc6553a869ae1e06e158a176aaccd928..844e3f3165bf9f39cea5f24e9cb5ed6f503e4413 100644 (file)
@@ -297,7 +297,6 @@ impl PivotTable {
 
     fn collect_footnotes<'a>(&self, tables: impl Iterator<Item = &'a Table>) -> Vec<Arc<Footnote>> {
         if self.footnotes.is_empty() {
-            dbg!();
             return Vec::new();
         }
 
@@ -305,7 +304,13 @@ impl PivotTable {
         for table in tables {
             for cell in table.cells() {
                 if let Some(styling) = &cell.inner().value.styling {
-                    refs.extend(styling.footnotes.iter().cloned());
+                    refs.extend(
+                        styling
+                            .footnotes
+                            .iter()
+                            .filter(|footnote| footnote.show)
+                            .cloned(),
+                    );
                 }
             }
         }
index 3c0dfa5fed0fbd02ef96ee28555a5bfa4461a931..a956b5c4f127c729e972fd8cce5ff21f31645af5 100644 (file)
@@ -3,8 +3,9 @@ use std::sync::Arc;
 use enum_map::EnumMap;
 
 use crate::output::pivot::{
-    Area, Axis2, Border, BorderStyle, Class, Color, Dimension, Footnote, Footnotes, Group,
-    HeadingRegion, LabelPosition, Look, PivotTable, RowColBorder, Stroke,
+    Area, Axis2, Border, BorderStyle, Class, Color, Dimension, Footnote, FootnoteMarkerPosition,
+    FootnoteMarkerType, Footnotes, Group, HeadingRegion, LabelPosition, Look, PivotTable,
+    RowColBorder, Stroke,
 };
 
 use super::{Axis3, Value};
@@ -549,10 +550,13 @@ Caption
     );
 }
 
-#[test]
-fn footnotes() {
+fn footnote_table(show_f0: bool) -> PivotTable {
     let mut footnotes = Footnotes::new();
-    let f0 = footnotes.push(Footnote::new("First footnote").with_marker("*"));
+    let f0 = footnotes.push(
+        Footnote::new("First footnote")
+            .with_marker("*")
+            .with_show(show_f0),
+    );
     let f1 = footnotes.push(Footnote::new("Second footnote"));
     let a = (
         Axis3::X,
@@ -586,17 +590,20 @@ fn footnotes() {
             .with_footnote(&f0)
             .with_footnote(&f1),
     );
-    let pt = pt
-        .with_look(Arc::new(look))
+    pt.with_look(Arc::new(look))
         .with_footnotes(footnotes)
         .with_caption(Value::new_text("Caption").with_footnote(&f0))
         .with_corner_text(
             Value::new_text("Corner")
                 .with_footnote(&f0)
                 .with_footnote(&f1),
-        );
+        )
+}
+
+#[test]
+fn footnote_alphabetic_subscript() {
     assert_rendering(
-        &pt,
+        &footnote_table(true),
         "\
 Pivot Table with Alphabetic Subscript Footnotes[*]
 ╭────────────┬──────────────────╮
@@ -614,6 +621,108 @@ b. Second footnote
     );
 }
 
+#[test]
+fn footnote_alphabetic_superscript() {
+    let mut pt = footnote_table(true);
+    let f0 = pt.footnotes.0[0].clone();
+    pt = pt.with_title(
+        Value::new_text("Pivot Table with Alphabetic Superscript Footnotes").with_footnote(&f0),
+    );
+    pt.look_mut().footnote_marker_position = FootnoteMarkerPosition::Superscript;
+    assert_rendering(
+        &pt,
+        "\
+Pivot Table with Alphabetic Superscript Footnotes[*]
+╭────────────┬──────────────────╮
+│            │       A[*]       │
+│            ├───────┬──────────┤
+│Corner[*][b]│  B[b] │  C[*][b] │
+├────────────┼───────┼──────────┤
+│D[b] E[*]   │    .00│   1.00[*]│
+│     F[*][b]│2.00[b]│3.00[*][b]│
+╰────────────┴───────┴──────────╯
+Caption[*]
+*. First footnote
+b. Second footnote
+",
+    );
+}
+
+#[test]
+fn footnote_numeric_subscript() {
+    let mut pt = footnote_table(true);
+    let f0 = pt.footnotes.0[0].clone();
+    pt = pt.with_title(
+        Value::new_text("Pivot Table with Numeric Subscript Footnotes").with_footnote(&f0),
+    );
+    pt.look_mut().footnote_marker_type = FootnoteMarkerType::Numeric;
+    assert_rendering(
+        &pt,
+        "\
+Pivot Table with Numeric Subscript Footnotes[*]
+╭────────────┬──────────────────╮
+│            │       A[*]       │
+│            ├───────┬──────────┤
+│Corner[*][2]│  B[2] │  C[*][2] │
+├────────────┼───────┼──────────┤
+│D[2] E[*]   │    .00│   1.00[*]│
+│     F[*][2]│2.00[2]│3.00[*][2]│
+╰────────────┴───────┴──────────╯
+Caption[*]
+*. First footnote
+2. Second footnote
+",
+    );
+}
+
+#[test]
+fn footnote_numeric_superscript() {
+    let mut pt = footnote_table(true);
+    let f0 = pt.footnotes.0[0].clone();
+    pt = pt.with_title(
+        Value::new_text("Pivot Table with Numeric Superscript Footnotes").with_footnote(&f0),
+    );
+    pt.look_mut().footnote_marker_type = FootnoteMarkerType::Numeric;
+    pt.look_mut().footnote_marker_position = FootnoteMarkerPosition::Superscript;
+    assert_rendering(
+        &pt,
+        "\
+Pivot Table with Numeric Superscript Footnotes[*]
+╭────────────┬──────────────────╮
+│            │       A[*]       │
+│            ├───────┬──────────┤
+│Corner[*][2]│  B[2] │  C[*][2] │
+├────────────┼───────┼──────────┤
+│D[2] E[*]   │    .00│   1.00[*]│
+│     F[*][2]│2.00[2]│3.00[*][2]│
+╰────────────┴───────┴──────────╯
+Caption[*]
+*. First footnote
+2. Second footnote
+",
+    );
+}
+
+#[test]
+fn footnote_hidden() {
+    assert_rendering(
+        &footnote_table(false),
+        "\
+Pivot Table with Alphabetic Subscript Footnotes[*]
+╭────────────┬──────────────────╮
+│            │       A[*]       │
+│            ├───────┬──────────┤
+│Corner[*][b]│  B[b] │  C[*][b] │
+├────────────┼───────┼──────────┤
+│D[b] E[*]   │    .00│   1.00[*]│
+│     F[*][b]│2.00[b]│3.00[*][b]│
+╰────────────┴───────┴──────────╯
+Caption[*]
+b. Second footnote
+",
+    );
+}
+
 #[test]
 fn no_dimension() {
     let pivot_table = PivotTable::new("No Dimensions", vec![]).with_look(Arc::new(test_look()));