Skip to content

Commit

Permalink
Add tests for new _mut variants
Browse files Browse the repository at this point in the history
  • Loading branch information
aturon committed Sep 26, 2014
1 parent af3cfcc commit c59ef66
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/libcollections/dlist.rs
Expand Up @@ -844,6 +844,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn test_append() {
{
let mut m = DList::new();
Expand Down
84 changes: 80 additions & 4 deletions src/libcollections/slice.rs
Expand Up @@ -850,6 +850,16 @@ mod tests {
assert_eq!(a.as_slice().head().unwrap(), &11);
}

#[test]
fn test_head_mut() {
let mut a = vec![];
assert_eq!(a.as_mut_slice().head_mut(), None);
a = vec![11i];
assert_eq!(*a.as_mut_slice().head_mut().unwrap(), 11);
a = vec![11i, 12];
assert_eq!(*a.as_mut_slice().head_mut().unwrap(), 11);
}

#[test]
fn test_tail() {
let mut a = vec![11i];
Expand All @@ -860,22 +870,39 @@ mod tests {
assert_eq!(a.tail(), b);
}

#[test]
fn test_tail_mut() {
let mut a = vec![11i];
let b: &mut [int] = &mut [];
assert!(a.as_mut_slice().tail_mut() == b);
a = vec![11i, 12];
let b: &mut [int] = &mut [12];
assert!(a.as_mut_slice().tail_mut() == b);
}

#[test]
#[should_fail]
fn test_tail_empty() {
let a: Vec<int> = vec![];
a.tail();
}

#[test]
#[should_fail]
fn test_tail_mut_empty() {
let mut a: Vec<int> = vec![];
a.as_mut_slice().tail_mut();
}

#[test]
#[allow(deprecated)]
fn test_tailn() {
let mut a = vec![11i, 12, 13];
let b: &[int] = &[11, 12, 13];
assert_eq!(a.tailn(0), b);
let b: &mut [int] = &mut [11, 12, 13];
assert!(a.tailn(0) == b);
a = vec![11i, 12, 13];
let b: &[int] = &[13];
assert_eq!(a.tailn(2), b);
let b: &mut [int] = &mut [13];
assert!(a.tailn(2) == b);
}

#[test]
Expand All @@ -896,13 +923,30 @@ mod tests {
assert_eq!(a.init(), b);
}

#[test]
fn test_init_mut() {
let mut a = vec![11i];
let b: &mut [int] = &mut [];
assert!(a.as_mut_slice().init_mut() == b);
a = vec![11i, 12];
let b: &mut [int] = &mut [11];
assert!(a.as_mut_slice().init_mut() == b);
}

#[test]
#[should_fail]
fn test_init_empty() {
let a: Vec<int> = vec![];
a.init();
}

#[test]
#[should_fail]
fn test_init_mut_empty() {
let mut a: Vec<int> = vec![];
a.as_mut_slice().init_mut();
}

#[test]
#[allow(deprecated)]
fn test_initn() {
Expand Down Expand Up @@ -932,6 +976,16 @@ mod tests {
assert_eq!(a.as_slice().last().unwrap(), &12);
}

#[test]
fn test_last_mut() {
let mut a = vec![];
assert_eq!(a.as_mut_slice().last_mut(), None);
a = vec![11i];
assert_eq!(*a.as_mut_slice().last_mut().unwrap(), 11);
a = vec![11i, 12];
assert_eq!(*a.as_mut_slice().last_mut().unwrap(), 12);
}

#[test]
fn test_slice() {
// Test fixed length vector.
Expand Down Expand Up @@ -1077,6 +1131,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn test_grow_set() {
let mut v = vec![1i, 2, 3];
v.grow_set(4u, &4, 5);
Expand Down Expand Up @@ -1610,6 +1665,7 @@ mod tests {

#[test]
#[should_fail]
#[allow(deprecated)]
fn test_copy_memory_oob() {
unsafe {
let mut a = [1i, 2, 3, 4];
Expand Down Expand Up @@ -1793,6 +1849,26 @@ mod tests {
assert_eq!(xs.splitn(1, |x| *x == 5).collect::<Vec<&[int]>>().as_slice(), splits);
}

#[test]
fn test_splitnator_mut() {
let xs = &mut [1i,2,3,4,5];

let splits: &[&mut [int]] = &[&mut [1,2,3,4,5]];
assert_eq!(xs.splitn_mut(0, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>().as_slice(),
splits);
let splits: &[&mut [int]] = &[&mut [1], &mut [3,4,5]];
assert_eq!(xs.splitn_mut(1, |x| *x % 2 == 0).collect::<Vec<&mut [int]>>().as_slice(),
splits);
let splits: &[&mut [int]] = &[&mut [], &mut [], &mut [], &mut [4,5]];
assert_eq!(xs.splitn_mut(3, |_| true).collect::<Vec<&mut [int]>>().as_slice(),
splits);

let xs: &mut [int] = &mut [];
let splits: &[&mut [int]] = &[&mut []];
assert_eq!(xs.splitn_mut(1, |x| *x == 5).collect::<Vec<&mut [int]>>().as_slice(),
splits);
}

#[test]
fn test_rsplitator() {
let xs = &[1i,2,3,4,5];
Expand Down

5 comments on commit c59ef66

@bors
Copy link
Contributor

@bors bors commented on c59ef66 Sep 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at aturon@c59ef66

@bors
Copy link
Contributor

@bors bors commented on c59ef66 Sep 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging aturon/rust/stabilize-mutable-slices = c59ef66 into auto

@bors
Copy link
Contributor

@bors bors commented on c59ef66 Sep 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aturon/rust/stabilize-mutable-slices = c59ef66 merged ok, testing candidate = 5d653c1

@bors
Copy link
Contributor

@bors bors commented on c59ef66 Sep 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on c59ef66 Sep 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 5d653c1

Please sign in to comment.