2019-07-26 16:54:25 -05:00
|
|
|
// run-pass
|
|
|
|
|
2011-05-31 14:24:18 -05:00
|
|
|
fn test_int() {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn f() -> isize { 10 }
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(f(), 10);
|
2011-05-31 14:24:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_vec() {
|
2016-10-29 16:54:04 -05:00
|
|
|
fn f() -> Vec<isize> { vec![10, 11] }
|
2014-03-05 17:28:08 -06:00
|
|
|
let vect = f();
|
2014-10-15 01:05:01 -05:00
|
|
|
assert_eq!(vect[1], 11);
|
2011-05-31 14:24:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_generic() {
|
2013-07-10 16:43:25 -05:00
|
|
|
fn f<T>(t: T) -> T { t }
|
2015-01-25 15:05:03 -06:00
|
|
|
assert_eq!(f(10), 10);
|
2011-05-31 14:24:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_alt() {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn f() -> isize { match true { false => { 10 } true => { 20 } } }
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(f(), 20);
|
2011-05-31 14:24:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_if() {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn f() -> isize { if true { 10 } else { 20 } }
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(f(), 10);
|
2011-05-31 14:24:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_block() {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn f() -> isize { { 10 } }
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(f(), 10);
|
2011-05-31 14:24:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_ret() {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn f() -> isize {
|
2012-08-01 19:30:05 -05:00
|
|
|
return 10 // no semi
|
2011-06-15 13:19:50 -05:00
|
|
|
|
|
|
|
}
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(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() {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn f() -> isize { let x = { 3 }; x }
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(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
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub 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
|
|
|
}
|