willowtreeapps / assertk

assertions for kotlin inspired by assertj
MIT License
760 stars 85 forks source link

New assertion: `containsMatch` #452

Closed JakeWharton closed 1 year ago

JakeWharton commented 1 year ago

A mixture of contains and match, but only looks for a match within the string rather than against the whole thing.

Implementation is basically matchesPredicate(regex::containsMatchIn), but it's nice to not have to do that every time you want to switch from an exact contains to a fuzzy, regex-based one (or similarly, from matching the whole string to only part of a string).

evant commented 1 year ago

You could also change your matching regex to match the whole thing but yeah I could see how this could be simpler.

JakeWharton commented 1 year ago

I did that first but weirdly couldn't make it work. Something with MULTILINE option maybe? I very quickly landed at matchesPredicate and didn't look much further.

evant commented 1 year ago

Ah yeah multiline regex can get weird