Skip to content

Commit

Permalink
chore: add more tests for allocated
Browse files Browse the repository at this point in the history
  • Loading branch information
polazarus committed Aug 12, 2023
1 parent 0a7fd55 commit 0056d20
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/raw/allocated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,38 @@ impl<B: Backend> Allocated<B> {
})
}
}

#[cfg(test)]
mod tests {
use super::Allocated;
use crate::Local;

#[test]
fn test_clone() {
let allocated = Allocated::<Local>::new(vec![]);
let _clone = allocated.clone();
let local = unsafe { Local::from_raw(allocated.owner) };
let count = Local::strong_count(&local);
let _ = Local::into_raw(local);
assert_eq!(count, 1);
}

#[test]
fn test_try_into_vec() {
let allocated = Allocated::<Local>::new(vec![0, 1, 2]);
{
let local = unsafe { Local::from_raw(allocated.owner) };
let result = allocated.slice(1..2).try_into_vec();
let count = Local::strong_count(&local);
let _ = Local::into_raw(local);
assert_eq!(count, 2);
assert!(result.is_err());
}

let local = unsafe { Local::from_raw(allocated.owner) };
let count = Local::strong_count(&local);
let _ = Local::into_raw(local);
assert_eq!(count, 1);
assert!(allocated.try_into_vec().is_ok());
}
}

0 comments on commit 0056d20

Please sign in to comment.