emqx_redis_command_SUITE.erl 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %% http://www.apache.org/licenses/LICENSE-2.0
  8. %%
  9. %% Unless required by applicable law or agreed to in writing, software
  10. %% distributed under the License is distributed on an "AS IS" BASIS,
  11. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. %% See the License for the specific language governing permissions and
  13. %% limitations under the License.
  14. %%--------------------------------------------------------------------
  15. -module(emqx_redis_command_SUITE).
  16. -compile(nowarn_export_all).
  17. -compile(export_all).
  18. -include_lib("eunit/include/eunit.hrl").
  19. all() ->
  20. emqx_common_test_helpers:all(?MODULE).
  21. t_split_ok(_Config) ->
  22. ?assertEqual(
  23. {ok, [<<"ab">>, <<"cd">>, <<"ef">>]},
  24. emqx_redis_command:split(<<" \"ab\" 'cd' ef ">>)
  25. ),
  26. ?assertEqual(
  27. {ok, [<<"ab">>, <<"cd">>, <<"ef">>]},
  28. emqx_redis_command:split(<<" ab\tcd ef">>)
  29. ),
  30. ?assertEqual(
  31. {ok, [<<"abc'd">>, <<"ef">>]},
  32. emqx_redis_command:split(<<"ab\"c'd\" ef">>)
  33. ),
  34. ?assertEqual(
  35. {ok, [<<"abc\"d">>, <<"ef">>]},
  36. emqx_redis_command:split(<<"ab'c\"d' ef">>)
  37. ),
  38. ?assertEqual(
  39. {ok, [<<"IJK">>, <<"\\x49\\x4a\\x4B">>]},
  40. emqx_redis_command:split(<<"\"\\x49\\x4a\\x4B\" \\x49\\x4a\\x4B">>)
  41. ),
  42. ?assertEqual(
  43. {ok, [<<"x\t\n\r\b\v">>]},
  44. emqx_redis_command:split(<<"\"\\x\\t\\n\\r\\b\\a\"">>)
  45. ),
  46. ?assertEqual(
  47. {ok, [<<"abc\'d">>, <<"ef">>]},
  48. emqx_redis_command:split(<<"'abc\\'d' ef">>)
  49. ),
  50. ?assertEqual(
  51. {ok, [<<>>, <<>>]},
  52. emqx_redis_command:split(<<" '' \"\" ">>)
  53. ).
  54. t_split_error(_Config) ->
  55. ?assertEqual(
  56. {error, trailing_after_quote},
  57. emqx_redis_command:split(<<"\"a\"b">>)
  58. ),
  59. ?assertEqual(
  60. {error, unterminated_quote},
  61. emqx_redis_command:split(<<"\"ab">>)
  62. ),
  63. ?assertEqual(
  64. {error, trailing_after_single_quote},
  65. emqx_redis_command:split(<<"'a'b'c">>)
  66. ),
  67. ?assertEqual(
  68. {error, unterminated_single_quote},
  69. emqx_redis_command:split(<<"'ab">>)
  70. ).