Skip to content

Commit

Permalink
CRF: add doc string
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix authored and Yoorkin committed Mar 11, 2024
1 parent c27fc5a commit c20bae1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions assertion/assertion.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ test "assert_true.false" {
assert_ne(assert_true(false), Ok(()))?
}

/// Assert referential equality of two values.
///
/// Returns Ok if the two arguments are the same object by reference, using the
/// `===` operator; raises an Error otherwise. Certain objects may be equal by
/// value, but they are different objects in the memory. This function checks
/// the latter.
///
/// # Examples
///
/// ```
/// let a = "4" + "2"
/// let b = "4" + "2"
/// assert_is(a, a)? // this is okay
/// assert_is(a, b)? // yields an error
/// ```
pub fn assert_is[T : Debug](a : T, b : T) -> Result[Unit, String] {
if a === b {
Ok(())
Expand All @@ -119,6 +134,21 @@ test "assert_is.is.not" {
assert_ne(assert_is(s1, s2), Ok(()))?
}

/// Assert referential inequality of two values.
///
/// Returns Ok if the two arguments are NOT the same object by reference, using
/// the `===` operator; raises an Error otherwise. Certain objects may be equal
/// by value, but they are different objects in the memory. This function
/// checks the latter.
///
/// # Examples
///
/// ```
/// let a = "4" + "2"
/// let b = "4" + "2"
/// assert_is_not(a, b)? // this is okay
/// assert_is_not(a, a)? // yields an error
/// ```
pub fn assert_is_not[T : Debug](a : T, b : T) -> Result[Unit, String] {
if not(a === b) {
Ok(())
Expand Down

0 comments on commit c20bae1

Please sign in to comment.