generated from PlexSheep/rs-base
Compare commits
3 commits
cd7f7cc376
...
1f91710bda
Author | SHA1 | Date | |
---|---|---|---|
1f91710bda | |||
b681a6b04d | |||
fe01412467 |
1 changed files with 45 additions and 0 deletions
|
@ -92,3 +92,48 @@ fn format_padding() {
|
||||||
"QUFBQUFBQUE="
|
"QUFBQUFBQUE="
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn format_prefix() {
|
||||||
|
let mut options = FormatOptions::default();
|
||||||
|
options.set_prefix(true);
|
||||||
|
|
||||||
|
assert_eq!(Format::Dec.format(1337, &options), "0d1337");
|
||||||
|
assert_eq!(
|
||||||
|
Format::Dec.format(u128::MAX, &options),
|
||||||
|
format!("0d{}", u128::MAX)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(Format::Hex.format(0x1337, &options), "0x1337");
|
||||||
|
assert_eq!(
|
||||||
|
Format::Hex.format(u128::MAX, &options),
|
||||||
|
format!("0x{:X}", u128::MAX)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Format::Bin.format(0b1010001001010010010100111, &options),
|
||||||
|
"0b1010001001010010010100111"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
Format::Bin.format(u128::MAX, &options),
|
||||||
|
format!("0b{:b}", u128::MAX)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(Format::Octal.format(0o13377331, &options), "0o13377331");
|
||||||
|
assert_eq!(
|
||||||
|
Format::Octal.format(u128::MAX, &options),
|
||||||
|
format!("0o{:o}", u128::MAX)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(Format::Base32.format(0x41414242, &options), "032sIFAUEQQ=");
|
||||||
|
assert_eq!(
|
||||||
|
Format::Base32.format(0x4141414141414141, &options),
|
||||||
|
"032sIFAUCQKBIFAUC==="
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(Format::Base64.format(0x41414242, &options), "0sQUFCQg==");
|
||||||
|
assert_eq!(
|
||||||
|
Format::Base64.format(0x4141414141414141, &options),
|
||||||
|
"0sQUFBQUFBQUE="
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Reference in a new issue