2 src/editor - tests for edit_complete_word_cmd() function
5 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2013
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 "/src/editor"
28 #include "tests/mctest.h"
33 #include "lib/charsets.h"
35 #include "lib/strutil.h"
37 #include "src/vfs/local/local.c"
39 #include "src/selcodepage.h"
41 #include "src/editor/editwidget.h"
42 #include "src/editor/editcmd_dialogs.h"
45 static WEdit
*test_edit
;
47 /* --------------------------------------------------------------------------------------------- */
50 edit_load_syntax (WEdit
* _edit
, char ***_pnames
, const char *_type
)
57 /* --------------------------------------------------------------------------------------------- */
61 edit_get_syntax_color (WEdit
* _edit
, off_t _byte_index
)
69 /* --------------------------------------------------------------------------------------------- */
73 edit_load_macro_cmd (WEdit
* _edit
)
80 /* --------------------------------------------------------------------------------------------- */
83 static const WEdit
*editcmd_dialog_completion_show__edit
;
85 static int editcmd_dialog_completion_show__max_len
;
87 static GString
**editcmd_dialog_completion_show__compl
;
89 static int editcmd_dialog_completion_show__num_compl
;
91 /* @ThenReturnValue */
92 static char *editcmd_dialog_completion_show__return_value
;
96 editcmd_dialog_completion_show (const WEdit
* edit
, int max_len
, GString
** compl, int num_compl
)
99 editcmd_dialog_completion_show__edit
= edit
;
100 editcmd_dialog_completion_show__max_len
= max_len
;
101 editcmd_dialog_completion_show__num_compl
= num_compl
;
106 editcmd_dialog_completion_show__compl
= g_new0 (GString
*, num_compl
);
108 for (iterator
= 0; iterator
< editcmd_dialog_completion_show__num_compl
; iterator
++)
109 editcmd_dialog_completion_show__compl
[iterator
] =
110 g_string_new_len (compl[iterator
]->str
, compl[iterator
]->len
);
113 return editcmd_dialog_completion_show__return_value
;
117 editcmd_dialog_completion_show__init (void)
119 editcmd_dialog_completion_show__edit
= NULL
;
120 editcmd_dialog_completion_show__max_len
= 0;
121 editcmd_dialog_completion_show__compl
= NULL
;
122 editcmd_dialog_completion_show__num_compl
= 0;
123 editcmd_dialog_completion_show__return_value
= NULL
;
127 editcmd_dialog_completion_show__deinit (void)
129 if (editcmd_dialog_completion_show__compl
!= NULL
)
133 for (iterator
= 0; iterator
< editcmd_dialog_completion_show__num_compl
; iterator
++)
134 g_string_free (editcmd_dialog_completion_show__compl
[iterator
], TRUE
);
136 g_free (editcmd_dialog_completion_show__compl
);
141 /* --------------------------------------------------------------------------------------------- */
147 str_init_strings (NULL
);
151 vfs_setup_work_dir ();
154 mc_global
.sysconfig_dir
= (char *) TEST_SHARE_DIR
;
155 load_codepages_list ();
156 #endif /* HAVE_CHARSET */
158 test_edit
= edit_init (NULL
, 0, 0, 24, 80, vfs_path_from_str ("test-data.txt"), 1);
159 editcmd_dialog_completion_show__init ();
162 /* --------------------------------------------------------------------------------------------- */
168 editcmd_dialog_completion_show__deinit ();
169 edit_clean (test_edit
);
173 free_codepages_list ();
174 #endif /* HAVE_CHARSET */
178 str_uninit_strings ();
181 /* --------------------------------------------------------------------------------------------- */
184 /* @DataSource("test_autocomplete_ds") */
186 static const struct test_autocomplete_ds
188 off_t input_position
;
189 const char *input_system_code_page
;
190 int input_source_codepage_id
;
191 const char *input_editor_code_page
;
192 int input_display_codepage_id
;
193 const char *input_completed_word
;
195 int expected_max_len
;
196 int expected_compl_word_count
;
197 int input_completed_word_start_pos
;
198 const char *expected_completed_word
;
199 } test_autocomplete_ds
[] =
230 /* @Test(dataSource = "test_autocomplete_ds") */
232 START_PARAMETRIZED_TEST (test_autocomplete
, test_autocomplete_ds
)
236 editcmd_dialog_completion_show__return_value
= g_strdup (data
->input_completed_word
);
239 mc_global
.source_codepage
= data
->input_source_codepage_id
;
240 mc_global
.display_codepage
= data
->input_display_codepage_id
;
241 cp_source
= data
->input_editor_code_page
;
242 cp_display
= data
->input_system_code_page
;
245 edit_set_codeset (test_edit
);
248 edit_cursor_move (test_edit
, data
->input_position
);
249 edit_complete_word_cmd (test_edit
);
252 mctest_assert_ptr_eq (editcmd_dialog_completion_show__edit
, test_edit
);
253 mctest_assert_int_eq (editcmd_dialog_completion_show__num_compl
,
254 data
->expected_compl_word_count
);
255 mctest_assert_int_eq (editcmd_dialog_completion_show__max_len
, data
->expected_max_len
);
259 GString
*actual_completed_str
;
261 actual_completed_str
= g_string_new ("");
267 chr
= edit_get_byte (test_edit
, data
->input_completed_word_start_pos
+ i
++);
270 g_string_append_c (actual_completed_str
, chr
);
272 mctest_assert_str_eq (actual_completed_str
->str
, data
->expected_completed_word
);
273 g_string_free (actual_completed_str
, TRUE
);
277 END_PARAMETRIZED_TEST
280 /* --------------------------------------------------------------------------------------------- */
282 /* @DataSource("test_autocomplete_single_ds") */
284 static const struct test_autocomplete_single_ds
286 off_t input_position
;
287 const char *input_system_code_page
;
288 int input_source_codepage_id
;
289 const char *input_editor_code_page
;
290 int input_display_codepage_id
;
292 int input_completed_word_start_pos
;
294 const char *expected_completed_word
;
295 } test_autocomplete_single_ds
[] =
310 /* @Test(dataSource = "test_autocomplete_single_ds") */
312 START_PARAMETRIZED_TEST (test_autocomplete_single
, test_autocomplete_single_ds
)
316 mc_global
.source_codepage
= data
->input_source_codepage_id
;
317 mc_global
.display_codepage
= data
->input_display_codepage_id
;
318 cp_source
= data
->input_editor_code_page
;
319 cp_display
= data
->input_system_code_page
;
322 edit_set_codeset (test_edit
);
325 edit_cursor_move (test_edit
, data
->input_position
);
326 edit_complete_word_cmd (test_edit
);
331 GString
*actual_completed_str
;
333 actual_completed_str
= g_string_new ("");
339 chr
= edit_get_byte (test_edit
, data
->input_completed_word_start_pos
+ i
++);
342 g_string_append_c (actual_completed_str
, chr
);
344 mctest_assert_str_eq (actual_completed_str
->str
, data
->expected_completed_word
);
345 g_string_free (actual_completed_str
, TRUE
);
349 END_PARAMETRIZED_TEST
353 #endif /* HAVE_CHARSET */
355 /* --------------------------------------------------------------------------------------------- */
362 Suite
*s
= suite_create (TEST_SUITE_NAME
);
363 TCase
*tc_core
= tcase_create ("Core");
366 tcase_add_checked_fixture (tc_core
, my_setup
, my_teardown
);
368 /* Add new tests here: *************** */
370 mctest_add_parameterized_test (tc_core
, test_autocomplete
, test_autocomplete_ds
);
371 mctest_add_parameterized_test (tc_core
, test_autocomplete_single
, test_autocomplete_single_ds
);
372 #endif /* HAVE_CHARSET */
373 /* *********************************** */
375 suite_add_tcase (s
, tc_core
);
376 sr
= srunner_create (s
);
377 srunner_set_log (sr
, "edit_complete_word_cmd.log");
378 srunner_run_all (sr
, CK_NORMAL
);
379 number_failed
= srunner_ntests_failed (sr
);
381 return (number_failed
== 0) ? 0 : 1;
384 /* --------------------------------------------------------------------------------------------- */