From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/generic-array/tests/hex.rs | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 vendor/generic-array/tests/hex.rs (limited to 'vendor/generic-array/tests/hex.rs') diff --git a/vendor/generic-array/tests/hex.rs b/vendor/generic-array/tests/hex.rs new file mode 100644 index 000000000..0c63391a6 --- /dev/null +++ b/vendor/generic-array/tests/hex.rs @@ -0,0 +1,61 @@ +#[macro_use] +extern crate generic_array; +extern crate typenum; + +use generic_array::GenericArray; +use std::str::from_utf8; +use typenum::U2048; + +#[test] +fn short_lower_hex() { + let ar = arr![u8; 10, 20, 30]; + assert_eq!(format!("{:x}", ar), "0a141e"); +} + +#[test] +fn short_upper_hex() { + let ar = arr![u8; 30, 20, 10]; + assert_eq!(format!("{:X}", ar), "1E140A"); +} + +#[test] +fn long_lower_hex() { + let ar = GenericArray::::default(); + assert_eq!(format!("{:x}", ar), from_utf8(&[b'0'; 4096]).unwrap()); +} + +#[test] +fn long_lower_hex_truncated() { + let ar = GenericArray::::default(); + assert_eq!(format!("{:.3001x}", ar), from_utf8(&[b'0'; 3001]).unwrap()); +} + +#[test] +fn long_upper_hex() { + let ar = GenericArray::::default(); + assert_eq!(format!("{:X}", ar), from_utf8(&[b'0'; 4096]).unwrap()); +} + +#[test] +fn long_upper_hex_truncated() { + let ar = GenericArray::::default(); + assert_eq!(format!("{:.2777X}", ar), from_utf8(&[b'0'; 2777]).unwrap()); +} + +#[test] +fn truncated_lower_hex() { + let ar = arr![u8; 10, 20, 30, 40, 50]; + assert_eq!(format!("{:.2x}", ar), "0a"); + assert_eq!(format!("{:.3x}", ar), "0a1"); + assert_eq!(format!("{:.4x}", ar), "0a14"); +} + +#[test] +fn truncated_upper_hex() { + let ar = arr![u8; 30, 20, 10, 17, 0]; + assert_eq!(format!("{:.4X}", ar), "1E14"); + assert_eq!(format!("{:.5X}", ar), "1E140"); + assert_eq!(format!("{:.6X}", ar), "1E140A"); + assert_eq!(format!("{:.7X}", ar), "1E140A1"); + assert_eq!(format!("{:.8X}", ar), "1E140A11"); +} -- cgit v1.2.3