From bb6c77e17e9e081ce0b618398225aafa8d5a96f1 Mon Sep 17 00:00:00 2001 From: Mauro Franceschini Date: Wed, 6 Apr 2022 17:09:58 +0200 Subject: [PATCH] fix: fixed as description --- described/as.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/described/as.go b/described/as.go index e104864..6282ed1 100644 --- a/described/as.go +++ b/described/as.go @@ -4,7 +4,6 @@ import ( "github.com/maurofran/hamcrest4go/matcher" "regexp" "strconv" - "strings" ) var argPattern = regexp.MustCompile("%([0-9]+)") @@ -29,15 +28,13 @@ func (a as[T]) Matches(value T) bool { } func (a as[T]) DescribeTo(description matcher.Description) { - parts := argPattern.Split(a.template, -1) - for _, part := range parts { - if strings.HasPrefix(part, "%") { - idx, _ := strconv.Atoi(part[1:]) - description.AppendValue(a.args[idx]) - } else { - description.AppendText(part) - } - } + result := argPattern.ReplaceAllStringFunc(a.template, func(s string) string { + idx, _ := strconv.Atoi(s) + description := matcher.StringDescription() + description.AppendValue(a.args[idx]) + return description.String() + }) + description.AppendText(result) } func (a as[T]) DescribeMismatch(actual T, description matcher.Description) {