assertables-rust-crate
assertables-rust-crate copied to clipboard
More types of assertions?
I am wondering if adding more types of assertions would be useful/beneficial to this project? I would really like to have things like
assert_none!(option) // ensures the option type is empty
assert_some_eq!(option, val) // ensures the option is inhabited and contains val
assert_ok!(result) // ensures the result is OK
assert_err_is!(result, errtype) // ensures the result is the expected error
assert_len!(seq, n) // ensures the sequence or object has n elements
I'm happy to implement and submit a PR if this would be useful!
I am wondering if adding more types of assertions would be useful/beneficial to this project?
Yes please.
I would really like to have things like...
All sound good.
Yes please for merge requests.
Heads up that the existing implementation macros are significantly long. Each macro group is its own file, and comes with variations to use a message parameter or not, as well as typical cargo tests, and cargo doc comments that are tests, and corresponding links in the README. I speculate that there may be better ways to arrange things, or do a meta-macro, or some such-- any ideas of yours will be good to know.
I will take a stab and see what I can come up with. I'll let you know if I run into issues!
Completed these:
- assert_ok etc.
- assert_err etc.
- assert_some etc.
- assert_none
- assert_ready etc.
- assert_pending
I have assert_len on the roadmap.
Thanks!
inserting asset type is assert of number being within range, but less of other number:
assert_lt_by!(9,10,2); // success
assert_lt_by!(7,10,2); // panics
similar to check number withing some delta/epsilon, but directional.
usage of existing delta/epsilon requires manual calculation of midpoints which is a lot of noise.
Are you saying something like this?
assert_lt_by!(a, b, c) => (b - a) < c
If so, what do you think of the word "delta" because it can make it more clear?
assert_delta_lt!(a, b, c) => (b - a) < c
If b - a under flows like (1u64 - 2u64), what would be panic? Ideally should assert with description, rather than underflow (that why I cannot write it as is easy - need sugar).
I am fine with any naming, most important is easy to grasp explanation imho. I wrote such methods before, were very useful. Just lost them all time moving from project to project.
Yes you're right. There will need to be a checked delta and it will need to returns a flow error.
I'll do it. E.t.a. 1-2 weeks.
Update for you...
The new macros assert_diff are ready on the main branch if you want to see them:
https://github.com/SixArm/assertables-rust-crate/tree/main/src/assert_diff
The macros assert_abs_diff are now updated with overflow detection:
https://github.com/SixArm/assertables-rust-crate/tree/main/src/assert_abs_diff
I intend to test and release this weekend.
Released. When convenient, can you upgrade to version 9.5.0, and try the new macros assert_diff_eq_x and assert_abs_diff_eq_x and let me know if they work the way you want?