1 /*
2 libmc - checks for processing esc sequences in replace string
3
4 Copyright (C) 2011-2025
5 Free Software Foundation, Inc.
6
7 Written by:
8 Andrew Borodin <aborodin@vmail.ru>, 2014
9
10 This file is part of the Midnight Commander.
11
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.
16
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.
21
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
26 #define TEST_SUITE_NAME "lib/search/glob"
27
28 #include "tests/mctest.h"
29
30 #include "glob.c" // for testing static functions
31
32 /* --------------------------------------------------------------------------------------------- */
33
34 /* @DataSource("test_glob_prepare_replace_str_ds") */
35 static const struct test_glob_prepare_replace_str_ds
36 {
37 const char *input_value;
38 const char *glob_str;
39 const char *replace_str;
40 const char *expected_result;
41 } test_glob_prepare_replace_str_ds[] = {
42 {
43 // 0.
44 "qqwwee",
45 "*ww*",
46 "\\1AA\\2",
47 "qqAAee",
48 },
49 {
50 // 1.
51 "qqwwee",
52 "*qq*",
53 "\\1SS\\2",
54 "SSwwee",
55 },
56 {
57 // 2.
58 "qqwwee",
59 "*ee*",
60 "\\1RR\\2",
61 "qqwwRR",
62 },
63 };
64
65 /* @Test(dataSource = "test_glob_prepare_replace_str_ds") */
66 START_PARAMETRIZED_TEST (test_glob_prepare_replace_str, test_glob_prepare_replace_str_ds)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
67 {
68 // given
69 mc_search_t *s;
70 char *dest_str;
71
72 s = mc_search_new (data->glob_str, NULL);
73 s->is_case_sensitive = TRUE;
74 s->search_type = MC_SEARCH_T_GLOB;
75
76 // when
77 mc_search_run (s, data->input_value, 0, strlen (data->input_value), NULL);
78 dest_str = mc_search_prepare_replace_str2 (s, data->replace_str);
79
80 // then
81 mctest_assert_str_eq (dest_str, data->expected_result);
82
83 g_free (dest_str);
84 mc_search_free (s);
85 }
86 END_PARAMETRIZED_TEST
87
88 /* --------------------------------------------------------------------------------------------- */
89
90 int
91 main (void)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
92 {
93 TCase *tc_core;
94
95 tc_core = tcase_create ("Core");
96
97 // Add new tests here: ***************
98 mctest_add_parameterized_test (tc_core, test_glob_prepare_replace_str,
99 test_glob_prepare_replace_str_ds);
100 // ***********************************
101
102 return mctest_run_all (tc_core);
103 }
104
105 /* --------------------------------------------------------------------------------------------- */