Skip to content

Commit c29de71

Browse files
ikravetsboyan-soubachov
authored andcommitted
add tests for correct msgAndArgs forwarding
len(msgAndArgs)>1 should lead to fmt.Sprintf()
1 parent f87e2b2 commit c29de71

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

assert/assertion_compare_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,21 @@ func Test_containsValue(t *testing.T) {
428428
Equal(t, currCase.result, compareResult)
429429
}
430430
}
431+
432+
func TestComparingMsgAndArgsForwarding(t *testing.T) {
433+
msgAndArgs := []interface{}{"format %s %x", "this", 0xc001}
434+
expectedOutput := "format this c001\n"
435+
funcs := []func(t TestingT){
436+
func(t TestingT) { Greater(t, 1, 2, msgAndArgs...) },
437+
func(t TestingT) { GreaterOrEqual(t, 1, 2, msgAndArgs...) },
438+
func(t TestingT) { Less(t, 2, 1, msgAndArgs...) },
439+
func(t TestingT) { LessOrEqual(t, 2, 1, msgAndArgs...) },
440+
func(t TestingT) { Positive(t, 0, msgAndArgs...) },
441+
func(t TestingT) { Negative(t, 0, msgAndArgs...) },
442+
}
443+
for _, f := range funcs {
444+
out := &outputT{buf: bytes.NewBuffer(nil)}
445+
f(out)
446+
Contains(t, out.buf.String(), expectedOutput)
447+
}
448+
}

assert/assertion_order_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,20 @@ func TestIsNonDecreasing(t *testing.T) {
184184
Contains(t, out.buf.String(), currCase.msg)
185185
}
186186
}
187+
188+
func TestOrderingMsgAndArgsForwarding(t *testing.T) {
189+
msgAndArgs := []interface{}{"format %s %x", "this", 0xc001}
190+
expectedOutput := "format this c001\n"
191+
collection := []int{1, 2, 1}
192+
funcs := []func(t TestingT){
193+
func(t TestingT) { IsIncreasing(t, collection, msgAndArgs...) },
194+
func(t TestingT) { IsNonIncreasing(t, collection, msgAndArgs...) },
195+
func(t TestingT) { IsDecreasing(t, collection, msgAndArgs...) },
196+
func(t TestingT) { IsNonDecreasing(t, collection, msgAndArgs...) },
197+
}
198+
for _, f := range funcs {
199+
out := &outputT{buf: bytes.NewBuffer(nil)}
200+
f(out)
201+
Contains(t, out.buf.String(), expectedOutput)
202+
}
203+
}

0 commit comments

Comments
 (0)