Merge branch '4524_cleanup'
[midnight-commander.git] / tests / lib / widget / complete_engine.c
blobd723b34a54e278f9b71ffc182ffea422aab796fe
1 /*
2 lib/widget - tests for autocomplete feature
4 Copyright (C) 2013-2024
5 Free Software Foundation, Inc.
7 Written by:
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 /* --------------------------------------------------------------------------------------------- */
40 /* @CapturedValue */
41 static char *try_complete__text__captured;
42 /* @CapturedValue */
43 static int try_complete__lc_start__captured;
44 /* @CapturedValue */
45 static int try_complete__lc_end__captured;
46 /* @CapturedValue */
47 static input_complete_t try_complete__flags__captured;
49 /* @ThenReturnValue */
50 static char **try_complete__return_value;
52 /* @Mock */
53 char **
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;
64 static void
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;
73 static void
74 try_complete__deinit (void)
76 g_free (try_complete__text__captured);
79 /* --------------------------------------------------------------------------------------------- */
81 /* @Before */
82 static void
83 setup (void)
85 str_init_strings (NULL);
86 try_complete__init ();
89 /* --------------------------------------------------------------------------------------------- */
91 /* @After */
92 static void
93 teardown (void)
95 try_complete__deinit ();
96 str_uninit_strings ();
99 /* --------------------------------------------------------------------------------------------- */
101 /* @DataSource("test_complete_engine_fill_completions_ds") */
102 /* *INDENT-OFF* */
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;
108 int expected_start;
109 int expected_end;
110 } test_complete_engine_fill_completions_ds[] =
113 "string",
115 INPUT_COMPLETE_NONE,
120 "some string",
122 INPUT_COMPLETE_NONE,
127 "some string",
129 INPUT_COMPLETE_SHELL_ESC,
134 "some\\ string111",
136 INPUT_COMPLETE_SHELL_ESC,
141 "some\\\tstring111",
143 INPUT_COMPLETE_SHELL_ESC,
148 "some\tstring",
150 INPUT_COMPLETE_NONE,
155 "some;string",
157 INPUT_COMPLETE_NONE,
162 "some|string",
164 INPUT_COMPLETE_NONE,
169 "some<string",
171 INPUT_COMPLETE_NONE,
176 "some>string",
178 INPUT_COMPLETE_NONE,
183 "some!@#$%^&*()_\\+~`\"',./?:string",
185 INPUT_COMPLETE_NONE,
190 /* *INDENT-ON* */
192 /* @Test(dataSource = "test_complete_engine_fill_completions_ds") */
193 /* *INDENT-OFF* */
194 START_PARAMETRIZED_TEST (test_complete_engine_fill_completions,
195 test_complete_engine_fill_completions_ds)
196 /* *INDENT-ON* */
198 /* given */
199 WInput *w_input;
201 w_input = input_new (1, 1, NULL, 100, data->input_buffer, NULL, data->input_completion_flags);
202 w_input->point = data->input_point;
204 /* when */
205 complete_engine_fill_completions (w_input);
207 /* then */
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);
213 /* *INDENT-OFF* */
214 END_PARAMETRIZED_TEST
215 /* *INDENT-ON* */
217 /* --------------------------------------------------------------------------------------------- */
220 main (void)
222 TCase *tc_core;
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 /* --------------------------------------------------------------------------------------------- */