Skip to content

Commit

Permalink
stack: Add IsZero
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguystone committed Jan 25, 2024
1 parent 74117e7 commit 9433315
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions callstack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func GetSkip(skip int) Stack {
}
}

// IsZero determines if this stack is a zero-value
func (st Stack) IsZero() bool {
return len(st.s) == 0
}

// A shallow wrapper around [runtime.CallersFrames]
func (st Stack) CallersFrames() *runtime.Frames {
return runtime.CallersFrames(st.s)
Expand Down
5 changes: 4 additions & 1 deletion callstack/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ func TestStackIters(t *testing.T) {

func TestStackString(t *testing.T) {
c := check.NewT(t)
c.Equal(Stack{}.String(), "")

var stack Stack
c.True(stack.IsZero())
c.Equal(stack.String(), "")
}

func BenchmarkGet(b *testing.B) {
Expand Down

0 comments on commit 9433315

Please sign in to comment.