Open nrxus opened 3 years ago
custom closure was added: from_fn!
: https://github.com/nrxus/faux/commit/a209091037a58cb10b9452148a3bfb7a10340a74
It's unclear to me from the docs how to use custom matcher, particularly the any() matcher. I have the following method:
db_service.table.insert(itemA: &String, itemB: &String, itemC: &String)
I care about matching A, but not B or C (which are the results of hashing and random number generation respectively). I have tried this:
when!(db_servier.table.insert(itemA, matcher::any(), matcher::any())).then_return(Result::default());
But this generates multiple errors:
`impl ArgMatcher<_>` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
no implementation for `impl ArgMatcher<_> == impl ArgMatcher<_>`
the trait `Borrow<impl ArgMatcher<_>>` is not implemented for `&std::string::String`
If these matchers cannot be inlined inside when!
, how should they be implemented?
Ah! I tried explaining that in the docs but it looks like it was either confusing or hard to find.
For your specific use case, to ignore arguments you can use _
.
In the general case, argument matchers are either:
_
_ = {matcher}
. The "matcher" here is any expression that returns a matcher so it could be faux::any()
, or faux::pattern(/* some pattern to match against */)
, etc. Let me know how could I have worded or organized the docs better to make this information more accessible.
Ah. I was scouring the Matcher page and all its structs, traits, and functions. I think a mention on any one of them that the when macro encodes them differently would be enough, with a link to when's documentation would suffice.
Good call, I'll be explicit about the when
syntax on each matcher function, or at least link to it. Thanks!
@mbuscemi I have updated the docs to hopefully make it more clear for the future: https://docs.rs/faux/0.1.3/faux/matcher/fn.any.html
The only implemented matchers at the moment are:
Any
: matches any argumentEq
matches based onArg: PartialEq
EqAgainst
matches based onArg: PartialEq<Against>
We could implement other matchers so
faux
users don't have to handwrite their own matchers.Quick ideas:
<
<=
>
>=
!
||
&&
ArgMatcher
though.~We can first decide what matchers to create and then see if
when!
can come up with an easy to use syntax for it.cc: @muscovite