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() {
|
2012-06-29 18:26:56 -05:00
|
|
|
fn f() -> ~[int] { ~[10, 11] }
|
2011-08-19 17:16:48 -05:00
|
|
|
assert (f()[1] == 11);
|
2011-05-31 14:24:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_generic() {
|
2012-09-07 16:52:28 -05:00
|
|
|
fn f<T: Copy>(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() {
|
2012-08-06 14:34:08 -05:00
|
|
|
fn f() -> int { match 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 {
|
2012-08-01 19:30:05 -05:00
|
|
|
return 10 // no semi
|
2011-06-15 13:19:50 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
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();
|
2011-08-10 11:27:22 -05:00
|
|
|
}
|