translate_replace_glob_to_regex.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. libmc - checks for processing esc sequences in replace string
  3. Copyright (C) 2011-2024
  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 <http://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. /* *INDENT-OFF* */
  26. static const struct test_translate_replace_glob_to_regex_ds
  27. {
  28. const char *input_value;
  29. const char *expected_result;
  30. } test_translate_replace_glob_to_regex_ds[] =
  31. {
  32. {
  33. "a&a?a",
  34. "a\\&a\\1a"
  35. },
  36. {
  37. "a\\&a?a",
  38. "a\\&a\\1a"
  39. },
  40. {
  41. "a&a\\?a",
  42. "a\\&a\\?a"
  43. },
  44. {
  45. "a\\&a\\?a",
  46. "a\\&a\\?a"
  47. },
  48. };
  49. /* *INDENT-ON* */
  50. /* @Test(dataSource = "test_translate_replace_glob_to_regex_ds") */
  51. /* *INDENT-OFF* */
  52. START_PARAMETRIZED_TEST (test_translate_replace_glob_to_regex, test_translate_replace_glob_to_regex_ds)
  53. /* *INDENT-ON* */
  54. {
  55. /* given */
  56. GString *dest_str;
  57. /* when */
  58. dest_str = mc_search__translate_replace_glob_to_regex (data->input_value);
  59. /* then */
  60. mctest_assert_str_eq (dest_str->str, data->expected_result);
  61. g_string_free (dest_str, TRUE);
  62. }
  63. /* *INDENT-OFF* */
  64. END_PARAMETRIZED_TEST
  65. /* *INDENT-ON* */
  66. /* --------------------------------------------------------------------------------------------- */
  67. int
  68. main (void)
  69. {
  70. TCase *tc_core;
  71. tc_core = tcase_create ("Core");
  72. /* Add new tests here: *************** */
  73. mctest_add_parameterized_test (tc_core, test_translate_replace_glob_to_regex,
  74. test_translate_replace_glob_to_regex_ds);
  75. /* *********************************** */
  76. return mctest_run_all (tc_core);
  77. }
  78. /* --------------------------------------------------------------------------------------------- */