]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/expr-fn.rs
25dae36bcb1546439949a170b4e9f8f031f757f4
[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 fn test_int() {
12     fn f() -> int { 10 }
13     assert_eq!(f(), 10);
14 }
15
16 fn test_vec() {
17     fn f() -> Vec<int> { vec!(10, 11) }
18     assert_eq!(f()[1], 11);
19 }
20
21 fn test_generic() {
22     fn f<T>(t: T) -> T { t }
23     assert_eq!(f(10), 10);
24 }
25
26 fn test_alt() {
27     fn f() -> int { match true { false => { 10 } true => { 20 } } }
28     assert_eq!(f(), 20);
29 }
30
31 fn test_if() {
32     fn f() -> int { if true { 10 } else { 20 } }
33     assert_eq!(f(), 10);
34 }
35
36 fn test_block() {
37     fn f() -> int { { 10 } }
38     assert_eq!(f(), 10);
39 }
40
41 fn test_ret() {
42     fn f() -> int {
43         return 10 // no semi
44
45     }
46     assert_eq!(f(), 10);
47 }
48
49
50 // From issue #372
51 fn test_372() {
52     fn f() -> int { let x = { 3 }; x }
53     assert_eq!(f(), 3);
54 }
55
56 fn test_nil() { () }
57
58 pub fn main() {
59     test_int();
60     test_vec();
61     test_generic();
62     test_alt();
63     test_if();
64     test_block();
65     test_ret();
66     test_372();
67     test_nil();
68 }