Skip to content

Commit

Permalink
Merge pull request #87 from myyrakle/feat/#86
Browse files Browse the repository at this point in the history
[#86] assert 함수 정의 변경
  • Loading branch information
myyrakle authored Nov 2, 2023
2 parents 50cb9f4 + 8152bc5 commit e51a39f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gost

![](https://img.shields.io/badge/language-Go-00ADD8) ![](https://img.shields.io/badge/version-v0.8.0-brightgreen) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
![](https://img.shields.io/badge/language-Go-00ADD8) ![](https://img.shields.io/badge/version-v0.8.1-brightgreen) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)

![](./etc/gorris.jpg)

Expand All @@ -11,7 +11,7 @@ Experience the true taste of Rust in Go
## Install

```
go get github.com/myyrakle/[email protected].0
go get github.com/myyrakle/[email protected].1
```

## Example
Expand Down
30 changes: 24 additions & 6 deletions panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,45 @@ func Panic(message String, args ...any) {
// Asserts that a boolean expression is true at runtime.
//
// gost.Assert(true, "This is true")
func Assert(condition Bool, message String, args ...any) {
func Assert(condition Bool, args ...any) {
if !condition {
panic(Format(message, args...))
if len(args) > 0 {
if message, ok := args[0].(String); ok {
panic(Format(message, args...))
}
}

panic(Format("assertion failed"))
}
}

// Asserts that two expressions are equal to each other
//
// gost.AssertEq(1, 1, "These are equal")
func AssertEq[T Eq[T]](lhs T, rhs T, message String, args ...any) {
func AssertEq[T Eq[T]](lhs T, rhs T, args ...any) {
if !lhs.Eq(rhs) {
panic(Format(message, args...))
if len(args) > 0 {
if message, ok := args[0].(String); ok {
panic(Format(message, args...))
}
}

panic(Format("assertion failed: {} != {}", lhs, rhs))
}
}

// Asserts that two expressions are not equal to each other
//
// gost.AssertNe(1, 2, "These are not equal")
func AssertNe[T Eq[T]](lhs T, rhs T, message String, args ...any) {
func AssertNe[T Eq[T]](lhs T, rhs T, args ...any) {
if lhs.Eq(rhs) {
panic(Format(message, args...))
if len(args) > 0 {
if message, ok := args[0].(String); ok {
panic(Format(message, args...))
}
}

panic(Format("assertion failed: {} == {}", lhs, rhs))
}
}

Expand Down

0 comments on commit e51a39f

Please sign in to comment.