Skip to content

Commit

Permalink
feat(assert): Code is from a set.
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 23, 2018
1 parent 6f48375 commit 72dca8d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,22 @@ impl IntoCodePredicate<predicates::ord::EqPredicate<i32>> for i32 {
}
}

impl IntoCodePredicate<predicates::iter::InPredicate<i32>> for Vec<i32> {
type Predicate = predicates::iter::InPredicate<i32>;

fn into_code(self) -> Self::Predicate {
predicates::iter::in_iter(self)
}
}

impl IntoCodePredicate<predicates::iter::InPredicate<i32>> for &'static [i32] {
type Predicate = predicates::iter::InPredicate<i32>;

fn into_code(self) -> Self::Predicate {
predicates::iter::in_iter(self.iter().cloned())
}
}

/// Used by `Assert` to convert Self into the needed `Predicate<[u8]>`.
pub trait IntoOutputPredicate<P>
where
Expand Down Expand Up @@ -422,6 +438,18 @@ mod test {
assert!(pred.eval(&10));
}

#[test]
fn into_code_from_vec() {
let pred = convert_code(vec![3, 10]);
assert!(pred.eval(&10));
}

#[test]
fn into_code_from_array() {
let pred = convert_code(&[3, 10] as &[i32]);
assert!(pred.eval(&10));
}

// Since IntoOutputPredicate exists solely for conversion, test it under that scenario to ensure
// it works as expected.
fn convert_output<I, P>(pred: I) -> P
Expand Down

0 comments on commit 72dca8d

Please sign in to comment.