You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util_tests.cxx 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*-
  2. * Copyright 2023 Vsevolod Stakhov
  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. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "util.hxx"
  17. #define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
  18. #include "doctest/doctest.h"
  19. using namespace rspamd;
  20. using namespace std::literals::string_view_literals;
  21. TEST_SUITE("cxx utils") {
  22. TEST_CASE("string_split_on") {
  23. std::tuple<std::string_view, char, std::pair<std::string_view, std::string_view>> cases[] = {
  24. {"test test"sv, ' ', std::pair{"test"sv, "test"sv}},
  25. {"test test"sv, ' ', std::pair{"test"sv, "test"sv}},
  26. {"test test "sv, ' ', std::pair{"test"sv, "test "sv}},
  27. {"testtest "sv, ' ', std::pair{"testtest"sv, ""sv}},
  28. {" testtest "sv, ' ', std::pair{""sv, "testtest "sv}},
  29. {"testtest"sv, ' ', std::pair{"testtest"sv, ""sv}},
  30. {""sv, ' ', std::pair{""sv, ""sv}},
  31. };
  32. for (const auto& c : cases) {
  33. auto res = string_split_on(std::get<0>(c), std::get<1>(c));
  34. auto expected = std::get<2>(c);
  35. CHECK(res.first == expected.first);
  36. CHECK(res.second == expected.second);
  37. }
  38. }
  39. }