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 Slava Zanko <slavazanko@gmail.com>, 2011, 2013
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/regex"
27
28 #include "tests/mctest.h"
29
30 #include "regex.c" // for testing static functions
31
32 /* --------------------------------------------------------------------------------------------- */
33
34 /* @DataSource("test_regex_process_escape_sequence_ds") */
35 static const struct test_regex_process_escape_sequence_ds
36 {
37 const char *input_from;
38 const replace_transform_type_t input_initial_flags;
39 const gboolean input_use_utf;
40 const char *expected_string;
41 } test_regex_process_escape_sequence_ds[] = {
42 {
43 // 0.
44 "{101}",
45 REPLACE_T_NO_TRANSFORM,
46 FALSE,
47 "A",
48 },
49 {
50 // 1.
51 "x42",
52 REPLACE_T_NO_TRANSFORM,
53 FALSE,
54 "B",
55 },
56 {
57 // 2.
58 "x{444}",
59 REPLACE_T_NO_TRANSFORM,
60 FALSE,
61 "D",
62 },
63 {
64 // 3.
65 "x{444}",
66 REPLACE_T_NO_TRANSFORM,
67 TRUE,
68 "ф",
69 },
70 {
71 // 4.
72 "n",
73 REPLACE_T_NO_TRANSFORM,
74 FALSE,
75 "\n",
76 },
77 {
78 // 5.
79 "t",
80 REPLACE_T_NO_TRANSFORM,
81 FALSE,
82 "\t",
83 },
84 {
85 // 6.
86 "v",
87 REPLACE_T_NO_TRANSFORM,
88 FALSE,
89 "\v",
90 },
91 {
92 // 7.
93 "b",
94 REPLACE_T_NO_TRANSFORM,
95 FALSE,
96 "\b",
97 },
98 {
99 // 8.
100 "r",
101 REPLACE_T_NO_TRANSFORM,
102 FALSE,
103 "\r",
104 },
105 {
106 // 9.
107 "f",
108 REPLACE_T_NO_TRANSFORM,
109 FALSE,
110 "\f",
111 },
112 {
113 // 10.
114 "a",
115 REPLACE_T_NO_TRANSFORM,
116 FALSE,
117 "\a",
118 },
119 };
120
121 /* @Test(dataSource = "test_regex_process_escape_sequence_ds") */
122 START_PARAMETRIZED_TEST (test_regex_process_escape_sequence, test_regex_process_escape_sequence_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)
*/
123 {
124 // given
125 GString *actual_string;
126 replace_transform_type_t replace_flags = REPLACE_T_NO_TRANSFORM;
127
128 replace_flags = data->input_initial_flags;
129 actual_string = g_string_new ("");
130
131 // when
132 mc_search_regex__process_escape_sequence (actual_string, data->input_from, -1, &replace_flags,
133 data->input_use_utf);
134
135 // then
136 mctest_assert_str_eq (actual_string->str, data->expected_string);
137
138 g_string_free (actual_string, TRUE);
139 }
140 END_PARAMETRIZED_TEST
141
142 /* --------------------------------------------------------------------------------------------- */
143
144 int
145 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)
*/
146 {
147 TCase *tc_core;
148
149 tc_core = tcase_create ("Core");
150
151 // Add new tests here: ***************
152 mctest_add_parameterized_test (tc_core, test_regex_process_escape_sequence,
153 test_regex_process_escape_sequence_ds);
154 // ***********************************
155
156 return mctest_run_all (tc_core);
157 }
158
159 /* --------------------------------------------------------------------------------------------- */