Skip to content

Commit

Permalink
Process error case for processTextAnnotations
Browse files Browse the repository at this point in the history
The error of function `processTextAnnotations` was never evaluated.

Add if case to panic in case `processTextAnnotations` has an error.
  • Loading branch information
HeavyWombat committed Oct 12, 2020
1 parent 5ed170d commit 31e0ce9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion convenience.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ func Foreground(color colorful.Color) StyleOption {
func EnableTextAnnotations() StyleOption {
return StyleOption{
postProcess: func(s *String, flags map[string]struct{}) {
processTextAnnotations(s)
if err := processTextAnnotations(s); err != nil {
panic(err)
}
},
}
}
Expand Down
6 changes: 6 additions & 0 deletions convenience_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ var _ = Describe("convenience functions", func() {
}).To(Panic())
})

It("should panic in case a non-existing color", func() {
Expect(func() {
Style("Foobar{test}", EnableTextAnnotations())
}).To(Panic())
})

It("should correctly apply a color to a string that already contains text emphasis", func() {
text := Sprintf("text with *bold* and _italic_.")
Expect(Style(text, Foreground(Orange))).To(
Expand Down

0 comments on commit 31e0ce9

Please sign in to comment.