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>, 2011
9 Slava Zanko <slavazanko@gmail.com>, 2013
10
11 This file is part of the Midnight Commander.
12
13 The Midnight Commander is free software: you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation, either version 3 of the License,
16 or (at your option) any later version.
17
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
27 #define TEST_SUITE_NAME "lib/search/glob"
28
29 #include "tests/mctest.h"
30
31 #include "glob.c" // for testing static functions
32
33 /* --------------------------------------------------------------------------------------------- */
34
35 /* @DataSource("test_glob_translate_to_regex_ds") */
36 static const struct test_glob_translate_to_regex_ds
37 {
38 const char *input_value;
39 const char *expected_result;
40 } test_glob_translate_to_regex_ds[] = {
41 {
42 "test*",
43 "test(.*)",
44 },
45 {
46 "t?es*t",
47 "t(.)es(.*)t",
48 },
49 {
50 "te{st}",
51 "te(st)",
52 },
53 {
54 "te{st|ts}",
55 "te(st|ts)",
56 },
57 {
58 "te{st,ts}",
59 "te(st|ts)",
60 },
61 {
62 "te[st]",
63 "te[st]",
64 },
65 {
66 "t,e.st",
67 "t,e\\.st",
68 },
69 {
70 "^t,e.+st+$",
71 "\\^t,e\\.\\+st\\+\\$",
72 },
73 {
74 "te!@#$%^&*()_+|\";:'{}:><?\\?\\*.,/[]|\\/st",
75 "te!@#\\$%\\^&(.*)\\(\\)_\\+|\";:'():><(.)\\?\\*\\.,/[]|\\/st",
76 },
77 };
78
79 /* @Test(dataSource = "test_glob_translate_to_regex_ds") */
80 START_PARAMETRIZED_TEST (test_glob_translate_to_regex, test_glob_translate_to_regex_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)
*/
81 {
82 // given
83 GString *tmp = g_string_new (data->input_value);
84 GString *dest_str;
85
86 // when
87 dest_str = mc_search__glob_translate_to_regex (tmp);
88
89 // then
90 g_string_free (tmp, TRUE);
91
92 mctest_assert_str_eq (dest_str->str, data->expected_result);
93 g_string_free (dest_str, TRUE);
94 }
95 END_PARAMETRIZED_TEST
96
97 /* --------------------------------------------------------------------------------------------- */
98
99 int
100 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)
*/
101 {
102 TCase *tc_core;
103
104 tc_core = tcase_create ("Core");
105
106 // Add new tests here: ***************
107 mctest_add_parameterized_test (tc_core, test_glob_translate_to_regex,
108 test_glob_translate_to_regex_ds);
109 // ***********************************
110
111 return mctest_run_all (tc_core);
112 }
113
114 /* --------------------------------------------------------------------------------------------- */