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 static const struct test_complete_engine_fill_completions_ds
103 {
104 const char *input_buffer;
105 const int input_point;
106 const input_complete_t input_completion_flags;
107 int expected_start;
108 int expected_end;
109 } test_complete_engine_fill_completions_ds[] = {
110 { "string", 3, INPUT_COMPLETE_NONE, 0, 3 },
111 { "some string", 7, INPUT_COMPLETE_NONE, 0, 7 },
112 { "some string", 7, INPUT_COMPLETE_SHELL_ESC, 5, 7 },
113 { "some\\ string111", 9, INPUT_COMPLETE_SHELL_ESC, 0, 9 },
114 { "some\\\tstring111", 9, INPUT_COMPLETE_SHELL_ESC, 0, 9 },
115 { "some\tstring", 7, INPUT_COMPLETE_NONE, 5, 7 },
116 { "some;string", 7, INPUT_COMPLETE_NONE, 5, 7 },
117 { "some|string", 7, INPUT_COMPLETE_NONE, 5, 7 },
118 { "some<string", 7, INPUT_COMPLETE_NONE, 5, 7 },
119 { "some>string", 7, INPUT_COMPLETE_NONE, 5, 7 },
120 { "some!@#$%^&*()_\\+~`\"',./?:string", 30, INPUT_COMPLETE_NONE, 0, 30 },
121 };
122
123
124 START_PARAMETRIZED_TEST (test_complete_engine_fill_completions,
125 test_complete_engine_fill_completions_ds)
126 {
127
128 WInput *w_input;
129
130 w_input = input_new (1, 1, NULL, 100, data->input_buffer, NULL, data->input_completion_flags);
131 w_input->point = data->input_point;
132
133
134 complete_engine_fill_completions (w_input);
135
136
137 mctest_assert_str_eq (try_complete__text__captured, data->input_buffer);
138 ck_assert_int_eq (try_complete__lc_start__captured, data->expected_start);
139 ck_assert_int_eq (try_complete__lc_end__captured, data->expected_end);
140 ck_assert_int_eq (try_complete__flags__captured, data->input_completion_flags);
141 }
142 END_PARAMETRIZED_TEST
143
144
145
146 int
147 main (void)
148 {
149 TCase *tc_core;
150
151 tc_core = tcase_create ("Core");
152
153 tcase_add_checked_fixture (tc_core, setup, teardown);
154
155
156 mctest_add_parameterized_test (tc_core, test_complete_engine_fill_completions,
157 test_complete_engine_fill_completions_ds);
158
159
160 return mctest_run_all (tc_core);
161 }
162
163