pub const MAC_ADDRESS: &str = "1x:";
pub const DISPLAY_STRING: &str = "255a";
pub const DATE_AND_TIME: &str = "2d-1d-1d,1d:1d:1d.1d,1a1d:1d";
pub const HEX_STRING: &str = "1x";
pub const HEX_STRING_SPACED: &str = "1x ";
pub const DOTTED_DECIMAL: &str = "1d.";
pub const UTF8_STRING: &str = "255t";
pub const INTEGER_HEX: &str = "x";
pub const DECIMAL_1: &str = "d-1";
pub const DECIMAL_2: &str = "d-2";
pub const DECIMAL_3: &str = "d-3";
#[cfg(test)]
mod tests {
use super::*;
use crate::Value;
use bytes::Bytes;
#[test]
fn test_mac_address_hint() {
let mac = Value::OctetString(Bytes::from_static(&[0x00, 0x1a, 0x2b, 0x3c, 0x4d, 0x5e]));
assert_eq!(
mac.format_with_hint(MAC_ADDRESS),
Some("00:1a:2b:3c:4d:5e".to_string())
);
}
#[test]
fn test_display_string_hint() {
let desc = Value::OctetString(Bytes::from_static(b"Hello World"));
assert_eq!(
desc.format_with_hint(DISPLAY_STRING),
Some("Hello World".to_string())
);
}
#[test]
fn test_hex_string_hint() {
let data = Value::OctetString(Bytes::from_static(&[0xDE, 0xAD, 0xBE, 0xEF]));
assert_eq!(
data.format_with_hint(HEX_STRING),
Some("deadbeef".to_string())
);
}
#[test]
fn test_dotted_decimal_hint() {
let ip = Value::OctetString(Bytes::from_static(&[192, 168, 1, 1]));
assert_eq!(
ip.format_with_hint(DOTTED_DECIMAL),
Some("192.168.1.1".to_string())
);
}
#[test]
fn test_integer_decimal_hints() {
assert_eq!(
Value::Integer(2350).format_with_hint(DECIMAL_2),
Some("23.50".to_string())
);
assert_eq!(
Value::Integer(1234).format_with_hint(DECIMAL_1),
Some("123.4".to_string())
);
assert_eq!(
Value::Integer(12500).format_with_hint(DECIMAL_3),
Some("12.500".to_string())
);
}
#[test]
fn test_integer_hex_hint() {
assert_eq!(
Value::Integer(255).format_with_hint(INTEGER_HEX),
Some("ff".to_string())
);
}
#[test]
fn test_hex_string_hint_displays_as_hex() {
let data = Value::OctetString(Bytes::from_static(&[0x0f, 0xff]));
assert_eq!(data.format_with_hint(HEX_STRING), Some("0fff".to_string()));
}
#[test]
fn test_utf8_string_multibyte() {
let data = Value::OctetString(Bytes::from("café".as_bytes()));
assert_eq!(data.format_with_hint(UTF8_STRING), Some("café".to_string()));
}
}