Skip to content

Commit

Permalink
Rollup merge of rust-lang#76273 - CraftSpider:master, r=matklad
Browse files Browse the repository at this point in the history
Move some Vec UI tests into alloc unit tests

A bit of work towards rust-lang#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.
  • Loading branch information
matklad committed Sep 4, 2020
2 parents 7ab6e80 + 2278c72 commit b4e784b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 69 deletions.
56 changes: 56 additions & 0 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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];
Expand All @@ -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];
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.

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

This file was deleted.

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

This file was deleted.

0 comments on commit b4e784b

Please sign in to comment.