From 2e9818b0489e787c4793de3828094314692f240d Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 12 Apr 2025 08:41:10 -0700 Subject: [PATCH] more footnote tests --- rust/pspp/src/output/pivot/mod.rs | 8 -- rust/pspp/src/output/pivot/output.rs | 9 +- rust/pspp/src/output/pivot/test.rs | 127 +++++++++++++++++++++++++-- 3 files changed, 125 insertions(+), 19 deletions(-) diff --git a/rust/pspp/src/output/pivot/mod.rs b/rust/pspp/src/output/pivot/mod.rs index 0eefb99b16..db15eda5ca 100644 --- a/rust/pspp/src/output/pivot/mod.rs +++ b/rust/pspp/src/output/pivot/mod.rs @@ -1408,14 +1408,6 @@ where } impl PivotTable { - /* - fn new(title: Box, look: Arc) -> Self { - Self { - title: Some(title), - look, - ..Self::default() - } - }*/ pub fn new(title: impl Into, dimensions_and_axes: Vec<(Axis3, Dimension)>) -> Self { let mut dimensions = Vec::new(); let mut axes = EnumMap::::default(); diff --git a/rust/pspp/src/output/pivot/output.rs b/rust/pspp/src/output/pivot/output.rs index d82fff5ccc..844e3f3165 100644 --- a/rust/pspp/src/output/pivot/output.rs +++ b/rust/pspp/src/output/pivot/output.rs @@ -297,7 +297,6 @@ impl PivotTable { fn collect_footnotes<'a>(&self, tables: impl Iterator) -> Vec> { 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(), + ); } } } diff --git a/rust/pspp/src/output/pivot/test.rs b/rust/pspp/src/output/pivot/test.rs index 3c0dfa5fed..a956b5c4f1 100644 --- a/rust/pspp/src/output/pivot/test.rs +++ b/rust/pspp/src/output/pivot/test.rs @@ -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())); -- 2.30.2