regex_process_escape_sequence.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. Slava Zanko <slavazanko@gmail.com>, 2011, 2013
  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/regex"
  20. #include "tests/mctest.h"
  21. #include "regex.c" /* for testing static functions */
  22. /* --------------------------------------------------------------------------------------------- */
  23. /* @DataSource("test_regex_process_escape_sequence_ds") */
  24. /* *INDENT-OFF* */
  25. static const struct test_regex_process_escape_sequence_ds
  26. {
  27. const char *input_from;
  28. const replace_transform_type_t input_initial_flags;
  29. const gboolean input_use_utf;
  30. const char *expected_string;
  31. } test_regex_process_escape_sequence_ds[] =
  32. {
  33. { /* 0. */
  34. "{101}",
  35. REPLACE_T_NO_TRANSFORM,
  36. FALSE,
  37. "A"
  38. },
  39. { /* 1. */
  40. "x42",
  41. REPLACE_T_NO_TRANSFORM,
  42. FALSE,
  43. "B"
  44. },
  45. { /* 2. */
  46. "x{444}",
  47. REPLACE_T_NO_TRANSFORM,
  48. FALSE,
  49. "D"
  50. },
  51. { /* 3. */
  52. "x{444}",
  53. REPLACE_T_NO_TRANSFORM,
  54. TRUE,
  55. "ф"
  56. },
  57. { /* 4. */
  58. "n",
  59. REPLACE_T_NO_TRANSFORM,
  60. FALSE,
  61. "\n"
  62. },
  63. { /* 5. */
  64. "t",
  65. REPLACE_T_NO_TRANSFORM,
  66. FALSE,
  67. "\t"
  68. },
  69. { /* 6. */
  70. "v",
  71. REPLACE_T_NO_TRANSFORM,
  72. FALSE,
  73. "\v"
  74. },
  75. { /* 7. */
  76. "b",
  77. REPLACE_T_NO_TRANSFORM,
  78. FALSE,
  79. "\b"
  80. },
  81. { /* 8. */
  82. "r",
  83. REPLACE_T_NO_TRANSFORM,
  84. FALSE,
  85. "\r"
  86. },
  87. { /* 9. */
  88. "f",
  89. REPLACE_T_NO_TRANSFORM,
  90. FALSE,
  91. "\f"
  92. },
  93. { /* 10. */
  94. "a",
  95. REPLACE_T_NO_TRANSFORM,
  96. FALSE,
  97. "\a"
  98. },
  99. };
  100. /* *INDENT-ON* */
  101. /* @Test(dataSource = "test_regex_process_escape_sequence_ds") */
  102. /* *INDENT-OFF* */
  103. START_PARAMETRIZED_TEST (test_regex_process_escape_sequence, test_regex_process_escape_sequence_ds)
  104. /* *INDENT-ON* */
  105. {
  106. /* given */
  107. GString *actual_string;
  108. replace_transform_type_t replace_flags = REPLACE_T_NO_TRANSFORM;
  109. replace_flags = data->input_initial_flags;
  110. actual_string = g_string_new ("");
  111. /* when */
  112. mc_search_regex__process_escape_sequence (actual_string, data->input_from, -1, &replace_flags,
  113. data->input_use_utf);
  114. /* then */
  115. mctest_assert_str_eq (actual_string->str, data->expected_string);
  116. g_string_free (actual_string, TRUE);
  117. }
  118. /* *INDENT-OFF* */
  119. END_PARAMETRIZED_TEST
  120. /* *INDENT-ON* */
  121. /* --------------------------------------------------------------------------------------------- */
  122. int
  123. main (void)
  124. {
  125. TCase *tc_core;
  126. tc_core = tcase_create ("Core");
  127. /* Add new tests here: *************** */
  128. mctest_add_parameterized_test (tc_core, test_regex_process_escape_sequence,
  129. test_regex_process_escape_sequence_ds);
  130. /* *********************************** */
  131. return mctest_run_all (tc_core);
  132. }
  133. /* --------------------------------------------------------------------------------------------- */