Skip to content

Commit

Permalink
Rename assertions to be more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
TehPers committed Aug 19, 2024
1 parent 5413f7e commit 1d783e8
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 76 deletions.
8 changes: 4 additions & 4 deletions src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
//!
//! // We need to create a struct for our assertion and define its behavior
//! #[derive(Clone, Debug)]
//! pub struct ToBeZeroAssertion(Annotated<String>);
//! pub struct ToBeZero(Annotated<String>);
//!
//! impl Assertion<i32> for ToBeZeroAssertion {
//! impl Assertion<i32> for ToBeZero {
//! // What does this assertion return when it's executed? Sometimes
//! // assertions want to return other output types, like if they need to
//! // run asynchronously and have to return a future instead.
Expand All @@ -69,8 +69,8 @@
//! trait MyAssertions {
//! // Input parameters are automatically annotated, so we need to wrap them
//! // with `Annotated<T>`
//! fn to_be_zero(&self, note: Annotated<String>) -> ToBeZeroAssertion {
//! ToBeZeroAssertion(note)
//! fn to_be_zero(&self, note: Annotated<String>) -> ToBeZero {
//! ToBeZero(note)
//! }
//! }
//!
Expand Down
6 changes: 3 additions & 3 deletions src/assertions/general/assertions/to_be_one_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use crate::{

/// Asserts that the subject is equal to one of the items in an iterator.
#[derive(Clone, Debug)]
pub struct ToBeOneOfAssertion<I> {
pub struct ToBeOneOf<I> {
items: Annotated<I>,
}

impl<I> ToBeOneOfAssertion<I> {
impl<I> ToBeOneOf<I> {
#[inline]
pub(crate) fn new(items: Annotated<I>) -> Self {
Self { items }
}
}

impl<I, T> Assertion<T> for ToBeOneOfAssertion<I>
impl<I, T> Assertion<T> for ToBeOneOf<I>
where
I: IntoIterator,
T: PartialEq<I::Item>,
Expand Down
6 changes: 3 additions & 3 deletions src/assertions/general/assertions/to_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use crate::{

/// A general-purpose assertion for comparing the ordering between two values.
#[derive(Clone, Debug)]
pub struct ToCmpAssertion<U> {
pub struct ToCmp<U> {
boundary: Annotated<U>,
ordering: Ordering,
allow_eq: bool,
cmp_message: &'static str,
}

impl<U> ToCmpAssertion<U> {
impl<U> ToCmp<U> {
#[inline]
pub(crate) fn new(
boundary: Annotated<U>,
Expand All @@ -32,7 +32,7 @@ impl<U> ToCmpAssertion<U> {
}
}

impl<T, U> Assertion<T> for ToCmpAssertion<U>
impl<T, U> Assertion<T> for ToCmp<U>
where
T: PartialOrd<U>,
{
Expand Down
6 changes: 3 additions & 3 deletions src/assertions/general/assertions/to_equal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ use crate::{

/// Asserts that the subject is equal to an expected value.
#[derive(Clone, Debug)]
pub struct ToEqualAssertion<U> {
pub struct ToEqual<U> {
expected: Annotated<U>,
}

impl<U> ToEqualAssertion<U> {
impl<U> ToEqual<U> {
#[inline]
pub(crate) fn new(expected: Annotated<U>) -> Self {
Self { expected }
}
}

impl<T, U> Assertion<T> for ToEqualAssertion<U>
impl<T, U> Assertion<T> for ToEqual<U>
where
T: PartialEq<U>,
{
Expand Down
8 changes: 4 additions & 4 deletions src/assertions/general/assertions/to_equal_approx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use crate::{

/// Asserts that the subject is approximately equal to an expected value.
#[derive(Clone, Debug)]
pub struct ToEqualApproxAssertion<T> {
pub struct ToEqualApprox<T> {
expected: Annotated<T>,
max_delta: Annotated<T>,
}

impl<T> ToEqualApproxAssertion<T> {
impl<T> ToEqualApprox<T> {
#[inline]
pub(crate) fn new(expected: Annotated<T>, max_delta: Annotated<T>) -> Self {
Self {
Expand All @@ -21,7 +21,7 @@ impl<T> ToEqualApproxAssertion<T> {
}
}

impl Assertion<f32> for ToEqualApproxAssertion<f32> {
impl Assertion<f32> for ToEqualApprox<f32> {
type Output = AssertionOutput;

fn execute(self, mut cx: AssertionContext, subject: f32) -> Self::Output {
Expand All @@ -34,7 +34,7 @@ impl Assertion<f32> for ToEqualApproxAssertion<f32> {
}
}

impl Assertion<f64> for ToEqualApproxAssertion<f64> {
impl Assertion<f64> for ToEqualApprox<f64> {
type Output = AssertionOutput;

fn execute(self, mut cx: AssertionContext, subject: f64) -> Self::Output {
Expand Down
6 changes: 3 additions & 3 deletions src/assertions/general/assertions/to_satisfy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use crate::{

/// Asserts that the subject satisfies a predicate.
#[derive(Clone, Debug)]
pub struct ToSatisfyAssertion<F> {
pub struct ToSatisfy<F> {
predicate: Annotated<F>,
}

impl<F> ToSatisfyAssertion<F> {
impl<F> ToSatisfy<F> {
#[inline]
pub(crate) fn new(predicate: Annotated<F>) -> Self {
Self { predicate }
}
}

impl<F, T> Assertion<T> for ToSatisfyAssertion<F>
impl<F, T> Assertion<T> for ToSatisfy<F>
where
F: FnOnce(T) -> bool,
{
Expand Down
6 changes: 3 additions & 3 deletions src/assertions/general/assertions/to_satisfy_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use crate::{

/// Asserts that the subject satisfies a series of assertions.
#[derive(Clone, Debug)]
pub struct ToSatisfyWithAssertion<F> {
pub struct ToSatisfyWith<F> {
predicate: Annotated<F>,
}

impl<F> ToSatisfyWithAssertion<F> {
impl<F> ToSatisfyWith<F> {
#[inline]
pub(crate) fn new(predicate: Annotated<F>) -> Self {
Self { predicate }
}
}

impl<F, T> Assertion<T> for ToSatisfyWithAssertion<F>
impl<F, T> Assertion<T> for ToSatisfyWith<F>
where
F: FnOnce(T) -> Result<(), AssertionError>,
{
Expand Down
40 changes: 20 additions & 20 deletions src/assertions/general/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
};

use super::{
Float, MapModifier, NotModifier, ToBeOneOfAssertion, ToCmpAssertion, ToEqualApproxAssertion,
ToEqualAssertion, ToSatisfyAssertion, ToSatisfyWithAssertion,
Float, MapModifier, NotModifier, ToBeOneOf, ToCmp, ToEqual, ToEqualApprox, ToSatisfy,
ToSatisfyWith,
};

/// General-purpose assertions and modifiers.
Expand Down Expand Up @@ -115,11 +115,11 @@ pub trait GeneralAssertions<T, M> {
/// expect!(1, to_satisfy(is_odd));
/// ```
#[inline]
fn to_satisfy<F>(&self, predicate: Annotated<F>) -> ToSatisfyAssertion<F>
fn to_satisfy<F>(&self, predicate: Annotated<F>) -> ToSatisfy<F>
where
F: FnOnce(T) -> bool,
{
ToSatisfyAssertion::new(predicate)
ToSatisfy::new(predicate)
}

/// Asserts that the subject matches a series of inner assertions. This
Expand Down Expand Up @@ -173,11 +173,11 @@ pub trait GeneralAssertions<T, M> {
/// ```
// TODO: make an async version
#[inline]
fn to_satisfy_with<F>(&self, predicate: Annotated<F>) -> ToSatisfyWithAssertion<F>
fn to_satisfy_with<F>(&self, predicate: Annotated<F>) -> ToSatisfyWith<F>
where
F: FnOnce(T) -> Result<(), AssertionError>,
{
ToSatisfyWithAssertion::new(predicate)
ToSatisfyWith::new(predicate)
}

/// Asserts that the subject is equal to the given value.
Expand All @@ -194,11 +194,11 @@ pub trait GeneralAssertions<T, M> {
/// expect!(1, to_equal(2));
/// ```
#[inline]
fn to_equal<U>(&self, expected: Annotated<U>) -> ToEqualAssertion<U>
fn to_equal<U>(&self, expected: Annotated<U>) -> ToEqual<U>
where
T: PartialEq<U>,
{
ToEqualAssertion::new(expected)
ToEqual::new(expected)
}

/// Asserts that the subject is within a specified range of another value.
Expand All @@ -219,11 +219,11 @@ pub trait GeneralAssertions<T, M> {
&self,
expected: Annotated<T>,
max_delta: Annotated<T>,
) -> ToEqualApproxAssertion<T>
) -> ToEqualApprox<T>
where
T: Float,
{
ToEqualApproxAssertion::new(expected, max_delta)
ToEqualApprox::new(expected, max_delta)
}

/// Asserts that the subject is less than the given value.
Expand All @@ -240,11 +240,11 @@ pub trait GeneralAssertions<T, M> {
/// expect!(2, to_be_less_than(1));
/// ```
#[inline]
fn to_be_less_than<U>(&self, boundary: Annotated<U>) -> ToCmpAssertion<U>
fn to_be_less_than<U>(&self, boundary: Annotated<U>) -> ToCmp<U>
where
T: PartialOrd<U>,
{
ToCmpAssertion::new(boundary, Ordering::Less, false, "less than")
ToCmp::new(boundary, Ordering::Less, false, "less than")
}

/// Asserts that the subject is less than or equal to the given value.
Expand All @@ -262,11 +262,11 @@ pub trait GeneralAssertions<T, M> {
/// expect!(2, to_be_less_than_or_equal_to(1));
/// ```
#[inline]
fn to_be_less_than_or_equal_to<U>(&self, boundary: Annotated<U>) -> ToCmpAssertion<U>
fn to_be_less_than_or_equal_to<U>(&self, boundary: Annotated<U>) -> ToCmp<U>
where
T: PartialOrd<U>,
{
ToCmpAssertion::new(boundary, Ordering::Less, true, "less than or equal to")
ToCmp::new(boundary, Ordering::Less, true, "less than or equal to")
}

/// Asserts that the subject is greater than the given value.
Expand All @@ -283,11 +283,11 @@ pub trait GeneralAssertions<T, M> {
/// expect!(1, to_be_greater_than(2));
/// ```
#[inline]
fn to_be_greater_than<U>(&self, boundary: Annotated<U>) -> ToCmpAssertion<U>
fn to_be_greater_than<U>(&self, boundary: Annotated<U>) -> ToCmp<U>
where
T: PartialOrd<U>,
{
ToCmpAssertion::new(boundary, Ordering::Greater, false, "greater than")
ToCmp::new(boundary, Ordering::Greater, false, "greater than")
}

/// Asserts that the subject is greater than or equal to the given value.
Expand All @@ -305,11 +305,11 @@ pub trait GeneralAssertions<T, M> {
/// expect!(1, to_be_greater_than_or_equal_to(2));
/// ```
#[inline]
fn to_be_greater_than_or_equal_to<U>(&self, boundary: Annotated<U>) -> ToCmpAssertion<U>
fn to_be_greater_than_or_equal_to<U>(&self, boundary: Annotated<U>) -> ToCmp<U>
where
T: PartialOrd<U>,
{
ToCmpAssertion::new(
ToCmp::new(
boundary,
Ordering::Greater,
true,
Expand All @@ -332,12 +332,12 @@ pub trait GeneralAssertions<T, M> {
/// expect!(1, to_be_one_of([2, 3, 4]));
/// ```
#[inline]
fn to_be_one_of<I>(&self, items: Annotated<I>) -> ToBeOneOfAssertion<I>
fn to_be_one_of<I>(&self, items: Annotated<I>) -> ToBeOneOf<I>
where
I: IntoIterator,
T: PartialEq<I::Item>,
{
ToBeOneOfAssertion::new(items)
ToBeOneOf::new(items)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/assertions/iterators/assertions/to_contain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use crate::{

/// Asserts that the subject contains an expected element.
#[derive(Clone, Debug)]
pub struct ToContainAssertion<U> {
pub struct ToContain<U> {
expected: Annotated<U>,
}

impl<U> ToContainAssertion<U> {
impl<U> ToContain<U> {
#[inline]
pub(crate) fn new(expected: Annotated<U>) -> Self {
Self { expected }
}
}

impl<U, T> Assertion<T> for ToContainAssertion<U>
impl<U, T> Assertion<T> for ToContain<U>
where
T: IntoIterator<Item: PartialEq<U>>,
{
Expand Down
6 changes: 3 additions & 3 deletions src/assertions/iterators/assertions/to_contain_exactly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use crate::{

/// Asserts that the subject is equal to the given sequence.
#[derive(Clone, Debug)]
pub struct ToContainExactlyAssertion<I> {
pub struct ToContainExactly<I> {
expected: Annotated<I>,
}

impl<I> ToContainExactlyAssertion<I> {
impl<I> ToContainExactly<I> {
#[inline]
pub(crate) fn new(expected: Annotated<I>) -> Self {
Self { expected }
}
}

impl<I, T> Assertion<T> for ToContainExactlyAssertion<I>
impl<I, T> Assertion<T> for ToContainExactly<I>
where
I: IntoIterator,
T: IntoIterator<Item: PartialEq<I::Item>>,
Expand Down
12 changes: 6 additions & 6 deletions src/assertions/iterators/extensions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{assertions::AssertionBuilder, metadata::Annotated};

use super::{
AsUtf8Modifier, CountModifier, MergeModifier, MergeStrategy, NthModifier, ToContainAssertion,
ToContainExactlyAssertion,
AsUtf8Modifier, CountModifier, MergeModifier, MergeStrategy, NthModifier, ToContain,
ToContainExactly,
};

/// Assertions and modifiers for [Iterator]s.
Expand Down Expand Up @@ -155,11 +155,11 @@ where
/// expect!([1, 2, 3], to_contain(4));
/// ```
#[inline]
fn to_contain<U>(&self, expected: Annotated<U>) -> ToContainAssertion<U>
fn to_contain<U>(&self, expected: Annotated<U>) -> ToContain<U>
where
T::Item: PartialEq<U>,
{
ToContainAssertion::new(expected)
ToContain::new(expected)
}

/// Asserts that the subject is equal to the given sequence.
Expand All @@ -177,12 +177,12 @@ where
/// expect!([1, 2, 3], to_contain_exactly([3, 2, 1]));
/// ```
#[inline]
fn to_contain_exactly<I>(&self, expected: Annotated<I>) -> ToContainExactlyAssertion<I>
fn to_contain_exactly<I>(&self, expected: Annotated<I>) -> ToContainExactly<I>
where
I: IntoIterator,
T::Item: PartialEq<I::Item>,
{
ToContainExactlyAssertion::new(expected)
ToContainExactly::new(expected)
}
}

Expand Down
Loading

0 comments on commit 1d783e8

Please sign in to comment.