Skip to content

Commit 224d03d

Browse files
committed
organize std tests a bit better
1 parent a94e197 commit 224d03d

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

tests/run-pass/rc.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
1-
use std::cell::RefCell;
1+
use std::cell::{Cell, RefCell};
22
use std::rc::Rc;
3+
use std::sync::Arc;
34

45
fn rc_refcell() {
56
let r = Rc::new(RefCell::new(42));
7+
let r2 = r.clone();
68
*r.borrow_mut() += 10;
7-
let x = *r.borrow();
9+
let x = *r2.borrow();
810
assert_eq!(x, 52);
911
}
1012

13+
fn rc_cell() {
14+
let r = Rc::new(Cell::new(42));
15+
let r2 = r.clone();
16+
let x = r.get();
17+
r2.set(x + x);
18+
assert_eq!(r.get(), 84);
19+
}
20+
21+
fn rc_refcell2() {
22+
let r = Rc::new(RefCell::new(42));
23+
let r2 = r.clone();
24+
*r.borrow_mut() += 10;
25+
let x = r2.borrow();
26+
let r3 = r.clone();
27+
let y = r3.borrow();
28+
assert_eq!((*x + *y)/2, 52);
29+
}
30+
1131
fn rc_raw() {
1232
let r = Rc::new(0);
1333
let r2 = Rc::into_raw(r.clone());
@@ -17,6 +37,14 @@ fn rc_raw() {
1737
assert!(Rc::try_unwrap(r2).is_ok());
1838
}
1939

40+
fn arc() {
41+
fn test() -> Arc<i32> {
42+
let a = Arc::new(42);
43+
a
44+
}
45+
assert_eq!(*test(), 42);
46+
}
47+
2048
// Make sure this Rc doesn't fall apart when touched
2149
fn check_unique_rc<T: ?Sized>(mut r: Rc<T>) {
2250
let r2 = r.clone();
@@ -34,6 +62,9 @@ fn rc_from() {
3462

3563
fn main() {
3664
rc_refcell();
65+
rc_refcell2();
66+
rc_cell();
3767
rc_raw();
3868
rc_from();
69+
arc();
3970
}

tests/run-pass/refcell.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::cell::RefCell;
22

3-
fn main() {
3+
fn lots_of_funny_borrows() {
44
let c = RefCell::new(42);
55
{
66
let s1 = c.borrow();
@@ -31,3 +31,7 @@ fn main() {
3131
let _y: i32 = *s2;
3232
}
3333
}
34+
35+
fn main() {
36+
lots_of_funny_borrows();
37+
}

tests/run-pass/std.rs

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)