rust/src/test/run-pass/anon-obj-cats.rs

47 lines
1.0 KiB
Rust
Raw Normal View History

2011-08-09 17:42:48 -05:00
fn main() {
// The Internet made me do it.
obj cat() {
fn ack() -> str { ret "ack"; }
fn meow() -> str { ret "meow"; }
fn zzz() -> str { ret self.meow(); }
2011-08-09 17:42:48 -05:00
}
let shortcat = cat();
let longcat =
obj () {
fn lol() -> str { ret "lol"; }
fn nyan() -> str { ret "nyan"; }
with
shortcat
};
let longercat =
obj () {
fn meow() -> str { ret "zzz"; }
with
shortcat
};
let evenlongercat =
obj () {
fn meow() -> str { ret "zzzzzz"; }
with
longercat
};
2011-08-09 17:42:48 -05:00
// Tests self-call.
assert (shortcat.zzz() == "meow");
// Tests forwarding/backwarding + self-call.
assert (longcat.zzz() == "meow");
// Tests forwarding/backwarding + self-call + override.
assert (longercat.zzz() == "zzz");
// Tests two-level forwarding/backwarding + self-call + override.
assert (evenlongercat.zzz() == "zzzzzz");
}