Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
fix(print): remove bug with trimming trailing new line in multi line …
Browse files Browse the repository at this point in the history
…text (#19)
  • Loading branch information
kenske authored and dmlittle committed Mar 25, 2019
1 parent 4d13c29 commit 6798ec9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.vscode/
tsconfig.json
jsconfig.json
.idea

### Go ###
# Binaries for programs and plugins
Expand Down
4 changes: 1 addition & 3 deletions pkg/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ func formatValue(value string, indentLength int) string {

formattedValue := strings.Replace(value, "\n", newlineReplacement, -1)

lastNewlineIndex := strings.LastIndex(formattedValue, "\n")

return formattedValue[:lastNewlineIndex]
return formattedValue
}

return value
Expand Down
16 changes: 16 additions & 0 deletions pkg/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,19 @@ func captureOutput(f func()) string {
writer.Close()
return <-out
}

func TestPrint(t *testing.T) {
t.Run("parses simple plans", func(tt *testing.T) {
input := "this:\n is:\n an:\n - example"

expected := "this:\n" +
" is:\n" +
" an:\n" +
" - example"

value := formatValue(input, 1)

assert.Equal(tt, expected, value)
})

}

0 comments on commit 6798ec9

Please sign in to comment.