Rollup merge of #76273 - CraftSpider:master, r=matklad
Move some Vec UI tests into alloc unit tests A bit of work towards #76268, makes a number of the Vec UI tests that are simply running code into unit tests. Ensured that they are being run when testing liballoc locally.
This commit is contained in:
commit
e488c4f187
@ -74,6 +74,42 @@ fn test_zst_capacity() {
|
||||
assert_eq!(Vec::<()>::new().capacity(), usize::MAX);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_indexing() {
|
||||
let v: Vec<isize> = vec![10, 20];
|
||||
assert_eq!(v[0], 10);
|
||||
assert_eq!(v[1], 20);
|
||||
let mut x: usize = 0;
|
||||
assert_eq!(v[x], 10);
|
||||
assert_eq!(v[x + 1], 20);
|
||||
x = x + 1;
|
||||
assert_eq!(v[x], 20);
|
||||
assert_eq!(v[x - 1], 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_debug_fmt() {
|
||||
let vec1: Vec<isize> = vec![];
|
||||
assert_eq!("[]", format!("{:?}", vec1));
|
||||
|
||||
let vec2 = vec![0, 1];
|
||||
assert_eq!("[0, 1]", format!("{:?}", vec2));
|
||||
|
||||
let slice: &[isize] = &[4, 5];
|
||||
assert_eq!("[4, 5]", format!("{:?}", slice));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_push() {
|
||||
let mut v = vec![];
|
||||
v.push(1);
|
||||
assert_eq!(v, [1]);
|
||||
v.push(2);
|
||||
assert_eq!(v, [1, 2]);
|
||||
v.push(3);
|
||||
assert_eq!(v, [1, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extend() {
|
||||
let mut v = Vec::new();
|
||||
@ -119,6 +155,18 @@ fn test_extend() {
|
||||
assert_eq!(count_x, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extend_from_slice() {
|
||||
let a: Vec<isize> = vec![1, 2, 3, 4, 5];
|
||||
let b: Vec<isize> = vec![6, 7, 8, 9, 0];
|
||||
|
||||
let mut v: Vec<isize> = a;
|
||||
|
||||
v.extend_from_slice(&b);
|
||||
|
||||
assert_eq!(v, [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extend_ref() {
|
||||
let mut v = vec![1, 2];
|
||||
@ -134,6 +182,14 @@ fn test_extend_ref() {
|
||||
assert_eq!(v, [1, 2, 3, 4, 5, 6, 7]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_slice_from_ref() {
|
||||
let values = vec![1, 2, 3, 4, 5];
|
||||
let slice = &values[1..3];
|
||||
|
||||
assert_eq!(slice, [2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_slice_from_mut() {
|
||||
let mut values = vec![1, 2, 3, 4, 5];
|
||||
|
@ -1,14 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
use std::vec;
|
||||
|
||||
pub fn main() {
|
||||
let a: Vec<isize> = vec![1, 2, 3, 4, 5];
|
||||
let b: Vec<isize> = vec![6, 7, 8, 9, 0];
|
||||
let mut v: Vec<isize> = a;
|
||||
v.extend_from_slice(&b);
|
||||
println!("{}", v[9]);
|
||||
assert_eq!(v[0], 1);
|
||||
assert_eq!(v[7], 8);
|
||||
assert_eq!(v[9], 0);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
|
||||
|
||||
pub fn main() {
|
||||
let mut v = vec![1];
|
||||
v.push(2);
|
||||
v.push(3);
|
||||
v.push(4);
|
||||
v.push(5);
|
||||
assert_eq!(v[0], 1);
|
||||
assert_eq!(v[1], 2);
|
||||
assert_eq!(v[2], 3);
|
||||
assert_eq!(v[3], 4);
|
||||
assert_eq!(v[4], 5);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
pub fn main() { let mut v = vec![1, 2, 3]; v.push(1); }
|
@ -1,9 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
|
||||
pub fn main() {
|
||||
let v = vec![1,2,3,4,5];
|
||||
let v2 = &v[1..3];
|
||||
assert_eq!(v2[0], 2);
|
||||
assert_eq!(v2[1], 3);
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!(format!("{:?}", vec![0, 1]), "[0, 1]".to_string());
|
||||
|
||||
let foo = vec![3, 4];
|
||||
let bar: &[isize] = &[4, 5];
|
||||
|
||||
assert_eq!(format!("{:?}", foo), "[3, 4]");
|
||||
assert_eq!(format!("{:?}", bar), "[4, 5]");
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
|
||||
|
||||
pub fn main() {
|
||||
let v: Vec<isize> = vec![10, 20];
|
||||
assert_eq!(v[0], 10);
|
||||
assert_eq!(v[1], 20);
|
||||
let mut x: usize = 0;
|
||||
assert_eq!(v[x], 10);
|
||||
assert_eq!(v[x + 1], 20);
|
||||
x = x + 1;
|
||||
assert_eq!(v[x], 20);
|
||||
assert_eq!(v[x - 1], 10);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user