Skip to content

Commit

Permalink
Add Twice and Many assertion helper (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fs02 committed Oct 9, 2021
1 parent ba0f002 commit 171178c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
13 changes: 13 additions & 0 deletions assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,27 @@ type Assert struct {
optional bool
}

// Once set max calls to one time.
func (a *Assert) Once() {
a.Times(1)
}

// Twice set max calls to two times.
func (a *Assert) Twice() {
a.Times(2)
}

// Many set max calls to unlimited times.
func (a *Assert) Many() {
a.Times(0)
}

// Times set number of allowed calls.
func (a *Assert) Times(times int) {
a.repeatability = times
}

// Maybe allow calls to be skipped.
func (a *Assert) Maybe() {
a.optional = true
}
Expand Down
21 changes: 17 additions & 4 deletions assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestAssert_default(t *testing.T) {
assert.True(t, a.call(context.TODO()))
}

func TestAssert_once(t *testing.T) {
func TestAssert_Once(t *testing.T) {
var (
a = &Assert{}
)
Expand All @@ -49,12 +49,12 @@ func TestAssert_once(t *testing.T) {
assert.False(t, a.call(context.TODO()))
}

func TestAssert_times(t *testing.T) {
func TestAssert_Twice(t *testing.T) {
var (
a = &Assert{}
)

a.Times(2)
a.Twice()

assert.False(t, a.assert(nt, nil))
assert.True(t, a.call(context.TODO()))
Expand All @@ -64,7 +64,20 @@ func TestAssert_times(t *testing.T) {
assert.False(t, a.call(context.TODO()))
}

func TestAssert_maybe(t *testing.T) {
func TestAssert_Many(t *testing.T) {
var (
a = &Assert{}
)

a.Many()

assert.False(t, a.assert(nt, nil))
assert.True(t, a.call(context.TODO()))
assert.True(t, a.assert(nt, nil))
assert.True(t, a.call(context.TODO()))
}

func TestAssert_Maybe(t *testing.T) {
var (
a = &Assert{}
)
Expand Down

0 comments on commit 171178c

Please sign in to comment.