Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests in @assertion #32

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(()))?
}