summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandro Pischinger <mail@sandropischinger.de>2023-12-03 22:25:52 +0100
committerSandro Pischinger <mail@sandropischinger.de>2023-12-03 22:25:52 +0100
commitee07830f9119a83d05fd1b65c0a6cb97a7764d67 (patch)
tree9f685333237211b6acfa4f4016c6c28ece7c5cc3
parentd39a0cfa8d6275de6593f4e28b42b38ed492262d (diff)
extend tests for no prefix option
-rw-r--r--src/lib.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index fa34f29..7f3c141 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -534,32 +534,56 @@ mod tests {
#[test]
pub fn test_hex_octal() {
let b: u8 = 0x6;
+
+ //with prefix
assert_eq!(Format::Octal.format(b, true), "0o0006");
assert_eq!(Format::Octal.format(b, true), format!("{:#06o}", b));
+
+ //without prefix
+ assert_eq!(Format::Octal.format(b, false), "0006");
+ assert_eq!(Format::Octal.format(b, false), format!("{:04o}", b));
}
/// hex lower hex, takes u8
#[test]
fn test_hex_lower_hex() {
let b: u8 = <u8>::max_value(); // 255
+
+ //with prefix
assert_eq!(Format::LowerHex.format(b, true), "0xff");
assert_eq!(Format::LowerHex.format(b, true), format!("{:#04x}", b));
+
+ //without prefix
+ assert_eq!(Format::LowerHex.format(b, false), "ff");
+ assert_eq!(Format::LowerHex.format(b, false), format!("{:02x}", b));
}
/// hex upper hex, takes u8
#[test]
fn test_hex_upper_hex() {
let b: u8 = <u8>::max_value();
+
+ //with prefix
assert_eq!(Format::UpperHex.format(b, true), "0xFF");
assert_eq!(Format::UpperHex.format(b, true), format!("{:#04X}", b));
+
+ // without prefix
+ assert_eq!(Format::UpperHex.format(b, false), "FF");
+ assert_eq!(Format::UpperHex.format(b, false), format!("{:02X}", b));
}
/// hex binary, takes u8
#[test]
fn test_hex_binary() {
let b: u8 = <u8>::max_value();
+
+ // with prefix
assert_eq!(Format::Binary.format(b, true), "0b11111111");
assert_eq!(Format::Binary.format(b, true), format!("{:#010b}", b));
+
+ // without prefix
+ assert_eq!(Format::Binary.format(b, false), "11111111");
+ assert_eq!(Format::Binary.format(b, false), format!("{:08b}", b));
}
#[test]