Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move some Vec UI tests into alloc unit tests #76273

Merged
merged 2 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
53 changes: 53 additions & 0 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,39 @@ 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));
}

#[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();
Expand Down Expand Up @@ -117,6 +150,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];
Expand All @@ -132,6 +177,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];
Expand Down
14 changes: 0 additions & 14 deletions src/test/ui/array-slice-vec/vec-concat.rs

This file was deleted.

16 changes: 0 additions & 16 deletions src/test/ui/array-slice-vec/vec-growth.rs

This file was deleted.

3 changes: 0 additions & 3 deletions src/test/ui/array-slice-vec/vec-push.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/ui/array-slice-vec/vec-slice.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/ui/array-slice-vec/vec-to_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@


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]");
}
CraftSpider marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 0 additions & 15 deletions src/test/ui/array-slice-vec/vec.rs

This file was deleted.