This is an automated email from the ASF dual-hosted git repository.

willholley pushed a commit to branch mango-beginswith
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/mango-beginswith by this push:
     new db49e3e80 add text eunit tests
db49e3e80 is described below

commit db49e3e80aa62cae25ca3a176166a14e734848bc
Author: Will Holley <[email protected]>
AuthorDate: Wed Oct 18 13:04:44 2023 +0000

    add text eunit tests
---
 src/mango/src/mango_selector_text.erl | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/mango/src/mango_selector_text.erl 
b/src/mango/src/mango_selector_text.erl
index fc9280d85..6ba4221a8 100644
--- a/src/mango/src/mango_selector_text.erl
+++ b/src/mango/src/mango_selector_text.erl
@@ -142,8 +142,9 @@ convert(Path, {[{<<"$exists">>, ShouldExist}]}) ->
         true -> FieldExists;
         false -> {op_not, {FieldExists, false}}
     end;
-convert(Path, {[{<<"$beginsWith">>, Arg}]}) ->
-    PrefixSearch = [value_str(Arg), <<"*">>],
+convert(Path, {[{<<"$beginsWith">>, Arg}]}) when is_binary(Arg) ->
+    Suffix = <<"*">>,
+    PrefixSearch = value_str(<<Arg/binary,  Suffix/binary>>),
     {op_field, {make_field(Path, Arg), PrefixSearch}};
 % We're not checking the actual type here, just looking for
 % anything that has a possibility of matching by checking
@@ -824,6 +825,12 @@ convert_nor_test() ->
         })
     ).
 
+convert_beginswith_test() ->
+    ?assertEqual(
+        {op_field, {[[<<"field">>], <<":">>, <<"string">>],<<"\"foo\\*\"">>}},
+        convert_selector(#{<<"field">> => #{<<"$beginsWith">> => <<"foo">>}})
+    ).
+
 to_query_test() ->
     F = fun(S) -> iolist_to_binary(to_query(S)) end,
     Input = {<<"name">>, <<"value">>},

Reply via email to