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

Commit

Permalink
Merge pull request #2 from maurofran/develop
Browse files Browse the repository at this point in the history
fix: fixed as description
  • Loading branch information
maurofran authored Apr 6, 2022
2 parents b606aba + bb6c77e commit 32265cd
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 32265cd

Please sign in to comment.