Skip to content

Commit

Permalink
use a trait default implementation to avoid repeating the code
Browse files Browse the repository at this point in the history
  • Loading branch information
glehmann committed Feb 8, 2024
1 parent 21adb7c commit d3cc000
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Deref;

use predicates_tree::CaseTreeExt;

pub trait TestPathChild {
Expand All @@ -11,26 +13,19 @@ impl TestPathChild for assert_fs::fixture::ChildPath {
}

pub trait TestString {
fn assert(&self, predicate: impl predicates::Predicate<str>) -> &Self;
}

impl TestString for str {
fn assert(&self, predicate: impl predicates::Predicate<str>) -> &Self {
if let Some(case) = predicate.find_case(false, self.as_ref()) {
panic!("{}", case.tree(),);
fn assert(&self, predicate: impl predicates::Predicate<str>) -> &Self
where
Self: Deref<Target = str>,
{
if let Some(case) = predicate.find_case(false, self) {
panic!("{}", case.tree());
}
self
}
}

impl TestString for String {
fn assert(&self, predicate: impl predicates::Predicate<str>) -> &Self {
if let Some(case) = predicate.find_case(false, self.as_ref()) {
panic!("{}", case.tree(),);
}
self
}
}
impl TestString for str {}
impl TestString for String {}

#[macro_export]
macro_rules! yage {
Expand Down

0 comments on commit d3cc000

Please sign in to comment.