Skip to content

Commit

Permalink
Merge pull request #268 from keitwb/patch-1
Browse files Browse the repository at this point in the history
strings.Indent should not indent when width is 0
  • Loading branch information
hairyhenderson authored Mar 3, 2018
2 parents 1ea5214 + 062b1b5 commit b3c245c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions strings/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import "strings"

// Indent - indent each line of the string with the given indent string
func Indent(width int, indent, s string) string {
if width == 0 {
return s
}
if width > 1 {
indent = strings.Repeat(indent, width)
}
Expand Down
1 change: 1 addition & 0 deletions strings/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
func TestIndent(t *testing.T) {
actual := "hello\nworld\n!"
expected := " hello\n world\n !"
assert.Equal(t, actual, Indent(0, " ", actual))
assert.Equal(t, expected, Indent(1, " ", actual))
assert.Equal(t, "\n", Indent(1, " ", "\n"))
assert.Equal(t, " foo\n", Indent(1, " ", "foo\n"))
Expand Down

0 comments on commit b3c245c

Please sign in to comment.