From c29de713426fdf9068696c483705fdbb24a815ac Mon Sep 17 00:00:00 2001 From: Ilia Kravets Date: Thu, 20 Jan 2022 11:25:52 +0200 Subject: [PATCH] add tests for correct msgAndArgs forwarding len(msgAndArgs)>1 should lead to fmt.Sprintf() --- assert/assertion_compare_test.go | 18 ++++++++++++++++++ assert/assertion_order_test.go | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/assert/assertion_compare_test.go b/assert/assertion_compare_test.go index 6f7db87c8..667dbf7c4 100644 --- a/assert/assertion_compare_test.go +++ b/assert/assertion_compare_test.go @@ -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) + } +} diff --git a/assert/assertion_order_test.go b/assert/assertion_order_test.go index 7726b82f9..eefe06127 100644 --- a/assert/assertion_order_test.go +++ b/assert/assertion_order_test.go @@ -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) + } +}