-
Notifications
You must be signed in to change notification settings - Fork 21
Output satisfies predicate? #55
Comments
Currently, we only support exact matches and substring matches. The idea is welcome. In #20, we talk about regex matches and Your suggestion for the name is fn all_lowercase(output: &str) -> bool {
...
}
...
.stdout().satisfies(all_lowercase)
.unwrap(); I don't (yet?) have much in the way of opinions on the name. Is there any kind of precedence that we should be consistent with? |
The std lib has an abstraction like that. I think it was Pattern, in str or
something like that.
Ed Page <[email protected]> schrieb am Mo. 16. Okt. 2017 um 20:05:
… Currently, we only support exact matches and substring matches.
The idea is welcome. In #20
<#20>, we talk about regex
matches and fn matches. For an fn, we either need to Box it or have a
state-less pointer.
Your suggestion for the name is satisfies. In the API, this would look
like
fn all_lowercase(output: &str) -> bool {
...
}
...
.stdout().satisfies(all_lowercase)
.unwrap();
I don't (yet?) have much in the way of opinions on the name. Is there any
kind of precedence that we should be consistent with?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#55 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABOX6XmhTW5JEkgHd3RN-QTdh60w3GUks5ss4zjgaJpZM4P66Ki>
.
|
Could it be something like this? It changes the code style, but I think that the Or ditch this plan altogether, cause closures are not very pleasant to work with. 😉 |
A lot of the value is the rich error reporting, we need to be sure to preserve that. While this might not need Debug/Clone, I still hesitate when not supporting such basic traits. Until someone has a use case for it, we could avoid unifying the code branches and have a stateless function pointer rather than a stateful one in a |
I restored the error reporting and restored the Debug/Clone trait implementations. Currently I use a I also implemented the functions that I mentioned before (although only (Compare changes: https://github.com/killercup/assert_cli/compare/master...dsprenkels:predicates?expand=1) |
Huh, somehow lost my post
I was thinking of a function pointer rather than a function trait unless there is a use case where we need the trait instead.
Yes please, it'll provide a better forum for talking about the code. Also, maybe I'm just being crotchety but I'm somewhat preferring the enum approach rather than unifying everything behind a boxed Fn trait. Thoughts? |
btw my current thought on what this API could look like
|
This accepts a message with it. This should hit the 90% case of a `satisfies_ok` (or whatever it'd be called). I'm also assuming that it'll be a best practice to document the custom predicates, so its acceptable to force it on everyone. If a `satisfies_ok` is found to be needed, I'm assuming its because the user wants to tie into existing machinery that has error reporting. This means we'll probably need to accept an `Fn` that `Box`es the error to preserve it. Fixes assert-rs#55
Thanks for this awesome library!
I would like to check if the command's output is from a specific format. I am specifically dealing with formats like this:
with the first byte being a counted integer, and the rest random. So I would like to check if the binary lengths are correct and if the first byte is
01, 02, ...
.Is it possible to pass a function to a
OutputAssertionBuilder
method which allows me to check by predicate?If not, I would like to propose one (
OutputAssertionBuilder::satisfy
), which you can call with a function which checks if the string satisfies a given predicate.Example type signature:
The text was updated successfully, but these errors were encountered: