Skip to content

Commit 1326d42

Browse files
committed
Add more tests for alt expressions
1 parent 99901bd commit 1326d42

File tree

3 files changed

+111
-2
lines changed

3 files changed

+111
-2
lines changed

src/test/run-pass/expr-alt-box.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// xfail-boot
2+
// -*- rust -*-
3+
4+
// Tests for alt as expressions resulting in boxed types
5+
6+
fn test_box() {
7+
auto res = alt (true) {
8+
case (true) {
9+
@100
10+
}
11+
};
12+
check (*res == 100);
13+
}
14+
15+
fn test_str() {
16+
auto res = alt (true) {
17+
case (true) {
18+
"happy"
19+
}
20+
};
21+
check (res == "happy");
22+
}
23+
24+
fn main() {
25+
test_box();
26+
test_str();
27+
}

src/test/run-pass/expr-alt-struct.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// xfail-boot
2+
// -*- rust -*-
3+
4+
// Tests for alt as expressions resulting in structural types
5+
6+
fn test_rec() {
7+
auto res = alt (true) {
8+
case (true) {
9+
rec(i = 100)
10+
}
11+
};
12+
check (res == rec(i = 100));
13+
}
14+
15+
fn test_tag() {
16+
tag mood {
17+
happy;
18+
sad;
19+
}
20+
21+
auto res = alt (true) {
22+
case (true) {
23+
happy
24+
}
25+
case (false) {
26+
sad
27+
}
28+
};
29+
check (res == happy);
30+
}
31+
32+
fn main() {
33+
test_rec();
34+
test_tag();
35+
}

src/test/run-pass/expr-alt.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// Tests for using alt as an expression
55

6-
fn test() {
6+
fn test_basic() {
77
let bool res = alt (true) {
88
case (true) {
99
true
@@ -25,6 +25,53 @@ fn test() {
2525
check (res);
2626
}
2727

28+
fn test_inferrence() {
29+
auto res = alt (true) {
30+
case (true) {
31+
true
32+
}
33+
case (false) {
34+
false
35+
}
36+
};
37+
check (res);
38+
}
39+
40+
fn test_alt_as_alt_head() {
41+
// Yeah, this is kind of confusing ...
42+
auto res = alt(alt (false) { case (true) { true } case (false) {false} }) {
43+
case (true) {
44+
false
45+
}
46+
case (false) {
47+
true
48+
}
49+
};
50+
check (res);
51+
}
52+
53+
fn test_alt_as_block_result() {
54+
auto res = alt (false) {
55+
case (true) {
56+
false
57+
}
58+
case (false) {
59+
alt (true) {
60+
case (true) {
61+
true
62+
}
63+
case (false) {
64+
false
65+
}
66+
}
67+
}
68+
};
69+
check (res);
70+
}
71+
2872
fn main() {
29-
test();
73+
test_basic();
74+
test_inferrence();
75+
test_alt_as_alt_head();
76+
test_alt_as_block_result();
3077
}

0 commit comments

Comments
 (0)