Skip to content

Commit d7ba59e

Browse files
committed
Test that a class can implement an interface defined in a different crate
1 parent 516b90e commit d7ba59e

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/test/auxiliary/cci_class_iface.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mod animals {
2+
3+
iface noisy {
4+
fn speak();
5+
}
6+
7+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// xfail-fast
2+
// aux-build:cci_class_iface.rs
3+
use cci_class_iface;
4+
import cci_class_iface::animals::*;
5+
6+
class cat implements noisy {
7+
priv {
8+
let mut meows : uint;
9+
fn meow() {
10+
#error("Meow");
11+
self.meows += 1u;
12+
if self.meows % 5u == 0u {
13+
self.how_hungry += 1;
14+
}
15+
}
16+
}
17+
18+
let mutable how_hungry : int;
19+
let name : str;
20+
21+
new(in_x : uint, in_y : int, in_name: str)
22+
{ self.meows = in_x; self.how_hungry = in_y; self.name = in_name; }
23+
24+
fn speak() { self.meow(); }
25+
26+
fn eat() -> bool {
27+
if self.how_hungry > 0 {
28+
#error("OM NOM NOM");
29+
self.how_hungry -= 2;
30+
ret true;
31+
}
32+
else {
33+
#error("Not hungry!");
34+
ret false;
35+
}
36+
}
37+
}
38+
39+
fn main() {
40+
let nyan = cat(0u, 2, "nyan");
41+
nyan.eat();
42+
assert(!nyan.eat());
43+
uint::range(1u, 10u, {|_i| nyan.speak(); });
44+
assert(nyan.eat());
45+
}

0 commit comments

Comments
 (0)