From 2227c43c1035dd205362ecafa1a50aba36a11a39 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 22 Mar 2025 11:29:12 -0700 Subject: [PATCH] add cc tests --- rust/pspp/src/format/mod.rs | 46 ++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/rust/pspp/src/format/mod.rs b/rust/pspp/src/format/mod.rs index 9f85588eed..342891a658 100644 --- a/rust/pspp/src/format/mod.rs +++ b/rust/pspp/src/format/mod.rs @@ -857,6 +857,10 @@ impl StyleSet { } impl Settings { + pub fn with_cc(mut self, cc: CC, style: NumberStyle) -> Self { + self.ccs[cc] = Some(Box::new(style)); + self + } fn number_style(&self, type_: Type) -> &NumberStyle { static DEFAULT: LazyLock = LazyLock::new(|| NumberStyle::new("", "", Decimal::Dot, None, false)); @@ -1040,12 +1044,11 @@ impl FromStr for NumberStyle { let mut s = String::new(); let mut quote = false; for c in iter { - if c == '\'' { + if c == '\'' && !quote { quote = true; + } else if c == grouping && !quote { + break; } else { - if c == grouping && !quote { - break; - } s.push(c); quote = false; } @@ -1969,7 +1972,7 @@ mod test { use crate::{ dictionary::Value, - format::{AbstractFormat, Format, Settings, UncheckedFormat}, + format::{AbstractFormat, Format, NumberStyle, Settings, UncheckedFormat, CC}, lex::{ scan::StringScanner, segment::Syntax, @@ -1982,7 +1985,12 @@ mod test { .join("src/format/testdata") .join(name); let input = BufReader::new(File::open(&filename).unwrap()); - let settings = Settings::default(); + let settings = Settings::default() + .with_cc(CC::A, ",,,".parse().unwrap()) + .with_cc(CC::B, "-,[[[,]]],-".parse().unwrap()) + .with_cc(CC::C, "((,[,],))".parse().unwrap()) + .with_cc(CC::D, ",XXX,,-".parse().unwrap()) + .with_cc(CC::E, ",,YYY,-".parse().unwrap()); let mut value = 0.0; let mut value_name = String::new(); for (line_number, line) in input.lines().map(|r| r.unwrap()).enumerate() { @@ -2015,6 +2023,7 @@ mod test { let expected = tokens[2].as_string().unwrap(); let actual = Value::Number(Some(value)) .display(format, UTF_8) + .with_settings(&settings) .to_string(); assert_eq!( expected, @@ -2067,4 +2076,29 @@ mod test { fn z() { test("z.txt"); } + + #[test] + fn cca() { + test("cca.txt"); + } + + #[test] + fn ccb() { + test("ccb.txt"); + } + + #[test] + fn ccc() { + test("ccc.txt"); + } + + #[test] + fn ccd() { + test("ccd.txt"); + } + + #[test] + fn cce() { + test("cce.txt"); + } } -- 2.30.2