Skip to content

Commit

Permalink
Fix print-issue for non-strings
Browse files Browse the repository at this point in the history
Fixes #37

Whenever a non string was used in the print functions, a `nil` was
returned rather than the actual input.

Add default switch case to pipe through all non-strings as-is.

Signed-off-by: Stephan Auf Der Landwehr <[email protected]>
  • Loading branch information
HeavyWombat committed Oct 13, 2020
1 parent 194c6ae commit a0e59da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions print.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import (
func evaluateInputs(in ...interface{}) []interface{} {
result := make([]interface{}, len(in))
for i, x := range in {
switch str := x.(type) {
switch obj := x.(type) {
case string:
result[i] = evaluateString(str)
result[i] = evaluateString(obj)
default:
result[i] = obj
}
}

Expand Down
8 changes: 7 additions & 1 deletion print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ var _ = Describe("print functions", func() {
})
})

Context("weird use cases", func() {
Context("weird use cases and issues", func() {
BeforeEach(func() {
ColorSetting = ON
})
Expand All @@ -150,5 +150,11 @@ var _ = Describe("print functions", func() {
Expect(Sprint("ok", "\x1b[38;2;1;2mnot ok\x1b[0m")).To(
BeEquivalentTo("ok\x1b[38;2;1;2mnot ok\x1b[0m"))
})
It("should not fail writing simple types", func() {
Expect(Sprint(42)).To(Equal("42"))
})
It("should not fail writing slices", func() {
Expect(Sprint([]int{42, 1})).To(Equal("[42 1]"))
})
})
})

0 comments on commit a0e59da

Please sign in to comment.