2019-07-27 00:54:25 +03:00
|
|
|
// run-pass
|
2020-03-27 21:56:19 +01:00
|
|
|
#![allow(unused_braces)]
|
2019-07-27 00:54:25 +03:00
|
|
|
|
2011-05-31 15:24:18 -04:00
|
|
|
fn test_int() {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn f() -> isize { 10 }
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(f(), 10);
|
2011-05-31 15:24:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_vec() {
|
2016-10-29 22:54:04 +01:00
|
|
|
fn f() -> Vec<isize> { vec![10, 11] }
|
2014-03-05 15:28:08 -08:00
|
|
|
let vect = f();
|
2014-10-14 23:05:01 -07:00
|
|
|
assert_eq!(vect[1], 11);
|
2011-05-31 15:24:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_generic() {
|
2013-07-10 14:43:25 -07:00
|
|
|
fn f<T>(t: T) -> T { t }
|
2015-01-25 22:05:03 +01:00
|
|
|
assert_eq!(f(10), 10);
|
2011-05-31 15:24:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_alt() {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn f() -> isize { match true { false => { 10 } true => { 20 } } }
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(f(), 20);
|
2011-05-31 15:24:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_if() {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn f() -> isize { if true { 10 } else { 20 } }
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(f(), 10);
|
2011-05-31 15:24:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_block() {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn f() -> isize { { 10 } }
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(f(), 10);
|
2011-05-31 15:24:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_ret() {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn f() -> isize {
|
2012-08-01 17:30:05 -07:00
|
|
|
return 10 // no semi
|
2011-06-15 11:19:50 -07:00
|
|
|
|
|
|
|
}
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(f(), 10);
|
2011-05-31 15:24:18 -04:00
|
|
|
}
|
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-05-31 15:24:18 -04:00
|
|
|
// From issue #372
|
|
|
|
fn test_372() {
|
2015-03-25 17:06:52 -07:00
|
|
|
fn f() -> isize { let x = { 3 }; x }
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(f(), 3);
|
2011-05-31 15:24:18 -04:00
|
|
|
}
|
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
fn test_nil() { () }
|
2011-05-31 15:24:18 -04:00
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2011-06-15 11:19:50 -07:00
|
|
|
test_int();
|
|
|
|
test_vec();
|
|
|
|
test_generic();
|
|
|
|
test_alt();
|
|
|
|
test_if();
|
|
|
|
test_block();
|
|
|
|
test_ret();
|
|
|
|
test_372();
|
|
|
|
test_nil();
|
2011-08-10 09:27:22 -07:00
|
|
|
}
|