diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2019-05-20 18:53:17 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2019-05-20 18:53:17 +0300 |
commit | a92e3f4e3ae25044336a0fa38c2c4d33291ae0d0 (patch) | |
tree | 761803cdd9976acec5b86c7bc484efadf576b6df | |
parent | 5fc48076a3d8037b0f9677ae0c88d5a75c33689f (diff) |
Add test for text.ChompBytes
-rw-r--r-- | internal/helper/text/chomp_test.go | 29 |
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)) + }) + } +} |