Skip to content

Commit

Permalink
Fix tests in @assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Mar 9, 2024
1 parent ad0d7c8 commit 61fa01f
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions assertion/assertion.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ pub fn assert_eq[T : Debug + Eq](a : T, b : T) -> Result[Unit, String] {
}
}

test "assert_eq.eq" {
match assert_eq(1, 1) {
Ok(_) => ()
Err(msg) => return Err("unexpected failure: \(msg)")
}
}

test "assert_eq.ne" {
match assert_eq(1, 2) {
Ok(_) => return Err("unexpected success")
Err(_) => ()
}
}

pub fn assert_ne[T : Debug + Eq](a : T, b : T) -> Result[Unit, String] {
if a != b {
Ok(())
Expand All @@ -41,6 +55,17 @@ pub fn assert_ne[T : Debug + Eq](a : T, b : T) -> Result[Unit, String] {
}
}

test "assert_ne.ne" {
assert_eq(assert_ne(1, 2), Ok(()))?
}

test "assert_ne.eq" {
match assert_ne(1, 1) {
Ok(_) => return Err("unexpected success")
Err(_) => ()
}
}

pub fn assert_false(x : Bool) -> Result[Unit, String] {
if x == false {
Ok(())
Expand All @@ -49,6 +74,14 @@ pub fn assert_false(x : Bool) -> Result[Unit, String] {
}
}

test "assert_false.false" {
assert_eq(assert_false(false), Ok(()))?
}

test "assert_false.true" {
assert_ne(assert_false(true), Ok(()))?
}

pub fn assert_true(x : Bool) -> Result[Unit, String] {
if x {
Ok(())
Expand All @@ -58,14 +91,9 @@ pub fn assert_true(x : Bool) -> Result[Unit, String] {
}

test "assert_true.true" {
assert_true(true)?
assert_eq(assert_true(true), Ok(()))?
}

test "assert_false.false" {
assert_false(false)?
}

test "assert_eq.eq" {
assert_eq(1, 1)?
assert_eq("123", "123")?
test "assert_true.false" {
assert_ne(assert_true(false), Ok(()))?
}

0 comments on commit 61fa01f

Please sign in to comment.