Skip to content

Commit

Permalink
test: Simulate abstract methods with template modules
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Apr 14, 2012
1 parent 611061b commit 658b6a7
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/test/run-pass/module-polymorphism4-files/cat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type T = cat;

enum cat {
howlycat,
meowlycat
}

fn animal() -> str { "cat" }
fn talk(c: cat) -> str {
alt c {
howlycat { "howl" }
meowlycat { "meow" }
}
}
9 changes: 9 additions & 0 deletions src/test/run-pass/module-polymorphism4-files/dog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type T = dog;

enum dog {
dog
}

fn animal() -> str { "dog" }
fn talk(_d: dog) -> str { "woof" }

9 changes: 9 additions & 0 deletions src/test/run-pass/module-polymorphism4-files/trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
impl talky for T {

// 'animal' and 'talk' functions are implemented by the module
// instantiating the talky trait. They are 'abstract'
fn says() -> str {
animal() + " says '" + talk(self) + "'"
}

}
28 changes: 28 additions & 0 deletions src/test/run-pass/module-polymorphism4.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#[no_core];


#[path = "module-polymorphism4-files"]
mod cat {

import inst::*;

#[path = "cat.rs"]
mod inst;

#[path = "trait.rs"]
mod trait;

}

#[path = "module-polymorphism4-files"]
mod dog {

import inst::*;

#[path = "dog.rs"]
mod inst;

#[path = "trait.rs"]
mod trait;

}
14 changes: 14 additions & 0 deletions src/test/run-pass/module-polymorphism4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This isn't really xfailed; it's used by the
// module-polymorphism.rc test
// xfail-test

fn main() {
import cat::trait::talky;
import dog::trait::talky;
let cat1 = cat::inst::meowlycat;
let cat2 = cat::inst::howlycat;
let dog = dog::inst::dog;
assert cat1.says() == "cat says 'meow'";
assert cat2.says() == "cat says 'howl'";
assert dog.says() == "dog says 'woof'";
}

0 comments on commit 658b6a7

Please sign in to comment.