summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-08-20 09:24:54 +1000
committerGitHub <noreply@github.com>2018-08-20 09:24:54 +1000
commit65c5a6014b11a5115a2c4a3570d7232ad833dd6d (patch)
tree43eef4ca9c4ed35189e27254541536f9d2b1c64c /pkg
parente6712832b502bf893d11d0c891f5ab1b69242fec (diff)
parentfc126a1718ec9a6133352b87920d95ee12730936 (diff)
Merge pull request #185 from antham/add-tests
Add test to utils package
Diffstat (limited to 'pkg')
-rw-r--r--pkg/utils/utils_test.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go
new file mode 100644
index 000000000..58e78cce9
--- /dev/null
+++ b/pkg/utils/utils_test.go
@@ -0,0 +1,83 @@
+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 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))
+ }
+}