smoothy 0.10.0

Write smooth assertions in a fluent and human readable way
Documentation
use crate::{implementation, private, Asserter};

/// Specifies various assertions on values that can be converted to a boolean. Implemented on
/// [`Asserter`]
///
/// This trait is sealed and cannot be implemented outside Smoothy.
pub trait BooleanAssertion<IntoBoolean>: private::Sealed
where
    IntoBoolean: Into<bool>,
{
    /// Convenience method for asserting that a value is true
    ///
    /// # Examples
    /// ```
    /// # use smoothy::prelude::*;
    /// #
    /// assert_that(true).is_true();
    /// ```
    ///
    /// ```should_panic
    /// # use smoothy::prelude::*;
    /// #
    /// assert_that(false).is_true();
    /// ```
    ///
    /// # Panics
    /// When the value is false
    #[track_caller]
    #[allow(clippy::wrong_self_convention)]
    fn is_true(self);

    /// Convenience method for asserting that a value is false
    ///
    /// # Examples
    /// ```
    /// # use smoothy::prelude::*;
    /// #
    /// assert_that(false).is_false();
    /// ```
    ///
    /// ```should_panic
    /// # use smoothy::prelude::*;
    /// #
    /// assert_that(true).is_false();
    /// ```
    ///
    /// # Panics
    /// When the value is true
    #[track_caller]
    #[allow(clippy::wrong_self_convention)]
    fn is_false(self);
}

impl<IntoBoolean> BooleanAssertion<IntoBoolean> for Asserter<IntoBoolean>
where
    IntoBoolean: Into<bool>,
{
    fn is_true(self) {
        let actual = self.value.into();

        implementation::assert(actual, actual, "to be", true);
    }

    fn is_false(self) {
        let actual = self.value.into();

        implementation::assert(!actual, actual, "to be", false);
    }
}