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