Skip to content

Commit 25ded11

Browse files
committed
coalesce some trivial Box tests into basic-operations.rs
1 parent 24ca3fc commit 25ded11

11 files changed

Lines changed: 72 additions & 102 deletions
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//! A collection of very old tests of basic `Box` functionality.
2+
//@ run-pass
3+
4+
fn deref_mut() {
5+
let mut i: Box<_> = Box::new(0);
6+
*i = 1;
7+
assert_eq!(*i, 1);
8+
}
9+
10+
// Tests for if as expressions returning boxed types
11+
fn box_if() {
12+
let rs: Box<_> = if true { Box::new(100) } else { Box::new(101) };
13+
assert_eq!(*rs, 100);
14+
}
15+
16+
fn cmp() {
17+
let i: Box<_> = Box::new(100);
18+
assert_eq!(i, Box::new(100));
19+
assert!(i < Box::new(101));
20+
assert!(i <= Box::new(100));
21+
assert!(i > Box::new(99));
22+
assert!(i >= Box::new(99));
23+
}
24+
25+
fn autoderef_field() {
26+
struct J {
27+
j: isize,
28+
}
29+
30+
let i: Box<_> = Box::new(J { j: 100 });
31+
assert_eq!(i.j, 100);
32+
}
33+
34+
fn assign_copy() {
35+
let mut i: Box<_> = Box::new(1);
36+
// Should be a copy
37+
let mut j;
38+
j = i.clone();
39+
*i = 2;
40+
*j = 3;
41+
assert_eq!(*i, 2);
42+
assert_eq!(*j, 3);
43+
}
44+
45+
fn arg_mut() {
46+
fn f(i: &mut Box<isize>) {
47+
*i = Box::new(200);
48+
}
49+
let mut i = Box::new(100);
50+
f(&mut i);
51+
assert_eq!(*i, 200);
52+
}
53+
54+
fn assign_generic() {
55+
fn f<T>(t: T) -> T {
56+
let t1 = t;
57+
t1
58+
}
59+
60+
let t = f::<Box<_>>(Box::new(100));
61+
assert_eq!(t, Box::new(100));
62+
}
63+
64+
pub fn main() {
65+
deref_mut();
66+
box_if();
67+
cmp();
68+
autoderef_field();
69+
assign_copy();
70+
arg_mut();
71+
assign_generic();
72+
}

tests/ui/box/unit/expr-if-unique.rs

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

tests/ui/box/unit/unique-assign-copy.rs

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

tests/ui/box/unit/unique-assign-drop.rs

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

tests/ui/box/unit/unique-assign-generic.rs

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

tests/ui/box/unit/unique-autoderef-field.rs

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

tests/ui/box/unit/unique-cmp.rs

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

tests/ui/box/unit/unique-decl-init-copy.rs

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

tests/ui/box/unit/unique-fn-arg-mut.rs

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

tests/ui/box/unit/unique-move-drop.rs

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

0 commit comments

Comments
 (0)