|
| 1 | +//! `process::Output` assertions. |
| 2 | +
|
1 | 3 | use std::fmt;
|
2 | 4 | use std::process;
|
3 | 5 | use std::str;
|
@@ -400,21 +402,69 @@ where
|
400 | 402 | }
|
401 | 403 | }
|
402 | 404 |
|
403 |
| -impl IntoOutputPredicate<predicates::ord::EqPredicate<&'static [u8]>> for &'static [u8] { |
404 |
| - type Predicate = predicates::ord::EqPredicate<&'static [u8]>; |
| 405 | +// Keep `predicates` concrete Predicates out of our public API. |
| 406 | +/// Predicate used by `IntoOutputPredicate` for bytes |
| 407 | +#[derive(Debug)] |
| 408 | +pub struct BytesContentOutputPredicate(predicates::ord::EqPredicate<&'static [u8]>); |
| 409 | + |
| 410 | +impl BytesContentOutputPredicate { |
| 411 | + pub(crate) fn new(value: &'static [u8]) -> Self { |
| 412 | + let pred = predicates::ord::eq(value); |
| 413 | + BytesContentOutputPredicate(pred) |
| 414 | + } |
| 415 | +} |
| 416 | + |
| 417 | +impl predicates::Predicate<[u8]> for BytesContentOutputPredicate { |
| 418 | + fn eval(&self, item: &[u8]) -> bool { |
| 419 | + self.0.eval(item) |
| 420 | + } |
| 421 | +} |
| 422 | + |
| 423 | +impl fmt::Display for BytesContentOutputPredicate { |
| 424 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 425 | + self.0.fmt(f) |
| 426 | + } |
| 427 | +} |
| 428 | + |
| 429 | +impl IntoOutputPredicate<BytesContentOutputPredicate> for &'static [u8] { |
| 430 | + type Predicate = BytesContentOutputPredicate; |
405 | 431 |
|
406 | 432 | fn into_output(self) -> Self::Predicate {
|
407 |
| - predicates::ord::eq(self) |
| 433 | + Self::Predicate::new(self) |
408 | 434 | }
|
409 | 435 | }
|
410 | 436 |
|
411 |
| -impl IntoOutputPredicate<predicates::str::Utf8Predicate<predicates::str::DifferencePredicate>> |
412 |
| - for &'static str |
413 |
| -{ |
414 |
| - type Predicate = predicates::str::Utf8Predicate<predicates::str::DifferencePredicate>; |
| 437 | +// Keep `predicates` concrete Predicates out of our public API. |
| 438 | +/// Predicate used by `IntoOutputPredicate` for `str` |
| 439 | +#[derive(Debug, Clone)] |
| 440 | +pub struct StrContentOutputPredicate( |
| 441 | + predicates::str::Utf8Predicate<predicates::str::DifferencePredicate>, |
| 442 | +); |
| 443 | + |
| 444 | +impl StrContentOutputPredicate { |
| 445 | + pub(crate) fn new(value: &'static str) -> Self { |
| 446 | + let pred = predicates::str::similar(value).from_utf8(); |
| 447 | + StrContentOutputPredicate(pred) |
| 448 | + } |
| 449 | +} |
| 450 | + |
| 451 | +impl predicates::Predicate<[u8]> for StrContentOutputPredicate { |
| 452 | + fn eval(&self, item: &[u8]) -> bool { |
| 453 | + self.0.eval(item) |
| 454 | + } |
| 455 | +} |
| 456 | + |
| 457 | +impl fmt::Display for StrContentOutputPredicate { |
| 458 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 459 | + self.0.fmt(f) |
| 460 | + } |
| 461 | +} |
| 462 | + |
| 463 | +impl IntoOutputPredicate<StrContentOutputPredicate> for &'static str { |
| 464 | + type Predicate = StrContentOutputPredicate; |
415 | 465 |
|
416 | 466 | fn into_output(self) -> Self::Predicate {
|
417 |
| - predicates::str::similar(self).from_utf8() |
| 467 | + Self::Predicate::new(self) |
418 | 468 | }
|
419 | 469 | }
|
420 | 470 |
|
|
0 commit comments