2011-05-31 19:24:18 +00:00
|
|
|
fn test_int() {
|
2011-06-15 18:19:50 +00:00
|
|
|
fn f() -> int { 10 }
|
|
|
|
assert (f() == 10);
|
2011-05-31 19:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_vec() {
|
2011-08-12 22:42:39 +00:00
|
|
|
fn f() -> [int] { ~[10, 11] }
|
2011-06-15 18:19:50 +00:00
|
|
|
assert (f().(1) == 11);
|
2011-05-31 19:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_generic() {
|
2011-08-12 13:37:25 +00:00
|
|
|
fn f<T>(t: &T) -> T { t }
|
2011-06-15 18:19:50 +00:00
|
|
|
assert (f(10) == 10);
|
2011-05-31 19:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_alt() {
|
2011-07-27 12:19:39 +00:00
|
|
|
fn f() -> int { alt true { false { 10 } true { 20 } } }
|
2011-06-15 18:19:50 +00:00
|
|
|
assert (f() == 20);
|
2011-05-31 19:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_if() {
|
2011-07-27 12:19:39 +00:00
|
|
|
fn f() -> int { if true { 10 } else { 20 } }
|
2011-06-15 18:19:50 +00:00
|
|
|
assert (f() == 10);
|
2011-05-31 19:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_block() {
|
2011-06-15 18:19:50 +00:00
|
|
|
fn f() -> int { { 10 } }
|
|
|
|
assert (f() == 10);
|
2011-05-31 19:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_ret() {
|
2011-06-15 18:19:50 +00:00
|
|
|
fn f() -> int {
|
|
|
|
ret 10 // no semi
|
|
|
|
|
|
|
|
}
|
|
|
|
assert (f() == 10);
|
2011-05-31 19:24:18 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 18:19:50 +00:00
|
|
|
|
2011-05-31 19:24:18 +00:00
|
|
|
// From issue #372
|
|
|
|
fn test_372() {
|
2011-07-27 12:19:39 +00:00
|
|
|
fn f() -> int { let x = { 3 }; x }
|
2011-06-15 18:19:50 +00:00
|
|
|
assert (f() == 3);
|
2011-05-31 19:24:18 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 18:19:50 +00:00
|
|
|
fn test_nil() { () }
|
2011-05-31 19:24:18 +00:00
|
|
|
|
|
|
|
fn main() {
|
2011-06-15 18:19:50 +00:00
|
|
|
test_int();
|
|
|
|
test_vec();
|
|
|
|
test_generic();
|
|
|
|
test_alt();
|
|
|
|
test_if();
|
|
|
|
test_block();
|
|
|
|
test_ret();
|
|
|
|
test_372();
|
|
|
|
test_nil();
|
2011-08-10 16:27:22 +00:00
|
|
|
}
|