From fae04d37cd3471af9ae8039e013801db2327de6f Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 9 Dec 2025 15:50:47 -0800 Subject: [PATCH] work --- rust/pspp/src/output/pivot.rs | 40 +++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/rust/pspp/src/output/pivot.rs b/rust/pspp/src/output/pivot.rs index 4bbcf2dab9..3a60b2d6d9 100644 --- a/rust/pspp/src/output/pivot.rs +++ b/rust/pspp/src/output/pivot.rs @@ -3142,7 +3142,7 @@ impl TemplateValue { if let Some(index) = index.checked_sub(1) && let Some(arg) = args.get(index) { - args_consumed = args_consumed.max(index); + args_consumed = args_consumed.max(index + 1); write!(f, "{}", arg.display(display.options))?; } } @@ -3381,7 +3381,8 @@ mod test { use std::str::FromStr; use crate::output::pivot::{ - Color, Display26Adic, MetadataEntry, MetadataValue, Value, tests::assert_rendering, + Color, Display26Adic, MetadataEntry, MetadataValue, TemplateValue, Value, ValueInner, + tests::assert_rendering, }; #[test] @@ -3413,6 +3414,41 @@ mod test { } } + #[test] + fn template() { + for (template, expected) in [ + ( + "1: [:^1,:]1; [:^1,:]2", + "1: First,1.00,Second,2,; Third,3.00,Fourth,4,", + ), + (r#"2: [:^1\n:]1"#, "2: First\n1.00\nSecond\n2\n"), + (r#"3: [:^1 = ^2\n:]1"#, "3: First = 1.00\nSecond = 2\n"), + ("4: [%1:, ^1:]1", "4: First, 1.00, Second, 2"), + ("5: [%1 = %2:, ^1 = ^2:]1", "5: First = 1.00, Second = 2"), + ("6: [%1:, ^1:]1", "6: First, 1.00, Second, 2"), + ] { + let value = Value::new(ValueInner::Template(TemplateValue { + args: vec![ + vec![ + Value::new_user_text("First"), + Value::new_number(Some(1.0)), + Value::new_user_text("Second"), + Value::new_integer(Some(2.0)), + ], + vec![ + Value::new_user_text("Third"), + Value::new_number(Some(3.0)), + Value::new_user_text("Fourth"), + Value::new_integer(Some(4.0)), + ], + ], + localized: String::from(template), + id: None, + })); + assert_eq!(value.display(()).to_string(), expected); + } + } + #[test] fn metadata_entry() { let tree = MetadataEntry { -- 2.30.2