From a0e59da629d3b25280fada12201b9e9728441efc Mon Sep 17 00:00:00 2001 From: Matthias Diester Date: Tue, 13 Oct 2020 15:08:23 +0200 Subject: [PATCH] Fix print-issue for non-strings 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 --- print.go | 6 ++++-- print_test.go | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/print.go b/print.go index 2b0a81c..ec2b8b5 100644 --- a/print.go +++ b/print.go @@ -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 } } diff --git a/print_test.go b/print_test.go index fec0085..ba15d6f 100644 --- a/print_test.go +++ b/print_test.go @@ -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 }) @@ -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]")) + }) }) })