aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/gotest.tools/internal/format/format.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-30 11:10:03 +0200
committerGitHub <noreply@github.com>2018-09-30 11:10:03 +0200
commitd71bb7dd7632780cf5aad5fda84027fa03a9d0f0 (patch)
treedba6c3c0bab18f41e21cd36a9fe05d1d27a574d4 /vendor/gotest.tools/internal/format/format.go
parent8fdd6bf99c111c3756056e87ffd9209875ac5c1f (diff)
parentbad9cda969b49bf1bce6799056476ac4684892df (diff)
downloadgit-bug-d71bb7dd7632780cf5aad5fda84027fa03a9d0f0.tar.gz
Merge pull request #54 from MichaelMure/editablecomment
Core support for editable comments
Diffstat (limited to 'vendor/gotest.tools/internal/format/format.go')
-rw-r--r--vendor/gotest.tools/internal/format/format.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/vendor/gotest.tools/internal/format/format.go b/vendor/gotest.tools/internal/format/format.go
new file mode 100644
index 00000000..8f6494f9
--- /dev/null
+++ b/vendor/gotest.tools/internal/format/format.go
@@ -0,0 +1,27 @@
+package format // import "gotest.tools/internal/format"
+
+import "fmt"
+
+// Message accepts a msgAndArgs varargs and formats it using fmt.Sprintf
+func Message(msgAndArgs ...interface{}) string {
+ switch len(msgAndArgs) {
+ case 0:
+ return ""
+ case 1:
+ return fmt.Sprintf("%v", msgAndArgs[0])
+ default:
+ return fmt.Sprintf(msgAndArgs[0].(string), msgAndArgs[1:]...)
+ }
+}
+
+// WithCustomMessage accepts one or two messages and formats them appropriately
+func WithCustomMessage(source string, msgAndArgs ...interface{}) string {
+ custom := Message(msgAndArgs...)
+ switch {
+ case custom == "":
+ return source
+ case source == "":
+ return custom
+ }
+ return fmt.Sprintf("%s: %s", source, custom)
+}