Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Apr 30, 2021
1 parent 987420d commit 1649ec2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/engine-jit/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,23 @@ pub fn pad_and_extend<T>(prev_data: &mut Vec<u8>, data: &[u8]) -> usize {
prev_data.extend(data);
offset
}

#[cfg(test)]
mod tests {
use super::pad_and_extend;

#[test]
fn test_pad_and_extend() {
let mut data: Vec<u8> = vec![];
let offset = pad_and_extend::<i64>(&mut data, &[1, 0, 0, 0, 0, 0, 0, 0]);
assert_eq!(offset, 0);
let offset = pad_and_extend::<i32>(&mut data, &[2, 0, 0, 0]);
assert_eq!(offset, 8);
let offset = pad_and_extend::<i64>(&mut data, &[3, 0, 0, 0, 0, 0, 0, 0]);
assert_eq!(offset, 16);
assert_eq!(
data,
&[1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0]
);
}
}

0 comments on commit 1649ec2

Please sign in to comment.