nickva commented on code in PR #4810:
URL: https://github.com/apache/couchdb/pull/4810#discussion_r1364096728
##########
src/mango/src/mango_selector.erl:
##########
@@ -1054,4 +1061,29 @@ fields_nor_test() ->
},
?assertEqual([<<"field1">>, <<"field2">>], fields_of(Selector2)).
+match_beginswith_test() ->
+ Doc =
+ {[
+ {<<"_id">>, <<"foo">>},
+ {<<"_rev">>, <<"bar">>},
+ {<<"user_id">>, 11}
+ ]},
+ Check = fun(Field, Prefix) ->
Review Comment:
The eunit test suite vs test vs generated test (a fun) is quite confusing.
It's usually simpler to use basic test functions. For a suite, the
setup/teardown with `?TDEF/?TDEF_FE` can work well.
Since we have two tests, it could be simpler to have a helper check function
like @pgj suggested. The Doc it could be defined in a macro like ?TEST_DOC or
re-defined inside the check match helper function, whichever looks better.
Then, tests can just be a list of simple asserts:
```erlang
match_demo_test() ->
?assert(check_match({[{<<"user_id">>, 11}]} , ?TEST_DOC))),
?assertNot(check_match({[{<<"user_id">>, 1234}]}, ?TEST_DOC))),
...
```
So it looks like a simple function. If it fails on an assert we should get
the exact line number and the expression where it fails.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]