This source file includes following definitions.
- try_complete
- try_complete__init
- try_complete__deinit
- setup
- teardown
- START_PARAMETRIZED_TEST
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #define TEST_SUITE_NAME "/lib/widget"
27
28 #include "tests/mctest.h"
29
30 #include "lib/strutil.h"
31 #include "lib/widget.h"
32
33
34
35 void complete_engine_fill_completions (WInput * in);
36 GPtrArray *try_complete (char *text, int *lc_start, int *lc_end, input_complete_t flags);
37
38
39
40
41 static char *try_complete__text__captured;
42
43 static int try_complete__lc_start__captured;
44
45 static int try_complete__lc_end__captured;
46
47 static input_complete_t try_complete__flags__captured;
48
49
50 static GPtrArray *try_complete__return_value;
51
52
53 GPtrArray *
54 try_complete (char *text, int *lc_start, int *lc_end, input_complete_t flags)
55 {
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;
60
61 return try_complete__return_value;
62 }
63
64 static void
65 try_complete__init (void)
66 {
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;
71 }
72
73 static void
74 try_complete__deinit (void)
75 {
76 g_free (try_complete__text__captured);
77 }
78
79
80
81
82 static void
83 setup (void)
84 {
85 str_init_strings (NULL);
86 try_complete__init ();
87 }
88
89
90
91
92 static void
93 teardown (void)
94 {
95 try_complete__deinit ();
96 str_uninit_strings ();
97 }
98
99
100
101
102
103 static const struct test_complete_engine_fill_completions_ds
104 {
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[] =
111 {
112 {
113 "string",
114 3,
115 INPUT_COMPLETE_NONE,
116 0,
117 3
118 },
119 {
120 "some string",
121 7,
122 INPUT_COMPLETE_NONE,
123 0,
124 7
125 },
126 {
127 "some string",
128 7,
129 INPUT_COMPLETE_SHELL_ESC,
130 5,
131 7
132 },
133 {
134 "some\\ string111",
135 9,
136 INPUT_COMPLETE_SHELL_ESC,
137 0,
138 9
139 },
140 {
141 "some\\\tstring111",
142 9,
143 INPUT_COMPLETE_SHELL_ESC,
144 0,
145 9
146 },
147 {
148 "some\tstring",
149 7,
150 INPUT_COMPLETE_NONE,
151 5,
152 7
153 },
154 {
155 "some;string",
156 7,
157 INPUT_COMPLETE_NONE,
158 5,
159 7
160 },
161 {
162 "some|string",
163 7,
164 INPUT_COMPLETE_NONE,
165 5,
166 7
167 },
168 {
169 "some<string",
170 7,
171 INPUT_COMPLETE_NONE,
172 5,
173 7
174 },
175 {
176 "some>string",
177 7,
178 INPUT_COMPLETE_NONE,
179 5,
180 7
181 },
182 {
183 "some!@#$%^&*()_\\+~`\"',./?:string",
184 30,
185 INPUT_COMPLETE_NONE,
186 0,
187 30
188 },
189 };
190
191
192
193
194 START_PARAMETRIZED_TEST (test_complete_engine_fill_completions,
195 test_complete_engine_fill_completions_ds)
196
197 {
198
199 WInput *w_input;
200
201 w_input = input_new (1, 1, NULL, 100, data->input_buffer, NULL, data->input_completion_flags);
202 w_input->point = data->input_point;
203
204
205 complete_engine_fill_completions (w_input);
206
207
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);
212 }
213
214 END_PARAMETRIZED_TEST
215
216
217
218
219 int
220 main (void)
221 {
222 TCase *tc_core;
223
224 tc_core = tcase_create ("Core");
225
226 tcase_add_checked_fixture (tc_core, setup, teardown);
227
228
229 mctest_add_parameterized_test (tc_core, test_complete_engine_fill_completions,
230 test_complete_engine_fill_completions_ds);
231
232
233 return mctest_run_all (tc_core);
234 }
235
236