Last active
August 29, 2015 14:00
-
-
Save wendorf/4598cf529804b18d90e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
it("works", ||{ | |
expect("hello").to(eq("hello")); | |
expect("hello").to(eq("Hello")); | |
expect(1).to(eq(2)); | |
expect(1).to(eq(1)); | |
}); | |
} | |
struct Expectation<T> { | |
actual: T | |
} | |
impl<T: Eq + std::fmt::Show> Expectation<T> { | |
fn to(&self, expected: EqMatcher<T>) { | |
let success = expected.test(&self.actual); | |
if !success { | |
println!("Error: expected {} to equal {}", self.actual, expected.expected); | |
} | |
} | |
} | |
trait Matcher<T: Eq + std::fmt::Show> { | |
fn test(&self, actual: &T) -> bool; | |
} | |
struct EqMatcher<T> { | |
expected: T | |
} | |
fn eq<T>(expected: T) -> EqMatcher<T> { | |
EqMatcher { expected: expected } | |
} | |
impl<T: Eq + std::fmt::Show> Matcher<T> for EqMatcher<T> { | |
fn test(&self, actual: &T) -> bool { | |
self.expected == *actual | |
} | |
} | |
fn expect<T>(actual: T) -> Expectation<T> { | |
Expectation { actual: actual } | |
} | |
fn it(description: &str, body: ||) { | |
let _ = description; | |
body(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment