Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,4 +853,24 @@ mod tests {
assert_eq!(wma.in_use(), 64);
assert!(vec1.try_clone().is_err());
}

#[test]
fn test_set_len() {
let _no_global_alloc_guard = NoGlobalAllocGuard::new();
let wma = WatermarkAllocator::new(64);
let mut vec: Vec<i32, _> = Vec::with_capacity_in(4, wma).unwrap();

// Write values directly to the buffer
let ptr = vec.as_mut_ptr();
unsafe {
ptr.write(1);
ptr.add(1).write(2);
ptr.add(2).write(3);
// Now set the length to match initialized elements
vec.set_len(3);
}

assert_eq!(vec.len(), 3);
assert_eq!(vec.as_slice(), &[1, 2, 3]);
}
}
Loading