willowtreeapps / assertk

assertions for kotlin inspired by assertj
MIT License
757 stars 84 forks source link

add map assertion doesNotContainKey #502

Closed nukeforum closed 8 months ago

nukeforum commented 9 months ago

Just adding a convenience assertion Map::doesNotContainKey. While existing assertions on Map can achieve the same functionality, having to pass an arbitrary value in addition to the key to be checked is overhead this PR endeavors to eliminate.

jzbrooks commented 8 months ago

In the same way that isNull is a terminal assertion while isNotNull is both an assertion and transformation, doesNotContainKey is a terminal assertion while key is an assertion and transformation.

JakeWharton commented 8 months ago

I would not expect this to be a terminal operation. It operates on the contents of the map which does not preclude additional assertions on it.

nukeforum commented 8 months ago

... which does not preclude additional assertions on it.

@JakeWharton Isn't that what the .all {} extension is for? I'm actually pretty new to assertK, so I could use some context to understand your feedback. 🙏

JakeWharton commented 8 months ago

Sorry yeah you're right. I've been working on a different testing library in Rust and it's been screwing up my knowledge of AssertK now multiple times today 🤦‍♂️

evant commented 8 months ago

yeah, https://github.com/willowtreeapps/assertk/discussions/346

evant commented 8 months ago

This does make me wonder if it's worth renaming key() to containsKey(), would make it more clear it's an assertion itself, but maybe it makes it slightly less clear that chaining targets the specific value, kinda 50/50 on it.