]> git.lizzy.rs Git - rust.git/blob - src/test/ui/structs-enums/class-separate-impl.rs
Pin panic-in-drop=abort test to old pass manager
[rust.git] / src / test / ui / structs-enums / class-separate-impl.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(non_camel_case_types)]
4
5 #![feature(box_syntax)]
6
7 use std::fmt;
8
9 struct cat {
10     meows : usize,
11
12     how_hungry : isize,
13     name : String,
14 }
15
16 impl cat {
17     pub fn speak(&mut self) { self.meow(); }
18
19     pub fn eat(&mut self) -> bool {
20         if self.how_hungry > 0 {
21             println!("OM NOM NOM");
22             self.how_hungry -= 2;
23             return true;
24         }
25         else {
26             println!("Not hungry!");
27             return false;
28         }
29     }
30 }
31
32 impl cat {
33     fn meow(&mut self) {
34         println!("Meow");
35         self.meows += 1;
36         if self.meows % 5 == 0 {
37             self.how_hungry += 1;
38         }
39     }
40 }
41
42 fn cat(in_x : usize, in_y : isize, in_name: String) -> cat {
43     cat {
44         meows: in_x,
45         how_hungry: in_y,
46         name: in_name
47     }
48 }
49
50 impl fmt::Display for cat {
51     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
52         write!(f, "{}", self.name)
53     }
54 }
55
56 fn print_out(thing: Box<dyn ToString>, expected: String) {
57   let actual = (*thing).to_string();
58   println!("{}", actual);
59   assert_eq!(actual.to_string(), expected);
60 }
61
62 pub fn main() {
63   let nyan: Box<dyn ToString> = box cat(0, 2, "nyan".to_string()) as Box<dyn ToString>;
64   print_out(nyan, "nyan".to_string());
65 }