2 libmc - checks for processing esc sequences in replace string
5 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software: you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation, either version 3 of the License,
15 or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #define TEST_SUITE_NAME "lib/search/regex"
32 #include "regex.c" /* for testing static functions*/
34 /* --------------------------------------------------------------------------------------------- */
35 #define test_helper_valid_data(from, etalon, dest_str, replace_flags, utf) { \
36 dest_str = g_string_new(""); \
37 mc_search_regex__process_escape_sequence (dest_str, from, -1, &replace_flags, utf); \
38 fail_if (strcmp(dest_str->str, etalon), "dest_str(%s) != %s", dest_str->str, etalon); \
39 g_string_free(dest_str, TRUE); \
42 /* --------------------------------------------------------------------------------------------- */
44 START_TEST (test_regex_process_escape_sequence_valid
)
47 replace_transform_type_t replace_flags
= REPLACE_T_NO_TRANSFORM
;
49 test_helper_valid_data("{101}", "A", dest_str
, replace_flags
, FALSE
);
50 test_helper_valid_data("x42", "B", dest_str
, replace_flags
, FALSE
);
51 test_helper_valid_data("x{444}", "D", dest_str
, replace_flags
, FALSE
);
52 test_helper_valid_data("x{444}", "ф", dest_str
, replace_flags
, TRUE
);
54 test_helper_valid_data("n", "\n", dest_str
, replace_flags
, FALSE
);
55 test_helper_valid_data("t", "\t", dest_str
, replace_flags
, FALSE
);
56 test_helper_valid_data("v", "\v", dest_str
, replace_flags
, FALSE
);
57 test_helper_valid_data("b", "\b", dest_str
, replace_flags
, FALSE
);
58 test_helper_valid_data("r", "\r", dest_str
, replace_flags
, FALSE
);
59 test_helper_valid_data("f", "\f", dest_str
, replace_flags
, FALSE
);
60 test_helper_valid_data("a", "\a", dest_str
, replace_flags
, FALSE
);
64 /* --------------------------------------------------------------------------------------------- */
71 Suite
*s
= suite_create (TEST_SUITE_NAME
);
72 TCase
*tc_core
= tcase_create ("Core");
75 /* Add new tests here: *************** */
76 tcase_add_test (tc_core
, test_regex_process_escape_sequence_valid
);
77 /* *********************************** */
79 suite_add_tcase (s
, tc_core
);
80 sr
= srunner_create (s
);
81 srunner_run_all (sr
, CK_NORMAL
);
82 number_failed
= srunner_ntests_failed (sr
);
84 return (number_failed
== 0) ? 0 : 1;
87 /* --------------------------------------------------------------------------------------------- */