|
1 | | -// FIXME #7306 |
2 | | -// xfail-fast |
| 1 | +// Copyright 2013 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. |
3 | 10 |
|
4 | | -use std::io; |
5 | | - |
6 | | -fn f1(ref_string: &str) { |
| 11 | +fn f1(ref_string: &str) -> ~str { |
7 | 12 | match ref_string { |
8 | | - "a" => io::println("found a"), |
9 | | - "b" => io::println("found b"), |
10 | | - _ => io::println("not found") |
| 13 | + "a" => ~"found a", |
| 14 | + "b" => ~"found b", |
| 15 | + _ => ~"not found" |
11 | 16 | } |
12 | 17 | } |
13 | 18 |
|
14 | | -fn f2(ref_string: &str) { |
| 19 | +fn f2(ref_string: &str) -> ~str { |
15 | 20 | match ref_string { |
16 | | - "a" => io::println("found a"), |
17 | | - "b" => io::println("found b"), |
18 | | - s => io::println(fmt!("not found (%s)", s)) |
| 21 | + "a" => ~"found a", |
| 22 | + "b" => ~"found b", |
| 23 | + s => fmt!("not found (%s)", s) |
19 | 24 | } |
20 | 25 | } |
21 | 26 |
|
22 | | -fn g1(ref_1: &str, ref_2: &str) { |
| 27 | +fn g1(ref_1: &str, ref_2: &str) -> ~str { |
23 | 28 | match (ref_1, ref_2) { |
24 | | - ("a", "b") => io::println("found a,b"), |
25 | | - ("b", "c") => io::println("found b,c"), |
26 | | - _ => io::println("not found") |
| 29 | + ("a", "b") => ~"found a,b", |
| 30 | + ("b", "c") => ~"found b,c", |
| 31 | + _ => ~"not found" |
27 | 32 | } |
28 | 33 | } |
29 | 34 |
|
30 | | -fn g2(ref_1: &str, ref_2: &str) { |
| 35 | +fn g2(ref_1: &str, ref_2: &str) -> ~str { |
31 | 36 | match (ref_1, ref_2) { |
32 | | - ("a", "b") => io::println("found a,b"), |
33 | | - ("b", "c") => io::println("found b,c"), |
34 | | - (s1, s2) => io::println(fmt!("not found (%s, %s)", s1, s2)) |
| 37 | + ("a", "b") => ~"found a,b", |
| 38 | + ("b", "c") => ~"found b,c", |
| 39 | + (s1, s2) => fmt!("not found (%s, %s)", s1, s2) |
35 | 40 | } |
36 | 41 | } |
37 | 42 |
|
38 | 43 | pub fn main() { |
39 | | - f1(@"a"); |
40 | | - f1(~"b"); |
41 | | - f1(&"c"); |
42 | | - f1("d"); |
43 | | - f2(@"a"); |
44 | | - f2(~"b"); |
45 | | - f2(&"c"); |
46 | | - f2("d"); |
47 | | - g1(@"a", @"b"); |
48 | | - g1(~"b", ~"c"); |
49 | | - g1(&"c", &"d"); |
50 | | - g1("d", "e"); |
51 | | - g2(@"a", @"b"); |
52 | | - g2(~"b", ~"c"); |
53 | | - g2(&"c", &"d"); |
54 | | - g2("d", "e"); |
| 44 | + assert_eq!(f1(@"a"), ~"found a"); |
| 45 | + assert_eq!(f1(~"b"), ~"found b"); |
| 46 | + assert_eq!(f1(&"c"), ~"not found"); |
| 47 | + assert_eq!(f1("d"), ~"not found"); |
| 48 | + assert_eq!(f2(@"a"), ~"found a"); |
| 49 | + assert_eq!(f2(~"b"), ~"found b"); |
| 50 | + assert_eq!(f2(&"c"), ~"not found (c)"); |
| 51 | + assert_eq!(f2("d"), ~"not found (d)"); |
| 52 | + assert_eq!(g1(@"a", @"b"), ~"found a,b"); |
| 53 | + assert_eq!(g1(~"b", ~"c"), ~"found b,c"); |
| 54 | + assert_eq!(g1(&"c", &"d"), ~"not found"); |
| 55 | + assert_eq!(g1("d", "e"), ~"not found"); |
| 56 | + assert_eq!(g2(@"a", @"b"), ~"found a,b"); |
| 57 | + assert_eq!(g2(~"b", ~"c"), ~"found b,c"); |
| 58 | + assert_eq!(g2(&"c", &"d"), ~"not found (c, d)"); |
| 59 | + assert_eq!(g2("d", "e"), ~"not found (d, e)"); |
55 | 60 | } |
| 61 | + |
0 commit comments