glob_prepare_replace_str.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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>, 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 <http://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. /* *INDENT-OFF* */
  25. static const struct test_glob_prepare_replace_str_ds
  26. {
  27. const char *input_value;
  28. const char *glob_str;
  29. const char *replace_str;
  30. const char *expected_result;
  31. } test_glob_prepare_replace_str_ds[] =
  32. {
  33. { /* 0. */
  34. "qqwwee",
  35. "*ww*",
  36. "\\1AA\\2",
  37. "qqAAee"
  38. },
  39. { /* 1. */
  40. "qqwwee",
  41. "*qq*",
  42. "\\1SS\\2",
  43. "SSwwee"
  44. },
  45. { /* 2. */
  46. "qqwwee",
  47. "*ee*",
  48. "\\1RR\\2",
  49. "qqwwRR"
  50. }
  51. };
  52. /* *INDENT-ON* */
  53. /* @Test(dataSource = "test_glob_prepare_replace_str_ds") */
  54. /* *INDENT-OFF* */
  55. START_PARAMETRIZED_TEST (test_glob_prepare_replace_str, test_glob_prepare_replace_str_ds)
  56. /* *INDENT-ON* */
  57. {
  58. /* given */
  59. mc_search_t *s;
  60. char *dest_str;
  61. s = mc_search_new (data->glob_str, NULL);
  62. s->is_case_sensitive = TRUE;
  63. s->search_type = MC_SEARCH_T_GLOB;
  64. /* when */
  65. mc_search_run (s, data->input_value, 0, strlen (data->input_value), NULL);
  66. dest_str = mc_search_prepare_replace_str2 (s, (char *) data->replace_str);
  67. /* then */
  68. mctest_assert_str_eq (dest_str, data->expected_result);
  69. g_free (dest_str);
  70. mc_search_free (s);
  71. }
  72. /* *INDENT-OFF* */
  73. END_PARAMETRIZED_TEST
  74. /* *INDENT-ON* */
  75. /* --------------------------------------------------------------------------------------------- */
  76. int
  77. main (void)
  78. {
  79. int number_failed;
  80. Suite *s = suite_create (TEST_SUITE_NAME);
  81. TCase *tc_core = tcase_create ("Core");
  82. SRunner *sr;
  83. /* Add new tests here: *************** */
  84. mctest_add_parameterized_test (tc_core, test_glob_prepare_replace_str,
  85. test_glob_prepare_replace_str_ds);
  86. /* *********************************** */
  87. suite_add_tcase (s, tc_core);
  88. sr = srunner_create (s);
  89. srunner_set_log (sr, "glob_prepare_replace_str.log");
  90. srunner_run_all (sr, CK_ENV);
  91. number_failed = srunner_ntests_failed (sr);
  92. srunner_free (sr);
  93. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  94. }
  95. /* --------------------------------------------------------------------------------------------- */