2 lib/widget - tests for autocomplete feature
4 Copyright (C) 2013-2024
5 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 "/lib/widget"
28 #include "tests/mctest.h"
30 #include "lib/strutil.h"
31 #include "lib/widget.h"
33 /* --------------------------------------------------------------------------------------------- */
35 void complete_engine_fill_completions (WInput
* in
);
36 char **try_complete (char *text
, int *lc_start
, int *lc_end
, input_complete_t flags
);
38 /* --------------------------------------------------------------------------------------------- */
41 static char *try_complete__text__captured
;
43 static int try_complete__lc_start__captured
;
45 static int try_complete__lc_end__captured
;
47 static input_complete_t try_complete__flags__captured
;
49 /* @ThenReturnValue */
50 static char **try_complete__return_value
;
54 try_complete (char *text
, int *lc_start
, int *lc_end
, input_complete_t flags
)
56 try_complete__text__captured
= g_strdup (text
);
57 try_complete__lc_start__captured
= *lc_start
;
58 try_complete__lc_end__captured
= *lc_end
;
59 try_complete__flags__captured
= flags
;
61 return try_complete__return_value
;
65 try_complete__init (void)
67 try_complete__text__captured
= NULL
;
68 try_complete__lc_start__captured
= 0;
69 try_complete__lc_end__captured
= 0;
70 try_complete__flags__captured
= 0;
74 try_complete__deinit (void)
76 g_free (try_complete__text__captured
);
79 /* --------------------------------------------------------------------------------------------- */
85 str_init_strings (NULL
);
86 try_complete__init ();
89 /* --------------------------------------------------------------------------------------------- */
95 try_complete__deinit ();
96 str_uninit_strings ();
99 /* --------------------------------------------------------------------------------------------- */
101 /* @DataSource("test_complete_engine_fill_completions_ds") */
103 static const struct test_complete_engine_fill_completions_ds
105 const char *input_buffer
;
106 const int input_point
;
107 const input_complete_t input_completion_flags
;
110 } test_complete_engine_fill_completions_ds
[] =
129 INPUT_COMPLETE_SHELL_ESC
,
136 INPUT_COMPLETE_SHELL_ESC
,
143 INPUT_COMPLETE_SHELL_ESC
,
183 "some!@#$%^&*()_\\+~`\"',./?:string",
192 /* @Test(dataSource = "test_complete_engine_fill_completions_ds") */
194 START_PARAMETRIZED_TEST (test_complete_engine_fill_completions
,
195 test_complete_engine_fill_completions_ds
)
201 w_input
= input_new (1, 1, NULL
, 100, data
->input_buffer
, NULL
, data
->input_completion_flags
);
202 w_input
->point
= data
->input_point
;
205 complete_engine_fill_completions (w_input
);
208 mctest_assert_str_eq (try_complete__text__captured
, data
->input_buffer
);
209 ck_assert_int_eq (try_complete__lc_start__captured
, data
->expected_start
);
210 ck_assert_int_eq (try_complete__lc_end__captured
, data
->expected_end
);
211 ck_assert_int_eq (try_complete__flags__captured
, data
->input_completion_flags
);
214 END_PARAMETRIZED_TEST
217 /* --------------------------------------------------------------------------------------------- */
224 tc_core
= tcase_create ("Core");
226 tcase_add_checked_fixture (tc_core
, setup
, teardown
);
228 /* Add new tests here: *************** */
229 mctest_add_parameterized_test (tc_core
, test_complete_engine_fill_completions
,
230 test_complete_engine_fill_completions_ds
);
231 /* *********************************** */
233 return mctest_run_all (tc_core
);
236 /* --------------------------------------------------------------------------------------------- */