Open quii opened 3 months ago
Given a struct like this
type Page struct { Title string Body string Description string Private bool Template string }
It would be rad if you could go generate matchers, and it should be possible as it's pretty boilerplate
go generate
func HasTemplate(expected string) Matcher[*cms.Page] { return func(got *cms.Page) MatchResult { return MatchResult{ Description: "has template " + expected, Matches: got.Template == expected, But: "it was " + got.Template, } } } func IsPrivate() Matcher[*cms.Page] { return func(got *cms.Page) MatchResult { return MatchResult{ Description: "is private", Matches: got.Private, But: "it was not private", } } } func HaveBody(expected string) Matcher[*cms.Page] { return func(got *cms.Page) MatchResult { return MatchResult{ Description: "have body " + expected, Matches: got.Body == expected, But: "it was " + got.Body, } } } func HaveDescription(expected string) Matcher[*cms.Page] { return func(got *cms.Page) MatchResult { return MatchResult{ Description: "have description " + expected, Matches: got.Description == expected, But: "it was " + got.Description, } } } func HaveTitle(expected string) Matcher[*cms.Page] { return func(got *cms.Page) MatchResult { return MatchResult{ Description: "have title " + expected, Matches: got.Title == expected, But: "it was " + got.Title, } } }
That said, magic AI made all of these for me, so 🤷
Given a struct like this
It would be rad if you could
go generate
matchers, and it should be possible as it's pretty boilerplate