coalesce some trivial Box tests into basic-operations.rs

This commit is contained in:
cyrgani
2026-02-24 21:51:09 +00:00
parent 24ca3fcac2
commit 25ded1163f
11 changed files with 72 additions and 102 deletions
+72
View File
@@ -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();
}
-9
View File
@@ -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(); }
-12
View File
@@ -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);
}
-10
View File
@@ -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);
}
-11
View File
@@ -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);
}
-11
View File
@@ -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);
}
-10
View File
@@ -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);
}
-7
View File
@@ -1,7 +0,0 @@
//@ run-pass
pub fn main() {
let mut i: Box<_> = Box::new(0);
*i = 1;
assert_eq!(*i, 1);
}