...

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

Documentation: gotest.tools/v3/internal/format

     1  package format // import "gotest.tools/v3/internal/format"
     2  
     3  import "fmt"
     4  
     5  // Message accepts a msgAndArgs varargs and formats it using fmt.Sprintf
     6  func Message(msgAndArgs ...interface{}) string {
     7  	switch len(msgAndArgs) {
     8  	case 0:
     9  		return ""
    10  	case 1:
    11  		return fmt.Sprintf("%v", msgAndArgs[0])
    12  	default:
    13  		return fmt.Sprintf(msgAndArgs[0].(string), msgAndArgs[1:]...)
    14  	}
    15  }
    16  
    17  // WithCustomMessage accepts one or two messages and formats them appropriately
    18  func WithCustomMessage(source string, msgAndArgs ...interface{}) string {
    19  	custom := Message(msgAndArgs...)
    20  	switch {
    21  	case custom == "":
    22  		return source
    23  	case source == "":
    24  		return custom
    25  	}
    26  	return fmt.Sprintf("%s: %s", source, custom)
    27  }
    28  

View as plain text