Skip to content

Commit fc60ace

Browse files
committed
port over the old tests to the new Rc
1 parent c5bcb22 commit fc60ace

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/librustuv/idle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ mod test {
127127
}
128128

129129
fn mk(v: uint) -> (~IdleWatcher, Chan) {
130-
let rc = Rc::from_send(RefCell::new((None, 0)));
130+
let rc = Rc::new(RefCell::new((None, 0)));
131131
let cb = ~MyCallback(rc.clone(), v);
132132
let cb = cb as ~Callback:;
133133
let cb = unsafe { cast::transmute(cb) };

src/libstd/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ mod tests {
509509
}
510510
}
511511

512-
let i = Rc::from_send(RefCell::new(0));
512+
let i = Rc::new(RefCell::new(0));
513513
{
514514
let x = R(i.clone());
515515
let opt = Some(x);

src/libstd/rc.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,49 @@ impl<T> Clone for Weak<T> {
172172

173173
#[cfg(test)]
174174
mod tests {
175+
use prelude::*;
175176
use super::*;
176-
use prelude::drop;
177+
use cell::RefCell;
178+
179+
#[test]
180+
fn test_clone() {
181+
let x = Rc::new(RefCell::new(5));
182+
let y = x.clone();
183+
x.borrow().with_mut(|inner| {
184+
*inner = 20;
185+
});
186+
assert_eq!(y.borrow().with(|v| *v), 20);
187+
}
188+
189+
#[test]
190+
fn test_deep_clone() {
191+
let x = Rc::new(RefCell::new(5));
192+
let y = x.deep_clone();
193+
x.borrow().with_mut(|inner| {
194+
*inner = 20;
195+
});
196+
assert_eq!(y.borrow().with(|v| *v), 5);
197+
}
198+
199+
#[test]
200+
fn test_simple() {
201+
let x = Rc::new(5);
202+
assert_eq!(*x.borrow(), 5);
203+
}
204+
205+
#[test]
206+
fn test_simple_clone() {
207+
let x = Rc::new(5);
208+
let y = x.clone();
209+
assert_eq!(*x.borrow(), 5);
210+
assert_eq!(*y.borrow(), 5);
211+
}
212+
213+
#[test]
214+
fn test_destructor() {
215+
let x = Rc::new(~5);
216+
assert_eq!(**x.borrow(), 5);
217+
}
177218

178219
#[test]
179220
fn test_live() {

0 commit comments

Comments
 (0)