]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/issue-13323.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / issue-13323.rs
1 // Copyright 2014 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 // pretty-expanded FIXME #23616
12
13 #![allow(unknown_features)]
14 #![feature(box_syntax)]
15
16 struct StrWrap {
17 s: String
18 }
19
20 impl StrWrap {
21 fn new(s: &str) -> StrWrap {
22 StrWrap { s: s.to_string() }
23 }
24
25 fn get_s<'a>(&'a self) -> &'a str {
26 &self.s
27 }
28 }
29
30 struct MyStruct {
31 s: StrWrap
32 }
33
34 impl MyStruct {
35 fn new(s: &str) -> MyStruct {
36 MyStruct { s: StrWrap::new(s) }
37 }
38
39 fn get_str_wrap<'a>(&'a self) -> &'a StrWrap {
40 &self.s
41 }
42 }
43
44 trait Matcher<T> {
45 fn matches(&self, actual: T) -> bool;
46 }
47
48 fn assert_that<T, U: Matcher<T>>(actual: T, matcher: &U) {
49 assert!(matcher.matches(actual));
50 }
51
52 struct EqualTo<T> {
53 expected: T
54 }
55
56 impl<T: Eq> Matcher<T> for EqualTo<T> {
57 fn matches(&self, actual: T) -> bool {
58 self.expected.eq(&actual)
59 }
60 }
61
62 fn equal_to<T: Eq>(expected: T) -> Box<EqualTo<T>> {
63 box EqualTo { expected: expected }
64 }
65
66 pub fn main() {
67 let my_struct = MyStruct::new("zomg");
68 let s = my_struct.get_str_wrap();
69
70 assert_that(s.get_s(), &*equal_to("zomg"));
71 }