Skip to content

Commit

Permalink
add Assertf
Browse files Browse the repository at this point in the history
  • Loading branch information
mkideal committed Aug 28, 2024
1 parent 9bf5689 commit 0e13aee
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion op/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,19 @@ func Assert(cond bool, msgs ...any) {
if !cond {
msg := "assertion failed"
if len(msgs) > 0 {
msg += ": " + fmt.Sprint(msgs)
msg = fmt.Sprint(msgs)

Check failure on line 169 in op/op.go

View workflow job for this annotation

GitHub Actions / build

missing ... in args forwarded to print-like function
}
panic(msg)
}
}

// Assertf panics with a formatted message if cond is false.
func Assertf(cond bool, format string, args ...any) {
if !cond {
panic(fmt.Sprintf(format, args...))
}
}

// ReverseCompare returns a comparison function that reverses the order of the original comparison function.
func ReverseCompare[T any](cmp func(T, T) int) func(T, T) int {
return func(x, y T) int {
Expand Down

0 comments on commit 0e13aee

Please sign in to comment.