Skip to content

Commit

Permalink
add tests for correct msgAndArgs forwarding
Browse files Browse the repository at this point in the history
len(msgAndArgs)>1 should lead to fmt.Sprintf()
  • Loading branch information
ikravets authored and boyan-soubachov committed Feb 10, 2022
1 parent f87e2b2 commit c29de71
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions assert/assertion_compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,21 @@ func Test_containsValue(t *testing.T) {
Equal(t, currCase.result, compareResult)
}
}

func TestComparingMsgAndArgsForwarding(t *testing.T) {
msgAndArgs := []interface{}{"format %s %x", "this", 0xc001}
expectedOutput := "format this c001\n"
funcs := []func(t TestingT){
func(t TestingT) { Greater(t, 1, 2, msgAndArgs...) },
func(t TestingT) { GreaterOrEqual(t, 1, 2, msgAndArgs...) },
func(t TestingT) { Less(t, 2, 1, msgAndArgs...) },
func(t TestingT) { LessOrEqual(t, 2, 1, msgAndArgs...) },
func(t TestingT) { Positive(t, 0, msgAndArgs...) },
func(t TestingT) { Negative(t, 0, msgAndArgs...) },
}
for _, f := range funcs {
out := &outputT{buf: bytes.NewBuffer(nil)}
f(out)
Contains(t, out.buf.String(), expectedOutput)
}
}
17 changes: 17 additions & 0 deletions assert/assertion_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,20 @@ func TestIsNonDecreasing(t *testing.T) {
Contains(t, out.buf.String(), currCase.msg)
}
}

func TestOrderingMsgAndArgsForwarding(t *testing.T) {
msgAndArgs := []interface{}{"format %s %x", "this", 0xc001}
expectedOutput := "format this c001\n"
collection := []int{1, 2, 1}
funcs := []func(t TestingT){
func(t TestingT) { IsIncreasing(t, collection, msgAndArgs...) },
func(t TestingT) { IsNonIncreasing(t, collection, msgAndArgs...) },
func(t TestingT) { IsDecreasing(t, collection, msgAndArgs...) },
func(t TestingT) { IsNonDecreasing(t, collection, msgAndArgs...) },
}
for _, f := range funcs {
out := &outputT{buf: bytes.NewBuffer(nil)}
f(out)
Contains(t, out.buf.String(), expectedOutput)
}
}

0 comments on commit c29de71

Please sign in to comment.