Add more tests for alt expressions

This commit is contained in:
Brian Anderson 2011-04-02 19:32:34 -04:00
parent 99901bdbc4
commit 1326d424c9
3 changed files with 112 additions and 3 deletions

View File

@ -0,0 +1,27 @@
// xfail-boot
// -*- rust -*-
// Tests for alt as expressions resulting in boxed types
fn test_box() {
auto res = alt (true) {
case (true) {
@100
}
};
check (*res == 100);
}
fn test_str() {
auto res = alt (true) {
case (true) {
"happy"
}
};
check (res == "happy");
}
fn main() {
test_box();
test_str();
}

View File

@ -0,0 +1,35 @@
// xfail-boot
// -*- rust -*-
// Tests for alt as expressions resulting in structural types
fn test_rec() {
auto res = alt (true) {
case (true) {
rec(i = 100)
}
};
check (res == rec(i = 100));
}
fn test_tag() {
tag mood {
happy;
sad;
}
auto res = alt (true) {
case (true) {
happy
}
case (false) {
sad
}
};
check (res == happy);
}
fn main() {
test_rec();
test_tag();
}

View File

@ -3,7 +3,7 @@
// Tests for using alt as an expression
fn test() {
fn test_basic() {
let bool res = alt (true) {
case (true) {
true
@ -25,6 +25,53 @@ fn test() {
check (res);
}
fn main() {
test();
fn test_inferrence() {
auto res = alt (true) {
case (true) {
true
}
case (false) {
false
}
};
check (res);
}
fn test_alt_as_alt_head() {
// Yeah, this is kind of confusing ...
auto res = alt(alt (false) { case (true) { true } case (false) {false} }) {
case (true) {
false
}
case (false) {
true
}
};
check (res);
}
fn test_alt_as_block_result() {
auto res = alt (false) {
case (true) {
false
}
case (false) {
alt (true) {
case (true) {
true
}
case (false) {
false
}
}
}
};
check (res);
}
fn main() {
test_basic();
test_inferrence();
test_alt_as_alt_head();
test_alt_as_block_result();
}