translate_replace_glob_to_regex.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. libmc - checks for processing esc sequences in replace string
  3. Copyright (C) 2011-2019
  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. int number_failed;
  71. Suite *s = suite_create (TEST_SUITE_NAME);
  72. TCase *tc_core = tcase_create ("Core");
  73. SRunner *sr;
  74. /* Add new tests here: *************** */
  75. mctest_add_parameterized_test (tc_core, test_translate_replace_glob_to_regex,
  76. test_translate_replace_glob_to_regex_ds);
  77. /* *********************************** */
  78. suite_add_tcase (s, tc_core);
  79. sr = srunner_create (s);
  80. srunner_set_log (sr, "translate_replace_glob_to_regex.log");
  81. srunner_run_all (sr, CK_ENV);
  82. number_failed = srunner_ntests_failed (sr);
  83. srunner_free (sr);
  84. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  85. }
  86. /* --------------------------------------------------------------------------------------------- */