Ticket #55: savannah: tab completion vs. spaces and escaping
[midnight-commander.git] / tests / lib / widget / complete_engine.c
blob656f1573d64fd8fc9892d8bf54cd62bdc548e2cd
1 /*
2 lib/widget - tests for autocomplete feature
4 Copyright (C) 2013
5 The 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 <config.h>
30 #include <check.h>
32 #include "lib/global.h"
33 #include "lib/strutil.h"
34 #include "lib/widget.h"
36 /* --------------------------------------------------------------------------------------------- */
38 void complete_engine_fill_completions (WInput * in);
39 char **try_complete (char *text, int *lc_start, int *lc_end, input_complete_t flags);
41 /* --------------------------------------------------------------------------------------------- */
43 /* @CapturedValue */
44 static char *try_complete__text__captured;
45 /* @CapturedValue */
46 static int try_complete__lc_start__captured;
47 /* @CapturedValue */
48 static int try_complete__lc_end__captured;
49 /* @CapturedValue */
50 static input_complete_t try_complete__flags__captured;
52 /* @ThenReturnValue */
53 static char **try_complete__return_value;
55 /* @Mock */
56 char **
57 try_complete (char *text, int *lc_start, int *lc_end, input_complete_t flags)
59 try_complete__text__captured = g_strdup (text);
60 try_complete__lc_start__captured = *lc_start;
61 try_complete__lc_end__captured = *lc_end;
62 try_complete__flags__captured = flags;
64 return try_complete__return_value;
67 static void
68 try_complete__init (void)
70 try_complete__text__captured = NULL;
71 try_complete__lc_start__captured = 0;
72 try_complete__lc_end__captured = 0;
73 try_complete__flags__captured = 0;
76 static void
77 try_complete__deinit (void)
79 g_free (try_complete__text__captured);
82 /* --------------------------------------------------------------------------------------------- */
84 /* @Before */
85 static void
86 setup (void)
88 str_init_strings (NULL);
89 try_complete__init ();
92 /* --------------------------------------------------------------------------------------------- */
94 /* @After */
95 static void
96 teardown (void)
98 try_complete__deinit ();
99 str_uninit_strings ();
102 /* --------------------------------------------------------------------------------------------- */
104 /* @DataSource("test_complete_engine_fill_completions_ds") */
105 /* *INDENT-OFF* */
106 static const struct test_complete_engine_fill_completions_ds
108 const char *input_buffer;
109 const int input_point;
110 const input_complete_t input_completion_flags;
111 int expected_start;
112 int expected_end;
113 } test_complete_engine_fill_completions_ds[] =
116 "string",
118 INPUT_COMPLETE_DEFAULT,
123 "some string",
125 INPUT_COMPLETE_DEFAULT,
130 "some\tstring",
132 INPUT_COMPLETE_DEFAULT,
137 "some;string",
139 INPUT_COMPLETE_DEFAULT,
144 "some|string",
146 INPUT_COMPLETE_DEFAULT,
151 "some<string",
153 INPUT_COMPLETE_DEFAULT,
158 "some>string",
160 INPUT_COMPLETE_DEFAULT,
165 "some!@#$%^&*()_\\+~`\"',./?:string",
167 INPUT_COMPLETE_DEFAULT,
172 /* *INDENT-ON* */
173 // " \t;|<>"
175 /* @Test(dataSource = "test_complete_engine_fill_completions_ds") */
176 /* *INDENT-OFF* */
177 START_TEST (test_complete_engine_fill_completions)
178 /* *INDENT-ON* */
180 /* given */
182 WInput *w_input;
183 const struct test_complete_engine_fill_completions_ds *data =
184 &test_complete_engine_fill_completions_ds[_i];
186 w_input = g_new (WInput, 1);
187 w_input->buffer = g_strdup (data->input_buffer);
188 w_input->point = data->input_point;
189 w_input->completion_flags = data->input_completion_flags;
191 /* when */
192 complete_engine_fill_completions (w_input);
194 /* then */
195 g_assert_cmpstr (try_complete__text__captured, ==, data->input_buffer);
196 ck_assert_int_eq (try_complete__lc_start__captured, data->expected_start);
197 ck_assert_int_eq (try_complete__lc_end__captured, data->expected_end);
198 ck_assert_int_eq (try_complete__flags__captured, data->input_completion_flags);
201 /* *INDENT-OFF* */
202 END_TEST
203 /* *INDENT-ON* */
205 /* --------------------------------------------------------------------------------------------- */
208 main (void)
210 int number_failed;
212 Suite *s = suite_create (TEST_SUITE_NAME);
213 TCase *tc_core = tcase_create ("Core");
214 SRunner *sr;
216 tcase_add_checked_fixture (tc_core, setup, teardown);
218 /* Add new tests here: *************** */
219 tcase_add_loop_test (tc_core, test_complete_engine_fill_completions, 0,
220 sizeof (test_complete_engine_fill_completions_ds) /
221 sizeof (test_complete_engine_fill_completions_ds[0]));
222 /* *********************************** */
224 suite_add_tcase (s, tc_core);
225 sr = srunner_create (s);
226 srunner_set_log (sr, "complete_engine.log");
227 srunner_run_all (sr, CK_NORMAL);
228 number_failed = srunner_ntests_failed (sr);
229 srunner_free (sr);
230 return (number_failed == 0) ? 0 : 1;
233 /* --------------------------------------------------------------------------------------------- */