glob_prepare_replace_str.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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>, 2014
  7. This file is part of the Midnight Commander.
  8. The Midnight Commander is free software: you can redistribute it
  9. and/or modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation, either version 3 of the License,
  11. or (at your option) any later version.
  12. The Midnight Commander is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #define TEST_SUITE_NAME "lib/search/glob"
  20. #include "tests/mctest.h"
  21. #include "glob.c" // for testing static functions
  22. /* --------------------------------------------------------------------------------------------- */
  23. /* @DataSource("test_glob_prepare_replace_str_ds") */
  24. static const struct test_glob_prepare_replace_str_ds
  25. {
  26. const char *input_value;
  27. const char *glob_str;
  28. const char *replace_str;
  29. const char *expected_result;
  30. } test_glob_prepare_replace_str_ds[] = {
  31. {
  32. // 0.
  33. "qqwwee",
  34. "*ww*",
  35. "\\1AA\\2",
  36. "qqAAee",
  37. },
  38. {
  39. // 1.
  40. "qqwwee",
  41. "*qq*",
  42. "\\1SS\\2",
  43. "SSwwee",
  44. },
  45. {
  46. // 2.
  47. "qqwwee",
  48. "*ee*",
  49. "\\1RR\\2",
  50. "qqwwRR",
  51. },
  52. };
  53. /* @Test(dataSource = "test_glob_prepare_replace_str_ds") */
  54. START_PARAMETRIZED_TEST (test_glob_prepare_replace_str, test_glob_prepare_replace_str_ds)
  55. {
  56. // given
  57. mc_search_t *s;
  58. char *dest_str;
  59. s = mc_search_new (data->glob_str, NULL);
  60. s->is_case_sensitive = TRUE;
  61. s->search_type = MC_SEARCH_T_GLOB;
  62. // when
  63. mc_search_run (s, data->input_value, 0, strlen (data->input_value), NULL);
  64. dest_str = mc_search_prepare_replace_str2 (s, data->replace_str);
  65. // then
  66. mctest_assert_str_eq (dest_str, data->expected_result);
  67. g_free (dest_str);
  68. mc_search_free (s);
  69. }
  70. END_PARAMETRIZED_TEST
  71. /* --------------------------------------------------------------------------------------------- */
  72. int
  73. main (void)
  74. {
  75. TCase *tc_core;
  76. tc_core = tcase_create ("Core");
  77. // Add new tests here: ***************
  78. mctest_add_parameterized_test (tc_core, test_glob_prepare_replace_str,
  79. test_glob_prepare_replace_str_ds);
  80. // ***********************************
  81. return mctest_run_all (tc_core);
  82. }
  83. /* --------------------------------------------------------------------------------------------- */