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"
38 #include "src/editor/editwidget.h"
39 #include "src/editor/editcmd_dialogs.h"
42 static WEdit
*test_edit
;
44 /* --------------------------------------------------------------------------------------------- */
47 edit_load_syntax (WEdit
* _edit
, char ***_pnames
, const char *_type
)
54 /* --------------------------------------------------------------------------------------------- */
58 edit_get_syntax_color (WEdit
* _edit
, off_t _byte_index
)
66 /* --------------------------------------------------------------------------------------------- */
70 edit_load_macro_cmd (WEdit
* _edit
)
77 /* --------------------------------------------------------------------------------------------- */
80 static const WEdit
*editcmd_dialog_completion_show__edit
;
82 static int editcmd_dialog_completion_show__max_len
;
84 static GString
**editcmd_dialog_completion_show__compl
;
86 static int editcmd_dialog_completion_show__num_compl
;
88 /* @ThenReturnValue */
89 static char *editcmd_dialog_completion_show__return_value
;
93 editcmd_dialog_completion_show (const WEdit
* edit
, int max_len
, GString
** compl, int num_compl
)
96 editcmd_dialog_completion_show__edit
= edit
;
97 editcmd_dialog_completion_show__max_len
= max_len
;
98 editcmd_dialog_completion_show__num_compl
= num_compl
;
103 editcmd_dialog_completion_show__compl
= g_new0 (GString
*, num_compl
);
105 for (iterator
= 0; iterator
< editcmd_dialog_completion_show__num_compl
; iterator
++)
106 editcmd_dialog_completion_show__compl
[iterator
] =
107 g_string_new_len (compl[iterator
]->str
, compl[iterator
]->len
);
110 return editcmd_dialog_completion_show__return_value
;
114 editcmd_dialog_completion_show__init (void)
116 editcmd_dialog_completion_show__edit
= NULL
;
117 editcmd_dialog_completion_show__max_len
= 0;
118 editcmd_dialog_completion_show__compl
= NULL
;
119 editcmd_dialog_completion_show__num_compl
= 0;
120 editcmd_dialog_completion_show__return_value
= NULL
;
124 editcmd_dialog_completion_show__deinit (void)
126 if (editcmd_dialog_completion_show__compl
!= NULL
)
130 for (iterator
= 0; iterator
< editcmd_dialog_completion_show__num_compl
; iterator
++)
131 g_string_free (editcmd_dialog_completion_show__compl
[iterator
], TRUE
);
133 g_free (editcmd_dialog_completion_show__compl
);
138 /* --------------------------------------------------------------------------------------------- */
144 str_init_strings (NULL
);
148 vfs_setup_work_dir ();
151 mc_global
.sysconfig_dir
= (char *) TEST_SHARE_DIR
;
152 load_codepages_list ();
153 #endif /* HAVE_CHARSET */
155 test_edit
= edit_init (NULL
, 0, 0, 24, 80, vfs_path_from_str ("test-data.txt"), 1);
156 editcmd_dialog_completion_show__init ();
159 /* --------------------------------------------------------------------------------------------- */
165 editcmd_dialog_completion_show__deinit ();
166 edit_clean (test_edit
);
170 free_codepages_list ();
171 #endif /* HAVE_CHARSET */
175 str_uninit_strings ();
178 /* --------------------------------------------------------------------------------------------- */
181 /* @DataSource("test_autocomplete_ds") */
183 static const struct test_autocomplete_ds
185 off_t input_position
;
186 const char *input_system_code_page
;
187 const char *input_editor_code_page
;
188 const char *input_completed_word
;
190 int expected_max_len
;
191 int expected_compl_word_count
;
192 int input_completed_word_start_pos
;
193 const char *expected_completed_word
;
194 } test_autocomplete_ds
[] =
221 /* @Test(dataSource = "test_autocomplete_ds") */
223 START_PARAMETRIZED_TEST (test_autocomplete
, test_autocomplete_ds
)
227 editcmd_dialog_completion_show__return_value
= g_strdup (data
->input_completed_word
);
228 cp_display
= data
->input_system_code_page
;
229 cp_source
= data
->input_editor_code_page
;
232 edit_cursor_move (test_edit
, data
->input_position
);
233 edit_complete_word_cmd (test_edit
);
236 mctest_assert_ptr_eq (editcmd_dialog_completion_show__edit
, test_edit
);
237 mctest_assert_int_eq (editcmd_dialog_completion_show__num_compl
,
238 data
->expected_compl_word_count
);
239 mctest_assert_int_eq (editcmd_dialog_completion_show__max_len
, data
->expected_max_len
);
243 GString
*actual_completed_str
;
245 actual_completed_str
= g_string_new ("");
251 chr
= edit_get_byte (test_edit
, data
->input_completed_word_start_pos
+ i
++);
254 g_string_append_c (actual_completed_str
, chr
);
256 mctest_assert_str_eq (actual_completed_str
->str
, data
->expected_completed_word
);
257 g_string_free (actual_completed_str
, TRUE
);
261 END_PARAMETRIZED_TEST
263 #endif /* HAVE_CHARSET */
265 /* --------------------------------------------------------------------------------------------- */
272 Suite
*s
= suite_create (TEST_SUITE_NAME
);
273 TCase
*tc_core
= tcase_create ("Core");
276 tcase_add_checked_fixture (tc_core
, my_setup
, my_teardown
);
278 /* Add new tests here: *************** */
280 mctest_add_parameterized_test (tc_core
, test_autocomplete
, test_autocomplete_ds
);
281 #endif /* HAVE_CHARSET */
282 /* *********************************** */
284 suite_add_tcase (s
, tc_core
);
285 sr
= srunner_create (s
);
286 srunner_set_log (sr
, "edit_complete_word_cmd.log");
287 srunner_run_all (sr
, CK_NORMAL
);
288 number_failed
= srunner_ntests_failed (sr
);
290 return (number_failed
== 0) ? 0 : 1;
293 /* --------------------------------------------------------------------------------------------- */