Move cell exterior test into library unit tests
This commit is contained in:
parent
4eff9b0b29
commit
8aae1eee94
@ -303,6 +303,30 @@ fn cell_into_inner() {
|
||||
assert_eq!("Hello world".to_owned(), cell.into_inner());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cell_exterior() {
|
||||
#[derive(Copy, Clone)]
|
||||
#[allow(dead_code)]
|
||||
struct Point {
|
||||
x: isize,
|
||||
y: isize,
|
||||
z: isize,
|
||||
}
|
||||
|
||||
fn f(p: &Cell<Point>) {
|
||||
assert_eq!(p.get().z, 12);
|
||||
p.set(Point { x: 10, y: 11, z: 13 });
|
||||
assert_eq!(p.get().z, 13);
|
||||
}
|
||||
|
||||
let a = Point { x: 10, y: 11, z: 12 };
|
||||
let b = &Cell::new(a);
|
||||
assert_eq!(b.get().z, 12);
|
||||
f(b);
|
||||
assert_eq!(a.z, 12);
|
||||
assert_eq!(b.get().z, 13);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refcell_default() {
|
||||
let cell: RefCell<u64> = Default::default();
|
||||
|
@ -1,24 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Point {x: isize, y: isize, z: isize}
|
||||
|
||||
fn f(p: &Cell<Point>) {
|
||||
assert_eq!(p.get().z, 12);
|
||||
p.set(Point {x: 10, y: 11, z: 13});
|
||||
assert_eq!(p.get().z, 13);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let a: Point = Point {x: 10, y: 11, z: 12};
|
||||
let b: &Cell<Point> = &Cell::new(a);
|
||||
assert_eq!(b.get().z, 12);
|
||||
f(b);
|
||||
assert_eq!(a.z, 12);
|
||||
assert_eq!(b.get().z, 13);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user