...

Source file src/gotest.tools/v3/internal/format/format_test.go

Documentation: gotest.tools/v3/internal/format

     1  package format_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gotest.tools/v3/assert"
     7  	"gotest.tools/v3/internal/format"
     8  )
     9  
    10  func TestMessage(t *testing.T) {
    11  	var testcases = []struct {
    12  		doc      string
    13  		args     []interface{}
    14  		expected string
    15  	}{
    16  		{
    17  			doc: "none",
    18  		},
    19  		{
    20  			doc:      "single string",
    21  			args:     args("foo"),
    22  			expected: "foo",
    23  		},
    24  		{
    25  			doc:      "single non-string",
    26  			args:     args(123),
    27  			expected: "123",
    28  		},
    29  		{
    30  			doc:      "format string and args",
    31  			args:     args("%s %v", "a", 3),
    32  			expected: "a 3",
    33  		},
    34  	}
    35  
    36  	for _, tc := range testcases {
    37  		t.Run(tc.doc, func(t *testing.T) {
    38  			assert.Equal(t, format.Message(tc.args...), tc.expected)
    39  		})
    40  	}
    41  }
    42  
    43  func args(a ...interface{}) []interface{} {
    44  	return a
    45  }
    46  
    47  func TestWithCustomMessage(t *testing.T) {
    48  	t.Run("only custom", func(t *testing.T) {
    49  		msg := format.WithCustomMessage("", "extra")
    50  		assert.Equal(t, msg, "extra")
    51  	})
    52  
    53  	t.Run("only source", func(t *testing.T) {
    54  		msg := format.WithCustomMessage("source")
    55  		assert.Equal(t, msg, "source")
    56  	})
    57  
    58  	t.Run("source and custom", func(t *testing.T) {
    59  		msg := format.WithCustomMessage("source", "extra")
    60  		assert.Equal(t, msg, "source: extra")
    61  	})
    62  }
    63  

View as plain text