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