2 libmc - checks for processing esc sequences in replace string
4 Copyright (C) 2011-2024
5 Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011, 2013
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"
28 #include "tests/mctest.h"
30 #include "regex.c" /* for testing static functions */
32 /* --------------------------------------------------------------------------------------------- */
33 #define test_helper_check_valid_data( a, b, c, d, e, f ) \
35 ck_assert_msg (a == b, "ret_value != %s", (b) ? "TRUE": "FALSE"); \
36 ck_assert_msg (c == d, "skip_len(%d) != %d", c, d); \
38 ck_assert_msg (e == f, "ret(%d) != %d", e, f); \
41 #define test_helper_handle_esc_seq( pos, r, skip, flag ) \
44 test_helper_check_valid_data(\
45 mc_search_regex__replace_handle_esc_seq( replace_str, pos, &skip_len, &ret ), r,\
51 /* --------------------------------------------------------------------------------------------- */
53 /* @DataSource("test_regex_replace_esc_seq_prepare_ds") */
55 static const struct test_regex_replace_esc_seq_prepare_ds
57 const char *input_string
;
58 const size_t input_pos
;
60 const gboolean expected_result
;
61 const gsize expected_skipped_len
;
62 const int expected_flags
;
63 } test_regex_replace_esc_seq_prepare_ds
[] =
66 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
70 REPLACE_PREPARE_T_ESCAPE_SEQ
73 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
77 REPLACE_PREPARE_T_ESCAPE_SEQ
79 { /* 2. \\x{456abcd} */
80 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
84 REPLACE_PREPARE_T_ESCAPE_SEQ
87 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
91 REPLACE_PREPARE_T_NOTHING_SPECIAL
94 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
98 REPLACE_PREPARE_T_ESCAPE_SEQ
101 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
105 REPLACE_PREPARE_T_ESCAPE_SEQ
108 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
112 REPLACE_PREPARE_T_ESCAPE_SEQ
115 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
119 REPLACE_PREPARE_T_ESCAPE_SEQ
122 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
126 REPLACE_PREPARE_T_ESCAPE_SEQ
129 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
133 REPLACE_PREPARE_T_ESCAPE_SEQ
136 "bla-bla\\{123}bla-bla\\xabc234 bla-bla\\x{456abcd}bla-bla\\xtre\\n\\t\\v\\b\\r\\f\\a",
140 REPLACE_PREPARE_T_ESCAPE_SEQ
143 "\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
147 REPLACE_PREPARE_T_NOTHING_SPECIAL
149 { /* 12. \\x{qwerty} */
150 "\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
154 REPLACE_PREPARE_T_NOTHING_SPECIAL
157 "\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
163 { /* 14. \\x{456a-bcd} */
164 "\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
168 REPLACE_PREPARE_T_NOTHING_SPECIAL
171 "\\{123 \\x{qwerty} \\12} \\x{456a-bcd}bla-bla\\satre",
180 /* @Test(dataSource = "test_regex_replace_esc_seq_prepare_ds") */
182 START_PARAMETRIZED_TEST (test_regex_replace_esc_seq_prepare
, test_regex_replace_esc_seq_prepare_ds
)
186 GString
*replace_str
;
187 gsize actual_skipped_len
= 0;
188 int actual_flags
= 0;
189 gboolean actual_result
;
191 replace_str
= g_string_new (data
->input_string
);
195 mc_search_regex__replace_handle_esc_seq (replace_str
, data
->input_pos
, &actual_skipped_len
,
199 ck_assert_int_eq (actual_result
, data
->expected_result
);
200 ck_assert_int_eq (actual_skipped_len
, data
->expected_skipped_len
);
201 ck_assert_int_eq (actual_flags
, data
->expected_flags
);
203 g_string_free (replace_str
, TRUE
);
206 END_PARAMETRIZED_TEST
209 /* --------------------------------------------------------------------------------------------- */
216 tc_core
= tcase_create ("Core");
218 /* Add new tests here: *************** */
219 mctest_add_parameterized_test (tc_core
, test_regex_replace_esc_seq_prepare
,
220 test_regex_replace_esc_seq_prepare_ds
);
221 /* *********************************** */
223 return mctest_run_all (tc_core
);
226 /* --------------------------------------------------------------------------------------------- */