mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 05:34:14 +00:00
Merge branch 'master' into display-uses-tokens
This commit is contained in:
commit
c90650a2d1
2 changed files with 27 additions and 0 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue