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
24 changes: 12 additions & 12 deletions googletest/crate_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ impl<T: PartialEq + Debug> Matcher for MyEqMatcher<T> {

fn matches(&self, actual: &Self::ActualT) -> MatcherResult {
if self.expected == *actual {
MatcherResult::Matches
MatcherResult::Match
} else {
MatcherResult::DoesNotMatch
MatcherResult::NoMatch
}
}

fn describe(&self, matcher_result: MatcherResult) -> String {
match matcher_result {
MatcherResult::Matches => {
MatcherResult::Match => {
format!("is equal to {:?} the way I define it", self.expected)
}
MatcherResult::DoesNotMatch => {
MatcherResult::NoMatch => {
format!("isn't equal to {:?} the way I define it", self.expected)
}
}
Expand All @@ -213,18 +213,18 @@ impl<T: PartialEq + Debug> Matcher for MyEqMatcher<T> {
#
# fn matches(&self, actual: &Self::ActualT) -> MatcherResult {
# if self.expected == *actual {
# MatcherResult::Matches
# MatcherResult::Match
# } else {
# MatcherResult::DoesNotMatch
# MatcherResult::NoMatch
# }
# }
#
# fn describe(&self, matcher_result: MatcherResult) -> String {
# match matcher_result {
# MatcherResult::Matches => {
# MatcherResult::Match => {
# format!("is equal to {:?} the way I define it", self.expected)
# }
# MatcherResult::DoesNotMatch => {
# MatcherResult::NoMatch => {
# format!("isn't equal to {:?} the way I define it", self.expected)
# }
# }
Expand Down Expand Up @@ -252,18 +252,18 @@ impl<T: PartialEq + Debug> Matcher for MyEqMatcher<T> {
#
# fn matches(&self, actual: &Self::ActualT) -> MatcherResult {
# if self.expected == *actual {
# MatcherResult::Matches
# MatcherResult::Match
# } else {
# MatcherResult::DoesNotMatch
# MatcherResult::NoMatch
# }
# }
#
# fn describe(&self, matcher_result: MatcherResult) -> String {
# match matcher_result {
# MatcherResult::Matches => {
# MatcherResult::Match => {
# format!("is equal to {:?} the way I define it", self.expected)
# }
# MatcherResult::DoesNotMatch => {
# MatcherResult::NoMatch => {
# format!("isn't equal to {:?} the way I define it", self.expected)
# }
# }
Expand Down
4 changes: 2 additions & 2 deletions googletest/src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ pub mod internal {
source_location: SourceLocation,
) -> Result<(), TestAssertionFailure> {
match expected.matches(actual) {
MatcherResult::Matches => Ok(()),
MatcherResult::DoesNotMatch => {
MatcherResult::Match => Ok(()),
MatcherResult::NoMatch => {
Err(create_assertion_failure(&expected, actual, actual_expr, source_location))
}
}
Expand Down
31 changes: 15 additions & 16 deletions googletest/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Expected: {}
Actual: {actual_formatted},
{}
{source_location}",
matcher.describe(MatcherResult::Matches),
matcher.describe(MatcherResult::Match),
matcher.explain_match(actual),
))
}
Expand All @@ -234,35 +234,34 @@ Actual: {actual_formatted},
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum MatcherResult {
/// The actual value matches according to the [`Matcher`] definition.
Matches,
Match,
/// The actual value does not match according to the [`Matcher`] definition.
DoesNotMatch,
NoMatch,
}

impl From<bool> for MatcherResult {
fn from(b: bool) -> Self {
if b { MatcherResult::Matches } else { MatcherResult::DoesNotMatch }
if b {
MatcherResult::Match
} else {
MatcherResult::NoMatch
}
}
}

impl From<MatcherResult> for bool {
fn from(matcher_result: MatcherResult) -> Self {
match matcher_result {
MatcherResult::Matches => true,
MatcherResult::DoesNotMatch => false,
}
matcher_result.is_match()
}
}

impl MatcherResult {
/// Returns `true` if `self` is [`MatcherResult::Matches`], otherwise
/// Returns `true` if `self` is [`MatcherResult::Match`], otherwise
/// `false`.
///
/// This delegates to `Into<bool>` but coerce the return type to `bool`
/// instead only calling `into()`. This is useful in `if
/// !matcher_result.into()`, which requires a constraint on the result
/// type of `into()` to compile.
pub fn into_bool(self) -> bool {
self.into()
pub fn is_match(self) -> bool {
match self {
MatcherResult::Match => true,
MatcherResult::NoMatch => false,
}
}
}
14 changes: 7 additions & 7 deletions googletest/src/matchers/all_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ pub mod internal {
fn matches(&self, actual: &Self::ActualT) -> MatcherResult {
for component in &self.components {
match component.matches(actual) {
MatcherResult::DoesNotMatch => {
return MatcherResult::DoesNotMatch;
MatcherResult::NoMatch => {
return MatcherResult::NoMatch;
}
MatcherResult::Matches => {}
MatcherResult::Match => {}
}
}
MatcherResult::Matches
MatcherResult::Match
}

fn explain_match(&self, actual: &Self::ActualT) -> String {
Expand All @@ -109,7 +109,7 @@ pub mod internal {
let failures = self
.components
.iter()
.filter(|component| !component.matches(actual).into_bool())
.filter(|component| !component.matches(actual).is_match())
.map(|component| component.explain_match(actual))
.collect::<Description>();
if failures.len() == 1 {
Expand Down Expand Up @@ -161,7 +161,7 @@ mod tests {
let matcher: internal::AllMatcher<String, 2> = all!(first_matcher, second_matcher);

verify_that!(
matcher.describe(MatcherResult::Matches),
matcher.describe(MatcherResult::Match),
eq(indoc!(
"
has all the following properties:
Expand All @@ -176,7 +176,7 @@ mod tests {
let first_matcher = starts_with("A");
let matcher: internal::AllMatcher<String, 1> = all!(first_matcher);

verify_that!(matcher.describe(MatcherResult::Matches), eq("starts with prefix \"A\""))
verify_that!(matcher.describe(MatcherResult::Match), eq("starts with prefix \"A\""))
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions googletest/src/matchers/anything_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ impl<T: Debug + ?Sized> Matcher for Anything<T> {
type ActualT = T;

fn matches(&self, _: &T) -> MatcherResult {
MatcherResult::Matches
MatcherResult::Match
}

fn describe(&self, matcher_result: MatcherResult) -> String {
match matcher_result {
MatcherResult::Matches => "is anything".to_string(),
MatcherResult::DoesNotMatch => "never matches".to_string(),
MatcherResult::Match => "is anything".to_string(),
MatcherResult::NoMatch => "never matches".to_string(),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions googletest/src/matchers/char_count_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ impl<T: Debug + ?Sized + AsRef<str>, E: Matcher<ActualT = usize>> Matcher for Ch

fn describe(&self, matcher_result: MatcherResult) -> String {
match matcher_result {
MatcherResult::Matches => {
MatcherResult::Match => {
format!(
"has character count, which {}",
self.expected.describe(MatcherResult::Matches)
self.expected.describe(MatcherResult::Match)
)
}
MatcherResult::DoesNotMatch => {
MatcherResult::NoMatch => {
format!(
"has character count, which {}",
self.expected.describe(MatcherResult::DoesNotMatch)
self.expected.describe(MatcherResult::NoMatch)
)
}
}
Expand Down
12 changes: 6 additions & 6 deletions googletest/src/matchers/conjunction_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ where

fn matches(&self, actual: &M1::ActualT) -> MatcherResult {
match (self.m1.matches(actual), self.m2.matches(actual)) {
(MatcherResult::Matches, MatcherResult::Matches) => MatcherResult::Matches,
_ => MatcherResult::DoesNotMatch,
(MatcherResult::Match, MatcherResult::Match) => MatcherResult::Match,
_ => MatcherResult::NoMatch,
}
}

fn explain_match(&self, actual: &M1::ActualT) -> String {
match (self.m1.matches(actual), self.m2.matches(actual)) {
(MatcherResult::Matches, MatcherResult::Matches) => {
(MatcherResult::Match, MatcherResult::Match) => {
format!(
"{} and\n {}",
self.m1.explain_match(actual),
self.m2.explain_match(actual)
)
}
(MatcherResult::DoesNotMatch, MatcherResult::Matches) => self.m1.explain_match(actual),
(MatcherResult::Matches, MatcherResult::DoesNotMatch) => self.m2.explain_match(actual),
(MatcherResult::DoesNotMatch, MatcherResult::DoesNotMatch) => {
(MatcherResult::NoMatch, MatcherResult::Match) => self.m1.explain_match(actual),
(MatcherResult::Match, MatcherResult::NoMatch) => self.m2.explain_match(actual),
(MatcherResult::NoMatch, MatcherResult::NoMatch) => {
format!(
"{} and\n {}",
self.m1.explain_match(actual),
Expand Down
14 changes: 7 additions & 7 deletions googletest/src/matchers/container_eq_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ where

fn describe(&self, matcher_result: MatcherResult) -> String {
match matcher_result {
MatcherResult::Matches => format!("is equal to {:?}", self.expected),
MatcherResult::DoesNotMatch => format!("isn't equal to {:?}", self.expected),
MatcherResult::Match => format!("is equal to {:?}", self.expected),
MatcherResult::NoMatch => format!("isn't equal to {:?}", self.expected),
}
}
}
Expand Down Expand Up @@ -265,21 +265,21 @@ mod tests {
}

#[test]
fn container_eq_matches_owned_vec_of_owned_strings_with_slice_of_string_references()
-> Result<()> {
fn container_eq_matches_owned_vec_of_owned_strings_with_slice_of_string_references(
) -> Result<()> {
let vector = vec!["A string".to_string(), "Another string".to_string()];
verify_that!(vector, container_eq(["A string", "Another string"]))
}

#[test]
fn container_eq_matches_owned_vec_of_owned_strings_with_shorter_slice_of_string_references()
-> Result<()> {
fn container_eq_matches_owned_vec_of_owned_strings_with_shorter_slice_of_string_references(
) -> Result<()> {
let actual = vec!["A string".to_string(), "Another string".to_string()];
let matcher = container_eq(["A string"]);

let result = matcher.matches(&actual);

verify_that!(result, eq(MatcherResult::DoesNotMatch))
verify_that!(result, eq(MatcherResult::NoMatch))
}

#[test]
Expand Down
Loading