]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/expr-fn.rs
auto merge of #19514 : jbranchaud/rust/add-btree-set-bitor, r=Gankro
[rust.git] / src / test / run-pass / expr-fn.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 fn test_int() {
13     fn f() -> int { 10 }
14     assert_eq!(f(), 10);
15 }
16
17 fn test_vec() {
18     fn f() -> Vec<int> { vec!(10, 11) }
19     let vect = f();
20     assert_eq!(vect[1], 11);
21 }
22
23 fn test_generic() {
24     fn f<T>(t: T) -> T { t }
25     assert_eq!(f(10i), 10);
26 }
27
28 fn test_alt() {
29     fn f() -> int { match true { false => { 10 } true => { 20 } } }
30     assert_eq!(f(), 20);
31 }
32
33 fn test_if() {
34     fn f() -> int { if true { 10 } else { 20 } }
35     assert_eq!(f(), 10);
36 }
37
38 fn test_block() {
39     fn f() -> int { { 10 } }
40     assert_eq!(f(), 10);
41 }
42
43 fn test_ret() {
44     fn f() -> int {
45         return 10 // no semi
46
47     }
48     assert_eq!(f(), 10);
49 }
50
51
52 // From issue #372
53 fn test_372() {
54     fn f() -> int { let x = { 3 }; x }
55     assert_eq!(f(), 3);
56 }
57
58 fn test_nil() { () }
59
60 pub fn main() {
61     test_int();
62     test_vec();
63     test_generic();
64     test_alt();
65     test_if();
66     test_block();
67     test_ret();
68     test_372();
69     test_nil();
70 }