regex_process_escape_sequence.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. libmc - checks for processing esc sequences in replace string
  3. Copyright (C) 2011
  4. The Free Software Foundation, Inc.
  5. Written by:
  6. Slava Zanko <slavazanko@gmail.com>, 2011
  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 <config.h>
  21. #include <check.h>
  22. #include "regex.c" /* for testing static functions*/
  23. /* --------------------------------------------------------------------------------------------- */
  24. #define test_helper_valid_data(from, etalon, dest_str, replace_flags, utf) { \
  25. dest_str = g_string_new(""); \
  26. mc_search_regex__process_escape_sequence (dest_str, from, -1, &replace_flags, utf); \
  27. fail_if (strcmp(dest_str->str, etalon), "dest_str(%s) != %s", dest_str->str, etalon); \
  28. g_string_free(dest_str, TRUE); \
  29. }
  30. /* --------------------------------------------------------------------------------------------- */
  31. START_TEST (test_regex_process_escape_sequence_valid)
  32. {
  33. GString *dest_str;
  34. replace_transform_type_t replace_flags = REPLACE_T_NO_TRANSFORM;
  35. test_helper_valid_data("{101}", "A", dest_str, replace_flags, FALSE);
  36. test_helper_valid_data("x42", "B", dest_str, replace_flags, FALSE);
  37. test_helper_valid_data("x{444}", "D", dest_str, replace_flags, FALSE);
  38. test_helper_valid_data("x{444}", "ф", dest_str, replace_flags, TRUE);
  39. test_helper_valid_data("n", "\n", dest_str, replace_flags, FALSE);
  40. test_helper_valid_data("t", "\t", dest_str, replace_flags, FALSE);
  41. test_helper_valid_data("v", "\v", dest_str, replace_flags, FALSE);
  42. test_helper_valid_data("b", "\b", dest_str, replace_flags, FALSE);
  43. test_helper_valid_data("r", "\r", dest_str, replace_flags, FALSE);
  44. test_helper_valid_data("f", "\f", dest_str, replace_flags, FALSE);
  45. test_helper_valid_data("a", "\a", dest_str, replace_flags, FALSE);
  46. }
  47. END_TEST
  48. /* --------------------------------------------------------------------------------------------- */
  49. int
  50. main (void)
  51. {
  52. int number_failed;
  53. Suite *s = suite_create (TEST_SUITE_NAME);
  54. TCase *tc_core = tcase_create ("Core");
  55. SRunner *sr;
  56. /* Add new tests here: *************** */
  57. tcase_add_test (tc_core, test_regex_process_escape_sequence_valid);
  58. /* *********************************** */
  59. suite_add_tcase (s, tc_core);
  60. sr = srunner_create (s);
  61. srunner_run_all (sr, CK_NORMAL);
  62. number_failed = srunner_ntests_failed (sr);
  63. srunner_free (sr);
  64. return (number_failed == 0) ? 0 : 1;
  65. }
  66. /* --------------------------------------------------------------------------------------------- */