Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2019-05-20 18:53:17 +0300
committerJohn Cai <jcai@gitlab.com>2019-05-20 18:53:17 +0300
commita92e3f4e3ae25044336a0fa38c2c4d33291ae0d0 (patch)
tree761803cdd9976acec5b86c7bc484efadf576b6df
parent5fc48076a3d8037b0f9677ae0c88d5a75c33689f (diff)
Add test for text.ChompBytes
-rw-r--r--internal/helper/text/chomp_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/helper/text/chomp_test.go b/internal/helper/text/chomp_test.go
new file mode 100644
index 000000000..fbdb1ecbc
--- /dev/null
+++ b/internal/helper/text/chomp_test.go
@@ -0,0 +1,29 @@
+package text
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestChompBytes(t *testing.T) {
+ testCases := []struct {
+ desc string
+ in []byte
+ out string
+ }{
+ {desc: "no space, trailing newline", in: []byte("hello world\n"), out: "hello world"},
+ {desc: "space, trailing newline", in: []byte(" hello world \n"), out: " hello world "},
+ {desc: "no space, no trailing newline", in: []byte("hello world"), out: "hello world"},
+ {desc: "space, no trailing newline", in: []byte(" hello world "), out: " hello world "},
+ {desc: "double newline", in: []byte(" hello world \n\n"), out: " hello world \n"},
+ {desc: "empty slice", in: []byte{}, out: ""},
+ {desc: "nil slice", in: nil, out: ""},
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.desc, func(t *testing.T) {
+ require.Equal(t, tc.out, ChompBytes(tc.in))
+ })
+ }
+}