File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed
branches/try/src/test/run-pass Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 2
2
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5
- refs/heads/try: f32d9f4853e878cdd721d5120aea023e901f81d4
5
+ refs/heads/try: c2382f9ebf1ad668df7624955268f4485068449a
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
Original file line number Diff line number Diff line change
1
+ import to_str:: * ;
2
+ import to_str:: to_str;
3
+
4
+ class cat {
5
+ priv {
6
+ let mut meows : uint;
7
+ fn meow ( ) {
8
+ #error ( "Meow" ) ;
9
+ self . meows += 1 u;
10
+ if self . meows % 5 u == 0 u {
11
+ self . how_hungry += 1 ;
12
+ }
13
+ }
14
+ }
15
+
16
+ let mut how_hungry : int ;
17
+ let name : str ;
18
+
19
+ new ( in_x : uint, in_y : int, in_name: str )
20
+ { self . meows = in_x; self . how_hungry = in_y; self . name = in_name; }
21
+
22
+ fn speak ( ) { self . meow ( ) ; }
23
+
24
+ fn eat ( ) -> bool {
25
+ if self . how_hungry > 0 {
26
+ #error ( "OM NOM NOM" ) ;
27
+ self . how_hungry -= 2 ;
28
+ ret true ;
29
+ }
30
+ else {
31
+ #error ( "Not hungry!" ) ;
32
+ ret false ;
33
+ }
34
+ }
35
+ }
36
+
37
+ impl of to_str for cat {
38
+ fn to_str ( ) -> str { self . name }
39
+ }
40
+
41
+ fn print_out < T : to_str > ( thing : T , expected : str ) {
42
+ let actual = thing. to_str ( ) ;
43
+ #debug ( "%s" , actual) ;
44
+ assert ( actual == expected) ;
45
+ }
46
+
47
+ fn main ( ) {
48
+ let nyan : to_str = cat ( 0 u, 2 , "nyan" ) as to_str ;
49
+ print_out ( nyan, "nyan" ) ;
50
+ }
You can’t perform that action at this time.
0 commit comments