This source file includes following definitions.
- message
- status_msg_init
- status_msg_deinit
- edit_search_update_callback
- edit_dialog_replace_show
- edit_dialog_replace_prompt_show
- edit_load_syntax
- edit_get_syntax_color
- edit_load_macro_cmd
- setup
- teardown
- test_replace_check
- START_TEST
- START_TEST
- START_TEST
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #define TEST_SUITE_NAME "/src/editor"
27
28 #include "tests/mctest.h"
29
30 #include <ctype.h>
31
32 #include "lib/charsets.h"
33 #include "src/selcodepage.h"
34
35 #include "src/editor/editwidget.h"
36 #include "src/editor/editmacros.h"
37 #include "src/editor/editsearch.h"
38
39 static WGroup owner;
40 static WEdit *test_edit;
41 static gboolean only_in_selection = FALSE;
42
43 static const char *test_regex_in = "qwe\n"
44 "qwe\n"
45 "qwe\n"
46 "qwe\n"
47 "qwe\n"
48 "qwe\n"
49 "qwe\n"
50 "qwe\n";
51 static const char *test_regex_out = "Xqwe\n"
52 "Xqwe\n"
53 "Xqwe\n"
54 "Xqwe\n"
55 "Xqwe\n"
56 "Xqwe\n"
57 "Xqwe\n"
58 "Xqwe\n";
59
60 static const char *test_regex_selected_in = "qwe\n"
61 "qwe\n"
62 "qwe\n"
63 "qwe\n"
64 "qwe\n"
65 "qwe\n"
66 "qwe\n"
67 "qwe\n";
68 static const char *test1_regex_selected_out = "qwe\n"
69 "qwe\n"
70 "Xqwe\n"
71 "Xqwe\n"
72 "Xqwe\n"
73 "qwe\n"
74 "qwe\n"
75 "qwe\n";
76 static const char *test2_regex_selected_out = "qwe\n"
77 "qwe\n"
78 "qwe\n"
79 "Xqwe\n"
80 "Xqwe\n"
81 "qwe\n"
82 "qwe\n"
83 "qwe\n";
84
85 static const char *replace_regex_from = "^.*";
86 static const char *replace_regex_to = "X\\0";
87
88
89
90 void edit_dialog_replace_show (WEdit *edit, const char *search_default, const char *replace_default,
91 char **search_text, char **replace_text);
92 int edit_dialog_replace_prompt_show (WEdit *edit, char *from_text, char *to_text, int xpos,
93 int ypos);
94
95
96
97 void
98 message (int flags, const char *title, const char *text, ...)
99 {
100 (void) flags;
101 (void) title;
102 (void) text;
103 }
104
105
106
107 void
108 status_msg_init (status_msg_t *sm, const char *title, double delay, status_msg_cb init_cb,
109 status_msg_update_cb update_cb, status_msg_cb deinit_cb)
110 {
111 (void) sm;
112 (void) title;
113 (void) delay;
114 (void) init_cb;
115 (void) update_cb;
116 (void) deinit_cb;
117 }
118
119
120
121 void
122 status_msg_deinit (status_msg_t *sm)
123 {
124 (void) sm;
125 }
126
127
128
129 mc_search_cbret_t
130 edit_search_update_callback (const void *user_data, off_t char_offset)
131 {
132 (void) user_data;
133 (void) char_offset;
134
135 return MC_SEARCH_CB_OK;
136 }
137
138
139
140 void
141 edit_dialog_replace_show (WEdit *edit, const char *search_default, const char *replace_default,
142 char **search_text, char **replace_text)
143 {
144 (void) edit;
145 (void) search_default;
146 (void) replace_default;
147
148 *search_text = g_strdup (replace_regex_from);
149 *replace_text = g_strdup (replace_regex_to);
150
151 edit_search_options.type = MC_SEARCH_T_REGEX;
152 edit_search_options.only_in_selection = only_in_selection;
153 }
154
155
156
157 int
158 edit_dialog_replace_prompt_show (WEdit *edit, char *from_text, char *to_text, int xpos, int ypos)
159 {
160 (void) edit;
161 (void) from_text;
162 (void) to_text;
163 (void) xpos;
164 (void) ypos;
165
166 return B_REPLACE_ALL;
167 }
168
169
170
171 void
172 edit_load_syntax (WEdit *edit, GPtrArray *pnames, const char *type)
173 {
174 (void) edit;
175 (void) pnames;
176 (void) type;
177 }
178
179
180
181
182 int
183 edit_get_syntax_color (WEdit *edit, off_t byte_index)
184 {
185 (void) edit;
186 (void) byte_index;
187
188 return 0;
189 }
190
191
192
193
194 gboolean
195 edit_load_macro_cmd (WEdit *edit)
196 {
197 (void) edit;
198
199 return FALSE;
200 }
201
202
203
204
205 static void
206 setup (void)
207 {
208 WRect r;
209
210 str_init_strings (NULL);
211
212 mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
213 load_codepages_list ();
214
215 edit_options.filesize_threshold = (char *) "64M";
216
217 rect_init (&r, 0, 0, 24, 80);
218 test_edit = edit_init (NULL, &r, NULL);
219 memset (&owner, 0, sizeof (owner));
220 group_add_widget (&owner, WIDGET (test_edit));
221
222 mc_global.source_codepage = 0;
223 mc_global.display_codepage = 0;
224 cp_source = "ASCII";
225 cp_display = "ASCII";
226
227 do_set_codepage (0);
228 edit_set_codeset (test_edit);
229 }
230
231
232
233
234 static void
235 teardown (void)
236 {
237 edit_clean (test_edit);
238 group_remove_widget (test_edit);
239 g_free (test_edit);
240
241 free_codepages_list ();
242 str_uninit_strings ();
243 }
244
245
246
247 static void
248 test_replace_check (const char *test_out)
249 {
250 GString *actual_replaced_str;
251
252 actual_replaced_str = g_string_new ("");
253
254 for (off_t i = 0; i < test_edit->buffer.size; i++)
255 {
256 const int chr = edit_buffer_get_byte (&test_edit->buffer, i);
257
258 g_string_append_c (actual_replaced_str, chr);
259 }
260
261 mctest_assert_str_eq (actual_replaced_str->str, test_out);
262 g_string_free (actual_replaced_str, TRUE);
263 }
264
265
266
267 START_TEST (test_replace_regex)
268 {
269
270 only_in_selection = FALSE;
271 test_edit->mark1 = 0;
272 test_edit->mark2 = 0;
273
274 for (const char *ti = test_regex_in; *ti != '\0'; ti++)
275 edit_buffer_insert (&test_edit->buffer, *ti);
276
277
278 edit_cursor_move (test_edit, 0);
279 edit_replace_cmd (test_edit, FALSE);
280
281
282 test_replace_check (test_regex_out);
283 }
284 END_TEST
285
286
287
288 START_TEST (test1_replace_regex_in_selection)
289 {
290
291 only_in_selection = TRUE;
292 test_edit->mark1 = 8;
293 test_edit->mark2 = 20;
294
295 for (const char *ti = test_regex_selected_in; *ti != '\0'; ti++)
296 edit_buffer_insert (&test_edit->buffer, *ti);
297
298
299 edit_cursor_move (test_edit, 0);
300 edit_replace_cmd (test_edit, FALSE);
301
302
303 test_replace_check (test1_regex_selected_out);
304 }
305 END_TEST
306
307
308
309 START_TEST (test2_replace_regex_in_selection)
310 {
311
312 only_in_selection = TRUE;
313 test_edit->mark1 = 9;
314 test_edit->mark2 = 20;
315
316 for (const char *ti = test_regex_selected_in; *ti != '\0'; ti++)
317 edit_buffer_insert (&test_edit->buffer, *ti);
318
319
320 edit_cursor_move (test_edit, 0);
321 edit_replace_cmd (test_edit, FALSE);
322
323
324 test_replace_check (test2_regex_selected_out);
325 }
326 END_TEST
327
328
329
330 int
331 main (void)
332 {
333 TCase *tc_core;
334
335 tc_core = tcase_create ("Core");
336
337 tcase_add_checked_fixture (tc_core, setup, teardown);
338
339
340 tcase_add_test (tc_core, test_replace_regex);
341 tcase_add_test (tc_core, test1_replace_regex_in_selection);
342 tcase_add_test (tc_core, test2_replace_regex_in_selection);
343
344
345 return mctest_run_all (tc_core);
346 }
347
348