Merge branch 'master' into display-uses-tokens

This commit is contained in:
Tiffany Bennett 2024-06-02 13:51:40 -07:00
commit c90650a2d1
2 changed files with 27 additions and 0 deletions

View file

@ -286,3 +286,25 @@ impl fmt::Display for NumberParts {
write!(fmt, "{}", self.format("n u w"))
}
}
#[cfg(test)]
mod tests {
use crate::types::{BaseUnit, Number, Numeric};
#[test]
fn test_fmt() {
let number = Number::new_unit(Numeric::from(42), BaseUnit::new("m"));
let ctx = crate::simple_context().unwrap();
let parts = number.to_parts(&ctx);
assert_eq!(parts.format("e"), "42");
assert_eq!(parts.format("a"), "");
assert_eq!(parts.format("u"), "meter");
assert_eq!(parts.format("q"), "length");
assert_eq!(parts.format("w"), "(length)");
assert_eq!(parts.format("d"), "m");
assert_eq!(parts.format("D"), "m");
assert_eq!(parts.format("p"), "(length; m)");
assert_eq!(parts.format("VALUE: e"), "VALUE: 42");
}
}

View file

@ -874,3 +874,8 @@ fn conversion_to_digit_errors() {
"Conversion to digits of US/Pacific is not defined",
);
}
#[test]
fn test_conversion_multiples() {
test("floppydisk to 512B", "2880 * 512 byte (information)");
}