diff options
author | Anthony HAMON <anthony.hamon@iadvize.com> | 2018-08-19 08:51:37 +0200 |
---|---|---|
committer | Anthony HAMON <anthony.hamon@iadvize.com> | 2018-08-19 10:37:03 +0200 |
commit | f91b4067f43af957d2bac7fc7ba7374751dd13e8 (patch) | |
tree | 5c20acdfdc0d048322b3228d67ed10c8da707b5b /pkg/utils | |
parent | 81b07daa01244b7f0326adeba2a5429516f2d85d (diff) |
add test to utils package
Diffstat (limited to 'pkg/utils')
-rw-r--r-- | pkg/utils/utils_test.go | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go new file mode 100644 index 000000000..6531d50ff --- /dev/null +++ b/pkg/utils/utils_test.go @@ -0,0 +1,87 @@ +package utils + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestSplitLines(t *testing.T) { + type scenario struct { + multilineString string + expected []string + } + + scenarios := []scenario{ + { + "", + []string{}, + }, + { + "\n", + []string{}, + }, + { + "hello world !\nhello universe !\n", + []string{ + "hello world !", + "hello universe !", + }, + }, + } + + for _, s := range scenarios { + assert.EqualValues(t, s.expected, SplitLines(s.multilineString)) + } +} + +func TestWithPadding(t *testing.T) { + type scenario struct { + str string + padding int + expected string + } + + scenarios := []scenario{ + { + "hello world !", + 1, + "hello world !", + }, + { + "hello world !", + 14, + "hello world ! ", + }, + } + + for _, s := range scenarios { + assert.EqualValues(t, s.expected, WithPadding(s.str, s.padding)) + } +} + +func TestCurrentRepoName(t *testing.T) { + assert.EqualValues(t, "utils", GetCurrentRepoName()) +} + +func TestTrimTrailingNewline(t *testing.T) { + type scenario struct { + str string + expected string + } + + scenarios := []scenario{ + { + "hello world !\n", + "hello world !", + }, + { + "hello world !", + "hello world !", + }, + } + + for _, s := range scenarios { + assert.EqualValues(t, s.expected, TrimTrailingNewline(s.str)) + } +} |