add tests for correct msgAndArgs forwarding

len(msgAndArgs)>1 should lead to fmt.Sprintf()
pull/1157/head
Ilia Kravets 2022-01-20 11:25:52 +02:00 committed by Boyan Soubachov
parent f87e2b2119
commit c29de71342
2 changed files with 35 additions and 0 deletions

View File

@ -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)
}
}

View File

@ -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)
}
}