Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
fix: fixed as description
Browse files Browse the repository at this point in the history
  • Loading branch information
maurofran committed Apr 6, 2022
1 parent 0ca449f commit bb6c77e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions described/as.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/maurofran/hamcrest4go/matcher"
"regexp"
"strconv"
"strings"
)

var argPattern = regexp.MustCompile("%([0-9]+)")
Expand All @@ -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) {
Expand Down

0 comments on commit bb6c77e

Please sign in to comment.