]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/trait-default-method-xc.rs
Imported Upstream version 1.0.0~0alpha
[rustc.git] / src / test / run-pass / trait-default-method-xc.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 // aux-build:trait_default_method_xc_aux.rs
12
13 extern crate "trait_default_method_xc_aux" as aux;
14 use aux::{A, TestEquality, Something};
15 use aux::B;
16
17 fn f<T: aux::A>(i: T) {
18 assert_eq!(i.g(), 10);
19 }
20
21 fn welp<T>(i: int, _x: &T) -> int {
22 i.g()
23 }
24
25 mod stuff {
26 pub struct thing { pub x: int }
27 }
28
29 impl A for stuff::thing {
30 fn f(&self) -> int { 10 }
31 }
32
33 fn g<T, U, V: B<T>>(i: V, j: T, k: U) -> (T, U) {
34 i.thing(j, k)
35 }
36
37 fn eq<T: TestEquality>(lhs: &T, rhs: &T) -> bool {
38 lhs.test_eq(rhs)
39 }
40 fn neq<T: TestEquality>(lhs: &T, rhs: &T) -> bool {
41 lhs.test_neq(rhs)
42 }
43
44
45 impl TestEquality for stuff::thing {
46 fn test_eq(&self, rhs: &stuff::thing) -> bool {
47 //self.x.test_eq(&rhs.x)
48 eq(&self.x, &rhs.x)
49 }
50 }
51
52
53 pub fn main() {
54 // Some tests of random things
55 f(0i);
56
57 assert_eq!(A::lurr(&0i, &1i), 21);
58
59 let a = stuff::thing { x: 0 };
60 let b = stuff::thing { x: 1 };
61 let c = Something { x: 1 };
62
63 assert_eq!(0i.g(), 10);
64 assert_eq!(a.g(), 10);
65 assert_eq!(a.h(), 11);
66 assert_eq!(c.h(), 11);
67
68 assert_eq!(0i.thing(3.14f64, 1i), (3.14f64, 1i));
69 assert_eq!(B::staticthing(&0i, 3.14f64, 1i), (3.14f64, 1i));
70 assert_eq!(B::<f64>::staticthing::<int>(&0i, 3.14, 1), (3.14, 1));
71
72 assert_eq!(g(0i, 3.14f64, 1i), (3.14f64, 1i));
73 assert_eq!(g(false, 3.14f64, 1i), (3.14, 1));
74
75
76 // Trying out a real one
77 assert!(12i.test_neq(&10i));
78 assert!(!10i.test_neq(&10i));
79 assert!(a.test_neq(&b));
80 assert!(!a.test_neq(&a));
81
82 assert!(neq(&12i, &10i));
83 assert!(!neq(&10i, &10i));
84 assert!(neq(&a, &b));
85 assert!(!neq(&a, &a));
86 }