port over the old tests to the new `Rc`

This commit is contained in:
Daniel Micay 2014-01-09 15:56:38 -05:00
parent c5bcb22719
commit fc60ace7a9
3 changed files with 44 additions and 3 deletions

View File

@ -127,7 +127,7 @@ mod test {
} }
fn mk(v: uint) -> (~IdleWatcher, Chan) { fn mk(v: uint) -> (~IdleWatcher, Chan) {
let rc = Rc::from_send(RefCell::new((None, 0))); let rc = Rc::new(RefCell::new((None, 0)));
let cb = ~MyCallback(rc.clone(), v); let cb = ~MyCallback(rc.clone(), v);
let cb = cb as ~Callback:; let cb = cb as ~Callback:;
let cb = unsafe { cast::transmute(cb) }; let cb = unsafe { cast::transmute(cb) };

View File

@ -509,7 +509,7 @@ mod tests {
} }
} }
let i = Rc::from_send(RefCell::new(0)); let i = Rc::new(RefCell::new(0));
{ {
let x = R(i.clone()); let x = R(i.clone());
let opt = Some(x); let opt = Some(x);

View File

@ -172,8 +172,49 @@ impl<T> Clone for Weak<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use prelude::*;
use super::*; use super::*;
use prelude::drop; use cell::RefCell;
#[test]
fn test_clone() {
let x = Rc::new(RefCell::new(5));
let y = x.clone();
x.borrow().with_mut(|inner| {
*inner = 20;
});
assert_eq!(y.borrow().with(|v| *v), 20);
}
#[test]
fn test_deep_clone() {
let x = Rc::new(RefCell::new(5));
let y = x.deep_clone();
x.borrow().with_mut(|inner| {
*inner = 20;
});
assert_eq!(y.borrow().with(|v| *v), 5);
}
#[test]
fn test_simple() {
let x = Rc::new(5);
assert_eq!(*x.borrow(), 5);
}
#[test]
fn test_simple_clone() {
let x = Rc::new(5);
let y = x.clone();
assert_eq!(*x.borrow(), 5);
assert_eq!(*y.borrow(), 5);
}
#[test]
fn test_destructor() {
let x = Rc::new(~5);
assert_eq!(**x.borrow(), 5);
}
#[test] #[test]
fn test_live() { fn test_live() {