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