mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
coalesce some trivial Box tests into basic-operations.rs
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
//! A collection of very old tests of basic `Box` functionality.
|
||||
//@ run-pass
|
||||
|
||||
fn deref_mut() {
|
||||
let mut i: Box<_> = Box::new(0);
|
||||
*i = 1;
|
||||
assert_eq!(*i, 1);
|
||||
}
|
||||
|
||||
// Tests for if as expressions returning boxed types
|
||||
fn box_if() {
|
||||
let rs: Box<_> = if true { Box::new(100) } else { Box::new(101) };
|
||||
assert_eq!(*rs, 100);
|
||||
}
|
||||
|
||||
fn cmp() {
|
||||
let i: Box<_> = Box::new(100);
|
||||
assert_eq!(i, Box::new(100));
|
||||
assert!(i < Box::new(101));
|
||||
assert!(i <= Box::new(100));
|
||||
assert!(i > Box::new(99));
|
||||
assert!(i >= Box::new(99));
|
||||
}
|
||||
|
||||
fn autoderef_field() {
|
||||
struct J {
|
||||
j: isize,
|
||||
}
|
||||
|
||||
let i: Box<_> = Box::new(J { j: 100 });
|
||||
assert_eq!(i.j, 100);
|
||||
}
|
||||
|
||||
fn assign_copy() {
|
||||
let mut i: Box<_> = Box::new(1);
|
||||
// Should be a copy
|
||||
let mut j;
|
||||
j = i.clone();
|
||||
*i = 2;
|
||||
*j = 3;
|
||||
assert_eq!(*i, 2);
|
||||
assert_eq!(*j, 3);
|
||||
}
|
||||
|
||||
fn arg_mut() {
|
||||
fn f(i: &mut Box<isize>) {
|
||||
*i = Box::new(200);
|
||||
}
|
||||
let mut i = Box::new(100);
|
||||
f(&mut i);
|
||||
assert_eq!(*i, 200);
|
||||
}
|
||||
|
||||
fn assign_generic() {
|
||||
fn f<T>(t: T) -> T {
|
||||
let t1 = t;
|
||||
t1
|
||||
}
|
||||
|
||||
let t = f::<Box<_>>(Box::new(100));
|
||||
assert_eq!(t, Box::new(100));
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
deref_mut();
|
||||
box_if();
|
||||
cmp();
|
||||
autoderef_field();
|
||||
assign_copy();
|
||||
arg_mut();
|
||||
assign_generic();
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
// Tests for if as expressions returning boxed types
|
||||
fn test_box() {
|
||||
let rs: Box<_> = if true { Box::new(100) } else { Box::new(101) };
|
||||
assert_eq!(*rs, 100);
|
||||
}
|
||||
|
||||
pub fn main() { test_box(); }
|
||||
@@ -1,12 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
pub fn main() {
|
||||
let mut i: Box<_> = Box::new(1);
|
||||
// Should be a copy
|
||||
let mut j;
|
||||
j = i.clone();
|
||||
*i = 2;
|
||||
*j = 3;
|
||||
assert_eq!(*i, 2);
|
||||
assert_eq!(*j, 3);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
//@ run-pass
|
||||
#![allow(unused_assignments)]
|
||||
|
||||
pub fn main() {
|
||||
let i: Box<_> = Box::new(1);
|
||||
let mut j: Box<_> = Box::new(2);
|
||||
// Should drop the previous value of j
|
||||
j = i;
|
||||
assert_eq!(*j, 1);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
fn f<T>(t: T) -> T {
|
||||
let t1 = t;
|
||||
t1
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let t = f::<Box<_>>(Box::new(100));
|
||||
assert_eq!(t, Box::new(100));
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
struct J { j: isize }
|
||||
|
||||
pub fn main() {
|
||||
let i: Box<_> = Box::new(J {
|
||||
j: 100
|
||||
});
|
||||
assert_eq!(i.j, 100);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
//@ run-pass
|
||||
#![allow(unused_allocation)]
|
||||
|
||||
pub fn main() {
|
||||
let i: Box<_> = Box::new(100);
|
||||
assert_eq!(i, Box::new(100));
|
||||
assert!(i < Box::new(101));
|
||||
assert!(i <= Box::new(100));
|
||||
assert!(i > Box::new(99));
|
||||
assert!(i >= Box::new(99));
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
pub fn main() {
|
||||
let mut i: Box<_> = Box::new(1);
|
||||
// Should be a copy
|
||||
let mut j = i.clone();
|
||||
*i = 2;
|
||||
*j = 3;
|
||||
assert_eq!(*i, 2);
|
||||
assert_eq!(*j, 3);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
fn f(i: &mut Box<isize>) {
|
||||
*i = Box::new(200);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let mut i = Box::new(100);
|
||||
f(&mut i);
|
||||
assert_eq!(*i, 200);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
#![allow(unused_variables)]
|
||||
|
||||
pub fn main() {
|
||||
let i: Box<_> = Box::new(100);
|
||||
let j: Box<_> = Box::new(200);
|
||||
let j = i;
|
||||
assert_eq!(*j, 100);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
//@ run-pass
|
||||
|
||||
pub fn main() {
|
||||
let mut i: Box<_> = Box::new(0);
|
||||
*i = 1;
|
||||
assert_eq!(*i, 1);
|
||||
}
|
||||
Reference in New Issue
Block a user