Skip to content

Commit

Permalink
Fix tests in @assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix authored and Yoorkin committed Mar 11, 2024
1 parent c830f0c commit 97e51de
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 @@ -28,6 +28,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 @@ -38,6 +52,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 @@ -46,6 +71,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 @@ -55,14 +88,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 97e51de

Please sign in to comment.