akshayjshah / attest

Type-safe assertion helpers for Go
https://pkg.go.dev/go.akshayshah.org/attest
MIT License
15 stars 2 forks source link

attest.StrContains #6

Closed komuw closed 2 years ago

komuw commented 2 years ago

I find myself wanting to use attest.Contains but then I remember that what I have is a string and not a slice.

So I end up doing; attest.True(t, strings.Contains("some-str", "some-other"))

https://github.com/komuw/ong/blob/2a6145e85fc3227def1173610fe554bc54096270/log/log_test.go#L143-L144

komuw commented 2 years ago

This will be similar to the same func like;

https://pkg.go.dev/github.com/go-quicktest/qt#StringContains

akshayjshah commented 2 years ago

I agree that it'd be nice to have something for this, but I'd really prefer not to have separate versions for string and []byte. Maybe rename Contains to SliceContains and make the new Contains accept either string or []byte arguments?

komuw commented 2 years ago

that sounds like a good plan.

akshayjshah commented 2 years ago

Added Subsequence in v0.4.0, which should address this for any type whose underlying type is string or []byte.

akshayjshah commented 2 years ago

Also, thanks for the really thoughtful issues you're filing @komuw 😍