test non-ascii custom currency
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 24 Mar 2025 01:24:12 +0000 (18:24 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 24 Mar 2025 01:24:12 +0000 (18:24 -0700)
rust/pspp/src/format/mod.rs

index c49d4a2226d4c6da73ee268b406ad7a2edad644e..d444a8c4e8f1d2c538060601b8566cd63549ca8a 100644 (file)
@@ -2154,4 +2154,26 @@ mod test {
         test.test(-0.99, [" -.99", " -1.0"], ["-0.99", " -1.0"]);
         test.test(-0.01, [" -.01", "   .0"], ["-0.01", "  0.0"]);
     }
+
+    #[test]
+    fn non_ascii_cc() {
+        fn test(settings: &Settings, value: f64, expected: &str) {
+            assert_eq!(
+                &Value::from(value)
+                    .display(Format::new(Type::CC(CC::A), 10, 2).unwrap(), UTF_8)
+                    .with_settings(settings)
+                    .to_string(),
+                expected
+            );
+        }
+
+        let settings = Settings::default().with_cc(CC::A, "«,¥,€,»".parse().unwrap());
+        test(&settings, 1.0, "   ¥1.00€ ");
+        test(&settings, -1.0, "  «¥1.00€»");
+        test(&settings, 1.5, "   ¥1.50€ ");
+        test(&settings, -1.5, "  «¥1.50€»");
+        test(&settings, 0.75, "    ¥.75€ ");
+        test(&settings, 1.5e10, " ¥2E+010€ ");
+        test(&settings, -1.5e10, "«¥2E+010€»");
+    }
 }