| 1 |
use hex_literal::hex; |
| 2 |
|
| 3 |
#[test] |
| 4 |
fn single_literal() { |
| 5 |
assert_eq!(hex!("ff e4"), [0xff, 0xe4]); |
| 6 |
} |
| 7 |
|
| 8 |
#[test] |
| 9 |
fn empty() { |
| 10 |
let nothing: [u8; 0] = hex!(); |
| 11 |
let empty_literals: [u8; 0] = hex!("" "" ""); |
| 12 |
let expected: [u8; 0] = []; |
| 13 |
assert_eq!(nothing, expected); |
| 14 |
assert_eq!(empty_literals, expected); |
| 15 |
} |
| 16 |
|
| 17 |
#[test] |
| 18 |
fn upper_case() { |
| 19 |
assert_eq!(hex!("AE DF 04 B2"), [0xae, 0xdf, 0x04, 0xb2]); |
| 20 |
assert_eq!(hex!("FF BA 8C 00 01"), [0xff, 0xba, 0x8c, 0x00, 0x01]); |
| 21 |
} |
| 22 |
|
| 23 |
#[test] |
| 24 |
fn mixed_case() { |
| 25 |
assert_eq!(hex!("bF dd E4 Cd"), [0xbf, 0xdd, 0xe4, 0xcd]); |
| 26 |
} |
| 27 |
|
| 28 |
#[test] |
| 29 |
fn multiple_literals() { |
| 30 |
assert_eq!( |
| 31 |
hex!( |
| 32 |
"01 dd f7 7f" |
| 33 |
"ee f0 d8" |
| 34 |
), |
| 35 |
[0x01, 0xdd, 0xf7, 0x7f, 0xee, 0xf0, 0xd8] |
| 36 |
); |
| 37 |
assert_eq!( |
| 38 |
hex!( |
| 39 |
"ff" |
| 40 |
"e8 d0" |
| 41 |
"" |
| 42 |
"01 1f" |
| 43 |
"ab" |
| 44 |
), |
| 45 |
[0xff, 0xe8, 0xd0, 0x01, 0x1f, 0xab] |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
#[test] |
| 50 |
fn no_spacing() { |
| 51 |
assert_eq!(hex!("abf0d8bb0f14"), [0xab, 0xf0, 0xd8, 0xbb, 0x0f, 0x14]); |
| 52 |
assert_eq!( |
| 53 |
hex!("09FFd890cbcCd1d08F"), |
| 54 |
[0x09, 0xff, 0xd8, 0x90, 0xcb, 0xcc, 0xd1, 0xd0, 0x8f] |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
#[test] |
| 59 |
fn allows_various_spacing() { |
| 60 |
// newlines |
| 61 |
assert_eq!( |
| 62 |
hex!( |
| 63 |
"f |
| 64 |
f |
| 65 |
d |
| 66 |
0 |
| 67 |
e |
| 68 |
|
| 69 |
8 |
| 70 |
" |
| 71 |
), |
| 72 |
[0xff, 0xd0, 0xe8] |
| 73 |
); |
| 74 |
// tabs |
| 75 |
assert_eq!(hex!("9f d 1 f07 3 01 "), [0x9f, 0xd1, 0xf0, 0x73, 0x01]); |
| 76 |
// spaces |
| 77 |
assert_eq!(hex!(" e e d0 9 1 f f "), [0xee, 0xd0, 0x91, 0xff]); |
| 78 |
} |
| 79 |
|
| 80 |
#[test] |
| 81 |
fn can_use_const() { |
| 82 |
const _: [u8; 4] = hex!("ff d3 01 7f"); |
| 83 |
} |