Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
codec: add test for type u128.
Browse files Browse the repository at this point in the history
Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang committed Oct 31, 2023
1 parent 5a9397a commit 939aec0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions codec/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,29 @@ mod tests {
use crate::codec::{Reader, Writer};
use crate::u24;

#[test]
fn test_u128() {
let u8_slice = &mut [0u8; 16];
{
let mut writer = Writer::init(u8_slice);
let value = 0x1234567890FFFEFEFFFFFE1234567890u128;
assert_eq!(value.encode(&mut writer), Ok(16));
}
let mut ser_data = [
0x12u8, 0x34, 0x56, 0x78, 0x90, 0xFF, 0xFE, 0xFE, 0xFF, 0xFF, 0xFE, 0x12, 0x34, 0x56,
0x78, 0x90,
];
ser_data.reverse();

let mut reader = Reader::init(u8_slice);
assert_eq!(16, reader.left());
assert_eq!(u8_slice, &ser_data);
assert_eq!(
u128::read(&mut reader).unwrap(),
0x1234567890FFFEFEFFFFFE1234567890u128
);
}

#[test]
fn test_u64() {
let u8_slice = &mut [0u8; 8];
Expand Down

0 comments on commit 939aec0

Please sign in to comment.