glob_translate_to_regex.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. libmc - checks for processing esc sequences in replace string
  3. Copyright (C) 2011-2021
  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_glob_translate_to_regex_ds") */
  25. /* *INDENT-OFF* */
  26. static const struct test_glob_translate_to_regex_ds
  27. {
  28. const char *input_value;
  29. const char *expected_result;
  30. } test_glob_translate_to_regex_ds[] =
  31. {
  32. {
  33. "test*",
  34. "test(.*)"
  35. },
  36. {
  37. "t?es*t",
  38. "t(.)es(.*)t"
  39. },
  40. {
  41. "te{st}",
  42. "te(st)"
  43. },
  44. {
  45. "te{st|ts}",
  46. "te(st|ts)"
  47. },
  48. {
  49. "te{st,ts}",
  50. "te(st|ts)"
  51. },
  52. {
  53. "te[st]",
  54. "te[st]"
  55. },
  56. {
  57. "t,e.st",
  58. "t,e\\.st"
  59. },
  60. {
  61. "^t,e.+st+$",
  62. "\\^t,e\\.\\+st\\+\\$"
  63. },
  64. {
  65. "te!@#$%^&*()_+|\";:'{}:><?\\?\\*.,/[]|\\/st",
  66. "te!@#\\$%\\^&(.*)\\(\\)_\\+|\";:'():><(.)\\?\\*\\.,/[]|\\/st"
  67. },
  68. };
  69. /* *INDENT-ON* */
  70. /* @Test(dataSource = "test_glob_translate_to_regex_ds") */
  71. /* *INDENT-OFF* */
  72. START_PARAMETRIZED_TEST (test_glob_translate_to_regex, test_glob_translate_to_regex_ds)
  73. /* *INDENT-ON* */
  74. {
  75. /* given */
  76. GString *tmp = g_string_new (data->input_value);
  77. GString *dest_str;
  78. /* when */
  79. dest_str = mc_search__glob_translate_to_regex (tmp);
  80. /* then */
  81. g_string_free (tmp, TRUE);
  82. mctest_assert_str_eq (dest_str->str, data->expected_result);
  83. g_string_free (dest_str, TRUE);
  84. }
  85. /* *INDENT-OFF* */
  86. END_PARAMETRIZED_TEST
  87. /* *INDENT-ON* */
  88. /* --------------------------------------------------------------------------------------------- */
  89. int
  90. main (void)
  91. {
  92. TCase *tc_core;
  93. tc_core = tcase_create ("Core");
  94. /* Add new tests here: *************** */
  95. mctest_add_parameterized_test (tc_core, test_glob_translate_to_regex,
  96. test_glob_translate_to_regex_ds);
  97. /* *********************************** */
  98. return mctest_run_all (tc_core);
  99. }
  100. /* --------------------------------------------------------------------------------------------- */