Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Oct 11, 2024
1 parent 24ba321 commit 0a7b0b6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions crates/oxc_allocator/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<'alloc, T: Hash> Hash for Vec<'alloc, T> {
#[cfg(test)]
mod test {
use super::Vec;
use crate::Allocator;
use crate::{Allocator, Box};

#[test]
fn vec_with_capacity() {
Expand Down Expand Up @@ -256,13 +256,16 @@ mod test {

#[test]
fn test_vec_to_boxed_slice() {
// file: oxc_allocator/src/vec.rs
use crate::boxed::Box;

let allocator = Allocator::default();
let v = Vec::from_iter_in([1, 2, 3], &allocator);
let b: Box<[i32]> = v.into_boxed_slice(); // <- compiler error
let mut v = Vec::with_capacity_in(10, &allocator);
v.extend([1, 2, 3]);

let b = v.into_boxed_slice();
// Check return value is an `oxc_allocator::Box`, not an `allocator_api2::boxed::Box`
let b: Box<[u8]> = b;

assert_eq!(&*b, &[1, 2, 3]);
// Check length of slice is equal to what `v.len()` was, not `v.capacity()`
assert_eq!(b.len(), 3);
}
}

0 comments on commit 0a7b0b6

Please sign in to comment.