Skip to content

Commit

Permalink
Add extra tests for naked prefixes with new key type
Browse files Browse the repository at this point in the history
  • Loading branch information
ueco-jb committed Nov 15, 2021
1 parent f0cfa5c commit 61dbbd1
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/storage-plus/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,45 @@ mod test {
);
}

#[test]
fn naked_8bit_prefixes() {
let pair: (u8, &[u8]) = (123, b"random");
let one: Vec<u8> = vec![123];
let two: Vec<u8> = b"random".to_vec();
assert_eq!(pair.prefix(), vec![one.as_slice(), two.as_slice()]);

let pair: (i8, &[u8]) = (123, b"random");
let one: Vec<u8> = vec![123];
let two: Vec<u8> = b"random".to_vec();
assert_eq!(pair.prefix(), vec![one.as_slice(), two.as_slice()]);
}

#[test]
fn naked_16bit_prefixes() {
let pair: (u16, &[u8]) = (12345, b"random");
let one: Vec<u8> = vec![48, 57];
let two: Vec<u8> = b"random".to_vec();
assert_eq!(pair.prefix(), vec![one.as_slice(), two.as_slice()]);

let pair: (i16, &[u8]) = (12345, b"random");
let one: Vec<u8> = vec![48, 57];
let two: Vec<u8> = b"random".to_vec();
assert_eq!(pair.prefix(), vec![one.as_slice(), two.as_slice()]);
}

#[test]
fn naked_64bit_prefixes() {
let pair: (u64, &[u8]) = (12345, b"random");
let one: Vec<u8> = vec![0, 0, 0, 0, 0, 0, 48, 57];
let two: Vec<u8> = b"random".to_vec();
assert_eq!(pair.prefix(), vec![one.as_slice(), two.as_slice()]);

let pair: (i64, &[u8]) = (12345, b"random");
let one: Vec<u8> = vec![0, 0, 0, 0, 0, 0, 48, 57];
let two: Vec<u8> = b"random".to_vec();
assert_eq!(pair.prefix(), vec![one.as_slice(), two.as_slice()]);
}

#[test]
fn naked_proper_prefixes() {
let pair: (u32, &[u8]) = (12345, b"random");
Expand Down

0 comments on commit 61dbbd1

Please sign in to comment.