translate_replace_glob_to_regex.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. libmc - checks for processing esc sequences in replace string
  3. Copyright (C) 2011-2025
  4. Free Software Foundation, Inc.
  5. Written by:
  6. Andrew Borodin <aborodin@vmail.ru>, 2011
  7. Slava Zanko <slavazanko@gmail.com>, 2013
  8. This file is part of the Midnight Commander.
  9. The Midnight Commander is free software: you can redistribute it
  10. and/or modify it under the terms of the GNU General Public License as
  11. published by the Free Software Foundation, either version 3 of the License,
  12. or (at your option) any later version.
  13. The Midnight Commander is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. #define TEST_SUITE_NAME "lib/search/glob"
  21. #include "tests/mctest.h"
  22. #include "glob.c" // for testing static functions
  23. /* --------------------------------------------------------------------------------------------- */
  24. /* @DataSource("test_translate_replace_glob_to_regex_ds") */
  25. static const struct test_translate_replace_glob_to_regex_ds
  26. {
  27. const char *input_value;
  28. const char *expected_result;
  29. } test_translate_replace_glob_to_regex_ds[] = {
  30. { "a&a?a", "a\\&a\\1a" },
  31. { "a\\&a?a", "a\\&a\\1a" },
  32. { "a&a\\?a", "a\\&a\\?a" },
  33. { "a\\&a\\?a", "a\\&a\\?a" },
  34. };
  35. /* @Test(dataSource = "test_translate_replace_glob_to_regex_ds") */
  36. START_PARAMETRIZED_TEST (test_translate_replace_glob_to_regex,
  37. test_translate_replace_glob_to_regex_ds)
  38. {
  39. // given
  40. GString *dest_str;
  41. // when
  42. dest_str = mc_search__translate_replace_glob_to_regex (data->input_value);
  43. // then
  44. mctest_assert_str_eq (dest_str->str, data->expected_result);
  45. g_string_free (dest_str, TRUE);
  46. }
  47. END_PARAMETRIZED_TEST
  48. /* --------------------------------------------------------------------------------------------- */
  49. int
  50. main (void)
  51. {
  52. TCase *tc_core;
  53. tc_core = tcase_create ("Core");
  54. // Add new tests here: ***************
  55. mctest_add_parameterized_test (tc_core, test_translate_replace_glob_to_regex,
  56. test_translate_replace_glob_to_regex_ds);
  57. // ***********************************
  58. return mctest_run_all (tc_core);
  59. }
  60. /* --------------------------------------------------------------------------------------------- */