assert-rs / predicates-rs

Boolean-valued predicate functions in Rust
docs.rs/predicates
Apache License 2.0
173 stars 29 forks source link

feat: Add str::contains_all function #147

Open Techassi opened 1 year ago

Techassi commented 1 year ago

This PR adds the str::contains_all predicate function. It allows one to check if the input contains all provided needles.

use predicates::prelude::*;

let predicate_fn = predicate::str::contains_all(vec!["One", "Two", "Three"]);

assert_eq!(true, predicate_fn.eval("One Two Three"));
assert_eq!(false, predicate_fn.eval("One Two Four"));
assert_eq!(false, predicate_fn.eval("Four Five Six"));
mre commented 1 year ago

In your example, shouldn't it be a vec with multiple strings as predicates, or am I misunderstanding something?

let predicate_fn = predicate::str::contains_all(vec!["One", "Two", "Three"]);
Techassi commented 1 year ago

You are absolutely correct. I somehow forgot to add the commas.

EDIT: I added the commas in my comment above and in the doc test in 45d4a17.

epage commented 1 year ago

If we move forward with this, can you squash your commits?

Techassi commented 1 year ago

Yes, I can do that once we are ready with this PR.

epage commented 1 year ago

Yes, I can do that once we are ready with this PR.

The downside to that is it requires an extra ping-pong between us to get this in, causing more context switches, and being fairly easy to fall through the cracks

Techassi commented 1 year ago

The downside to that is it requires an extra ping-pong between us to get this in, causing more context switches, and being fairly easy to fall through the cracks

Can't we just use squash-merge? Then GitHub would do the heavy lifting for us :)

epage commented 1 year ago

Can't we just use squash-merge? Then GitHub would do the heavy lifting for us :)

Not the most ideal experience and I don't like blindly squashing PRs but only doing it as a last resort because we should preserve multiple commits when they are relevant.

Techassi commented 1 year ago

I now squashed all previous commits (Adding the function, updating the docs, and merging changes from main).

I will now continue to work on the unresolved conversations above.