Skip to content

Commit

Permalink
Merge pull request #15 from globin/rustup
Browse files Browse the repository at this point in the history
rustup
  • Loading branch information
alexcrichton committed Feb 23, 2015
2 parents 70d572f + fb73232 commit af4418f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/hamcrest/matchers/close_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn close_to_eps<T: Float + PartialEq + fmt::Display>(expected: T, epsilon: T
#[cfg(test)]
mod test {
use std::num::Float;
use std::thread::Thread;
use std::thread;
use {assert_that,is,close_to,close_to_eps};

#[test]
Expand All @@ -56,15 +56,15 @@ mod test {
assert_that(1e-40f32, is(close_to_eps(0.0, 0.01)));

// Unsuccessful match
assert!(Thread::scoped(|| {
assert!(thread::spawn(|| {
assert_that(2.0, is(close_to(1.0f32)));
}).join().is_err());

assert!(Thread::scoped(move || {
assert!(thread::spawn(move || {
assert_that(nan, is(close_to(nan)));
}).join().is_err());

assert!(Thread::scoped(|| {
assert!(thread::spawn(|| {
assert_that(1e-40f32, is(close_to_eps(0.0, 0.000001)));
}).join().is_err());
}
Expand Down
4 changes: 2 additions & 2 deletions src/hamcrest/matchers/equal_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn equal_to<T : PartialEq + fmt::Debug>(expected: T) -> EqualTo<T> {

#[cfg(test)]
mod test {
use std::thread::Thread;
use std::thread;
use {assert_that,is,equal_to};

#[test]
Expand All @@ -37,7 +37,7 @@ mod test {
assert_that(&1, is(equal_to(&1i)));

// Unsuccessful match
let res = Thread::scoped(|| {
let res = thread::spawn(|| {
assert_that(&2, is(equal_to(&1i)));
}).join();

Expand Down
13 changes: 8 additions & 5 deletions src/hamcrest/matchers/is.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::fmt;
use {Matcher,MatchResult};
use std::marker::PhantomData;
use {Matcher, MatchResult};

pub struct Is<T, M> {
matcher: M
matcher: M,
marker: PhantomData<T>,
}

impl<T, M: Matcher<T>> fmt::Display for Is<T, M> {
Expand All @@ -18,11 +20,12 @@ impl<T, M : Matcher<T>> Matcher<T> for Is<T, M> {
}

pub fn is<T, M: Matcher<T>>(matcher: M) -> Is<T, M> {
Is { matcher: matcher }
Is { matcher: matcher, marker: PhantomData }
}

pub struct IsNot<T, M> {
matcher: M
matcher: M,
marker: PhantomData<T>,
}

impl<T, M : Matcher<T>> fmt::Display for IsNot<T, M> {
Expand All @@ -41,5 +44,5 @@ impl<T, M : Matcher<T>> Matcher<T> for IsNot<T, M> {
}

pub fn is_not<T, M: Matcher<T>>(matcher: M) -> IsNot<T, M> {
IsNot { matcher: matcher }
IsNot { matcher: matcher, marker: PhantomData }
}
9 changes: 6 additions & 3 deletions src/hamcrest/matchers/none.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use std::fmt;
use std::marker::PhantomData;

use {success,Matcher,MatchResult};
use {success, Matcher, MatchResult};

pub struct IsNone<T>;
pub struct IsNone<T> {
marker: PhantomData<T>,
}

impl<T> fmt::Display for IsNone<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -20,7 +23,7 @@ impl<T: fmt::Display> Matcher<Option<T>> for IsNone<T> {
}

pub fn none<T>() -> IsNone<T> {
IsNone
IsNone { marker: PhantomData }
}

#[cfg(test)]
Expand Down
8 changes: 4 additions & 4 deletions src/hamcrest/matchers/vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ impl<T> Contains<T> {
impl<T: fmt::Display> fmt::Display for Contains<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.exactly {
write!(f, "containing exactly {}", Pretty(&self.items[]))
write!(f, "containing exactly {}", Pretty(&self.items))
} else {
write!(f, "containing {}", Pretty(&self.items[]))
write!(f, "containing {}", Pretty(&self.items))
}
}
}
Expand All @@ -58,12 +58,12 @@ impl<'a, T: fmt::Display + PartialEq + Clone> Matcher<&'a Vec<T>> for Contains<T
for item in self.items.iter() {
match rem.iter().position(|a| *item == *a) {
Some(idx) => { rem.remove(idx); },
None => return Err(format!("was {}", Pretty(&actual[])))
None => return Err(format!("was {}", Pretty(&actual)))
}
}

if self.exactly && !rem.is_empty() {
return Err(format!("also had {}", Pretty(&rem[])));
return Err(format!("also had {}", Pretty(&rem)));
}

success()
Expand Down

0 comments on commit af4418f

Please sign in to comment.