Skip to content

Commit 86bbefa

Browse files
committed
Add more test cases
1 parent bedcf79 commit 86bbefa

File tree

8 files changed

+143
-0
lines changed

8 files changed

+143
-0
lines changed

tests/ui/fail/option_inc.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@error-in-other-file: Unsat
2+
//@compile-flags: -C debug-assertions=off
3+
4+
fn maybe_inc(x: i32, do_it: bool) -> Option<i32> {
5+
if do_it {
6+
Some(x + 1)
7+
} else {
8+
None
9+
}
10+
}
11+
12+
fn main() {
13+
let res = maybe_inc(10, true);
14+
if let Some(v) = res {
15+
assert!(v == 12);
16+
}
17+
}

tests/ui/fail/option_loop.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@error-in-other-file: Unsat
2+
//@compile-flags: -C debug-assertions=off
3+
4+
fn main() {
5+
let mut opt = Some(5);
6+
while let Some(x) = opt {
7+
if x > 0 {
8+
opt = Some(x - 1);
9+
} else {
10+
opt = None;
11+
}
12+
}
13+
assert!(false);
14+
}

tests/ui/fail/result_mut.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@error-in-other-file: Unsat
2+
//@compile-flags: -C debug-assertions=off
3+
4+
fn mutate_res(r: &mut Result<i32, i32>) {
5+
match r {
6+
Ok(v) => *v += 1,
7+
Err(e) => *e -= 1,
8+
}
9+
}
10+
11+
fn main() {
12+
let mut r = Ok(10);
13+
mutate_res(&mut r);
14+
match r {
15+
Ok(v) => assert!(v == 10),
16+
Err(_) => unreachable!(),
17+
}
18+
}

tests/ui/fail/result_struct.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@error-in-other-file: Unsat
2+
//@compile-flags: -C debug-assertions=off
3+
4+
struct Point {
5+
x: i32,
6+
y: i32,
7+
}
8+
9+
fn make_point(x: i32, y: i32) -> Result<Point, ()> {
10+
if x >= 0 && y >= 0 {
11+
Ok(Point { x, y })
12+
} else {
13+
Err(())
14+
}
15+
}
16+
17+
fn main() {
18+
let p = make_point(1, 2);
19+
if let Ok(pt) = p {
20+
assert!(pt.x > 1);
21+
}
22+
}

tests/ui/pass/option_inc.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@check-pass
2+
//@compile-flags: -C debug-assertions=off
3+
4+
fn maybe_inc(x: i32, do_it: bool) -> Option<i32> {
5+
if do_it {
6+
Some(x + 1)
7+
} else {
8+
None
9+
}
10+
}
11+
12+
fn main() {
13+
let res = maybe_inc(10, true);
14+
if let Some(v) = res {
15+
assert!(v == 11);
16+
}
17+
}

tests/ui/pass/option_loop.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@check-pass
2+
//@compile-flags: -C debug-assertions=off
3+
4+
fn main() {
5+
let mut opt = Some(5);
6+
while let Some(x) = opt {
7+
if x > 0 {
8+
opt = Some(x - 1);
9+
} else {
10+
opt = None;
11+
}
12+
}
13+
assert!(matches!(opt, None));
14+
}

tests/ui/pass/result_mut.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@check-pass
2+
//@compile-flags: -C debug-assertions=off
3+
4+
fn mutate_res(r: &mut Result<i32, i32>) {
5+
match r {
6+
Ok(v) => *v += 1,
7+
Err(e) => *e -= 1,
8+
}
9+
}
10+
11+
fn main() {
12+
let mut r = Ok(10);
13+
mutate_res(&mut r);
14+
match r {
15+
Ok(v) => assert!(v == 11),
16+
Err(_) => unreachable!(),
17+
}
18+
}

tests/ui/pass/result_struct.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@check-pass
2+
//@compile-flags: -C debug-assertions=off
3+
4+
struct Point {
5+
x: i32,
6+
y: i32,
7+
}
8+
9+
fn make_point(x: i32, y: i32) -> Result<Point, ()> {
10+
if x >= 0 && y >= 0 {
11+
Ok(Point { x, y })
12+
} else {
13+
Err(())
14+
}
15+
}
16+
17+
fn main() {
18+
let p = make_point(1, 2);
19+
if let Ok(pt) = p {
20+
assert!(pt.x >= 0);
21+
assert!(pt.y >= 0);
22+
}
23+
}

0 commit comments

Comments
 (0)