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 "lib/global.h"
33 #include "lib/strutil.h"
34 #include "lib/search.h"
37 static mc_search_t
*search
;
42 str_init_strings (NULL
);
43 search
= mc_search_new ("<a", -1);
44 search
->search_type
= MC_SEARCH_T_REGEX
;
50 mc_search_free (search
);
51 str_uninit_strings ();
55 /* --------------------------------------------------------------------------------------------- */
56 START_TEST (regex_search_test
)
59 gsize actual_found_len
;
60 gboolean actual_result
;
64 actual_result
= mc_search_run (
66 "some string with <a for searching",
73 ck_assert_int_eq (actual_result
, TRUE
);
74 ck_assert_int_eq (actual_found_len
, 2);
75 ck_assert_int_eq (search
->normal_offset
, 17);
79 /* --------------------------------------------------------------------------------------------- */
81 static mc_search_cbret_t
82 regex_search_callback (const void *user_data
, gsize char_offset
, int *current_char
) {
83 static const char *data
= "some string with <a for searching";
87 *current_char
= data
[char_offset
];
88 return MC_SEARCH_CB_OK
;
91 START_TEST (regex_search_callback_test
)
94 gsize actual_found_len
;
95 gboolean actual_result
;
97 search
->search_fn
= regex_search_callback
;
100 actual_result
= mc_search_run (
108 ck_assert_int_eq (actual_result
, TRUE
);
109 ck_assert_int_eq (actual_found_len
, 2);
110 ck_assert_int_eq (search
->normal_offset
, 17);
115 /* --------------------------------------------------------------------------------------------- */
123 Suite
*s
= suite_create (TEST_SUITE_NAME
);
124 TCase
*tc_core
= tcase_create ("Core");
127 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
129 /* Add new tests here: *************** */
130 tcase_add_test (tc_core
, regex_search_test
);
131 tcase_add_test (tc_core
, regex_search_callback_test
);
132 /* *********************************** */
134 suite_add_tcase (s
, tc_core
);
135 sr
= srunner_create (s
);
136 srunner_run_all (sr
, CK_NORMAL
);
137 number_failed
= srunner_ntests_failed (sr
);
139 return (number_failed
== 0) ? 0 : 1;
142 /* --------------------------------------------------------------------------------------------- */