Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/char/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,14 @@ fn verify_borrowed_char_is_whitespace_fails() {
proptest! {
#[test]
fn asserting_ascii_and_lowercase_is_equivalent_to_ascii_lowercase_method(
chr in any::<char>(),
chr in prop::arbitrary::any::<char>(),
) {
prop_assert_eq!(chr.is_ascii() && chr.is_lowercase(), chr.is_ascii_lowercase());
}

#[test]
fn asserting_ascii_and_uppercase_is_equivalent_to_ascii_uppercase_method(
chr in any::<char>(),
chr in prop::arbitrary::any::<char>(),
) {
prop_assert_eq!(chr.is_ascii() && chr.is_uppercase(), chr.is_ascii_uppercase());
}
Expand Down
171 changes: 171 additions & 0 deletions src/expectation_combinators/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
use crate::expectations::{All, Any, IntoRec, Not, Rec};
use crate::spec::{DiffFormat, Expectation, Expression, Invertible};
use crate::std::string::String;

impl<S, E> Expectation<S> for Rec<E>
where
E: Expectation<S>,
{
fn test(&mut self, subject: &S) -> bool {
let result = self.expectation.test(subject);
self.result = Some(result);
result
}

fn message(
&self,
expression: &Expression<'_>,
actual: &S,
inverted: bool,
format: &DiffFormat,
) -> String {
if self.is_failure() {
self.expectation
.message(expression, actual, inverted, format)
+ "\n"
} else {
String::new()
}
}
}

impl<E> From<E> for Rec<E> {
fn from(expectation: E) -> Self {
Self::new(expectation)
}
}

macro_rules! impl_into_rec_for_tuple {
( $( $tp_name:ident )+ ) => {
#[allow(non_snake_case)]
impl<$($tp_name: Into<Rec<$tp_name >>),+> IntoRec for ($($tp_name,)+) {
type Output = ($(Rec<$tp_name>,)+);

fn into_rec(self) -> Self::Output {
let ($($tp_name,)+) = self;
($($tp_name.into(),)+)
}
}
};
}

impl_into_rec_for_tuple! { A1 }
impl_into_rec_for_tuple! { A1 A2 }
impl_into_rec_for_tuple! { A1 A2 A3 }
impl_into_rec_for_tuple! { A1 A2 A3 A4 }
impl_into_rec_for_tuple! { A1 A2 A3 A4 A5 }
impl_into_rec_for_tuple! { A1 A2 A3 A4 A5 A6 }
impl_into_rec_for_tuple! { A1 A2 A3 A4 A5 A6 A7 }
impl_into_rec_for_tuple! { A1 A2 A3 A4 A5 A6 A7 A8 }
impl_into_rec_for_tuple! { A1 A2 A3 A4 A5 A6 A7 A8 A9 }
impl_into_rec_for_tuple! { A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 }
impl_into_rec_for_tuple! { A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 }
impl_into_rec_for_tuple! { A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 }

impl<S, E> Expectation<S> for Not<E>
where
E: Invertible + Expectation<S>,
{
fn test(&mut self, subject: &S) -> bool {
!self.0.test(subject)
}

fn message(
&self,
expression: &Expression<'_>,
actual: &S,
inverted: bool,
format: &DiffFormat,
) -> String {
self.0.message(expression, actual, !inverted, format)
}
}

macro_rules! impl_expectation_for_all_combinator {
( $( $tp_name:ident )+ ) => {
#[allow(non_snake_case)]
impl<S, $($tp_name: Expectation<S>),+> Expectation<S> for All<($(Rec<$tp_name>,)+)> {
fn test(&mut self, subject: &S) -> bool {
let ($($tp_name,)+) = &mut self.0;
$(
let $tp_name = $tp_name.test(subject);
)+
$( $tp_name )&&+
}

fn message(
&self,
expression: &Expression<'_>,
actual: &S,
inverted: bool,
format: &DiffFormat,
) -> String {
let ($($tp_name,)+) = &self.0;
let mut message = String::new();
$(
message.push_str(&$tp_name.message(expression, actual, inverted, format));
)+
message
}
}
};
}

impl_expectation_for_all_combinator! { A1 }
impl_expectation_for_all_combinator! { A1 A2 }
impl_expectation_for_all_combinator! { A1 A2 A3 }
impl_expectation_for_all_combinator! { A1 A2 A3 A4 }
impl_expectation_for_all_combinator! { A1 A2 A3 A4 A5 }
impl_expectation_for_all_combinator! { A1 A2 A3 A4 A5 A6 }
impl_expectation_for_all_combinator! { A1 A2 A3 A4 A5 A6 A7 }
impl_expectation_for_all_combinator! { A1 A2 A3 A4 A5 A6 A7 A8 }
impl_expectation_for_all_combinator! { A1 A2 A3 A4 A5 A6 A7 A8 A9 }
impl_expectation_for_all_combinator! { A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 }
impl_expectation_for_all_combinator! { A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 }
impl_expectation_for_all_combinator! { A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 }

macro_rules! impl_expectation_for_any_combinator {
( $( $tp_name:ident )+ ) => {
#[allow(non_snake_case)]
impl<S, $($tp_name: Expectation<S>),+> Expectation<S> for Any<($(Rec<$tp_name>,)+)> {
fn test(&mut self, subject: &S) -> bool {
let ($($tp_name,)+) = &mut self.0;
$(
let $tp_name = $tp_name.test(subject);
)+
$( $tp_name )||+
}

fn message(
&self,
expression: &Expression<'_>,
actual: &S,
inverted: bool,
format: &DiffFormat,
) -> String {
let ($($tp_name,)+) = &self.0;
let mut message = String::new();
$(
message.push_str(&$tp_name.message(expression, actual, inverted, format));
)+
message
}
}
};
}

impl_expectation_for_any_combinator! { A1 }
impl_expectation_for_any_combinator! { A1 A2 }
impl_expectation_for_any_combinator! { A1 A2 A3 }
impl_expectation_for_any_combinator! { A1 A2 A3 A4 }
impl_expectation_for_any_combinator! { A1 A2 A3 A4 A5 }
impl_expectation_for_any_combinator! { A1 A2 A3 A4 A5 A6 }
impl_expectation_for_any_combinator! { A1 A2 A3 A4 A5 A6 A7 }
impl_expectation_for_any_combinator! { A1 A2 A3 A4 A5 A6 A7 A8 }
impl_expectation_for_any_combinator! { A1 A2 A3 A4 A5 A6 A7 A8 A9 }
impl_expectation_for_any_combinator! { A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 }
impl_expectation_for_any_combinator! { A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 }
impl_expectation_for_any_combinator! { A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 }

#[cfg(test)]
mod tests;
Loading
Loading