efl

Форк
0
/
elm_code_test_indent.c 
233 строки · 5.9 Кб
1
#ifdef HAVE_CONFIG_H
2
# include "elementary_config.h"
3
#endif
4

5
#include "elm_suite.h"
6
#include "Elementary.h"
7
#include "elm_code_indent.h"
8

9
static void
10
_indent_check(Elm_Code_File *file, const char *prev, const char *expected)
11
{
12
   Elm_Code_Line *line;
13
   char *str;
14

15
   elm_code_file_clear(file);
16

17
   elm_code_file_line_append(file, prev, strlen(prev), NULL);
18
   elm_code_file_line_append(file, "", 0, NULL);
19
   line = elm_code_file_line_get(file, 2);
20

21
   str = elm_code_line_indent_get(line);
22
   ck_assert_str_eq(expected, str);
23

24
   free(str);
25
}
26

27
EFL_START_TEST(elm_code_indent_whitespace_test)
28
{
29
   Elm_Code *code;
30
   Elm_Code_File *file;
31

32
   char *args[] = { "exe" };
33
   elm_init(1, args);
34
   code = elm_code_create();
35
   file = elm_code_file_new(code);
36

37
   _indent_check(file, "", "");
38
   _indent_check(file, "  ", "  ");
39
   _indent_check(file, "\t", "\t");
40
   _indent_check(file, "\t  ", "\t  ");
41

42
   elm_shutdown();
43
}
44
EFL_END_TEST
45

46
EFL_START_TEST(elm_code_indent_comments_test)
47
{
48
   Elm_Code *code;
49
   Elm_Code_File *file;
50

51
   char *args[] = { "exe" };
52
   elm_init(1, args);
53
   code = elm_code_create();
54
   file = elm_code_file_new(code);
55

56
   _indent_check(file, " /**", "  * ");
57
   _indent_check(file, "  * ", "  * ");
58
   _indent_check(file, "  */", " ");
59
   _indent_check(file, "\t//", "\t//");
60

61
   // test these are not comments
62
   _indent_check(file, " / ", " ");
63
   _indent_check(file, " hi//", " ");
64

65
   elm_shutdown();
66
}
67
EFL_END_TEST
68

69
EFL_START_TEST(elm_code_indent_simple_braces)
70
{
71
   Elm_Code *code;
72
   Elm_Code_File *file;
73

74
   char *args[] = { "exe" };
75
   elm_init(1, args);
76
   code = elm_code_create();
77
   file = elm_code_file_new(code);
78
   code->config.indent_style_efl = EINA_TRUE;
79

80
   _indent_check(file, "if() {", "     ");
81
   _indent_check(file, "}", "");
82

83
   _indent_check(file, "  {", "     ");
84
   _indent_check(file, "  }", "");
85

86
   elm_shutdown();
87
}
88
EFL_END_TEST
89

90
EFL_START_TEST(elm_code_indent_tab_simple_braces)
91
{
92
   Elm_Code *code;
93
   Elm_Code_File *file;
94

95
   elm_init(1, NULL);
96
   code = elm_code_create();
97
   file = elm_code_file_new(code);
98
   code->config.indent_style_efl = EINA_FALSE;
99

100
   _indent_check(file, "if() {", "\t");
101
   _indent_check(file, "}", "");
102

103
   _indent_check(file, "\t{", "\t\t");
104
   _indent_check(file, "\t}", "\t");
105

106
   elm_shutdown();
107
}
108
EFL_END_TEST
109

110
EFL_START_TEST(elm_code_indent_matching_braces)
111
{
112
   Elm_Code_File *file;
113
   Elm_Code_Line *line;
114
   Elm_Code *code;
115
   const char *str;
116
   unsigned int str_len;
117

118
   char *args[] = { "exe" };
119
   elm_init(1, args);
120
   code = elm_code_create();
121
   file = elm_code_file_new(code);
122

123
   elm_code_file_line_append(file, "", 0, NULL);
124
   line = elm_code_file_line_get(file, 1);
125

126
   elm_code_file_line_insert(file, 1, "   if ()", 8, NULL);
127
   str = elm_code_line_indent_matching_braces_get(line, &str_len);
128
   ck_assert_strn_eq(str, "", str_len);
129

130
   elm_code_file_line_insert(file, 2, "     {", 6, NULL);
131
   str = elm_code_line_indent_matching_braces_get(line, &str_len);
132
   ck_assert_int_eq(str_len, 5);
133
   ck_assert_strn_eq(str, "     ", str_len);
134

135
   elm_code_file_line_insert(file, 3, "        if (){", 14, NULL);
136
   str = elm_code_line_indent_matching_braces_get(line, &str_len);
137
   ck_assert_int_eq(str_len, 8);
138
   ck_assert_strn_eq(str, "        ", str_len);
139

140
   elm_code_file_line_insert(file, 4, "        }", 9, NULL);
141
   str = elm_code_line_indent_matching_braces_get(line, &str_len);
142
   ck_assert_int_eq(str_len, 5);
143
   ck_assert_strn_eq(str, "     ", str_len);
144

145
   elm_code_file_line_insert(file, 5, "     }", 6, NULL);
146
   str = elm_code_line_indent_matching_braces_get(line, &str_len);
147
   ck_assert_strn_eq(str, "", str_len);
148

149
   elm_code_free(code);
150
   elm_shutdown();
151
}
152
EFL_END_TEST
153

154
EFL_START_TEST(elm_code_indent_tab_matching_braces)
155
{
156
   Elm_Code_File *file;
157
   Elm_Code_Line *line;
158
   Elm_Code *code;
159
   const char *str;
160
   unsigned int str_len;
161

162
   elm_init(1, NULL);
163
   code = elm_code_create();
164
   file = elm_code_file_new(code);
165

166
   elm_code_file_line_append(file, "", 0, NULL);
167
   line = elm_code_file_line_get(file, 1);
168

169
   elm_code_file_line_insert(file, 1, "\tif ()", 6, NULL);
170
   str = elm_code_line_indent_matching_braces_get(line, &str_len);
171
   ck_assert_strn_eq(str, "", str_len);
172

173
   elm_code_file_line_insert(file, 2, "\t{", 2, NULL);
174
   str = elm_code_line_indent_matching_braces_get(line, &str_len);
175
   ck_assert_int_eq(str_len, 1);
176
   ck_assert_strn_eq(str, "\t", str_len);
177

178
   elm_code_file_line_insert(file, 3, "\t}", 2, NULL);
179
   str = elm_code_line_indent_matching_braces_get(line, &str_len);
180
   ck_assert_strn_eq(str, "", str_len);
181

182
   elm_code_free(code);
183
   elm_shutdown();
184
}
185
EFL_END_TEST
186

187
EFL_START_TEST(elm_code_indent_startswith_keyword)
188
{
189
   Elm_Code_File *file;
190
   Elm_Code *code;
191

192
   char *args[] = { "exe" };
193
   elm_init(1, args);
194
   code = elm_code_create();
195
   file = elm_code_file_new(code);
196

197
   _indent_check(file, "if ()", "  ");
198
   _indent_check(file, "else", "  ");
199
   _indent_check(file, "else if ()", "  ");
200
   _indent_check(file, "for ()", "  ");
201
   _indent_check(file, "while ()", "  ");
202
   _indent_check(file, "do", "  ");
203
   _indent_check(file, "do {", "     ");
204

205
   _indent_check(file, "  switch ()", "    ");
206
   _indent_check(file, "   case a:", "     ");
207
   _indent_check(file, "   default:", "     ");
208

209
   _indent_check(file, "if ();", "");
210
   _indent_check(file, "  for ();", "  ");
211

212
   _indent_check(file, "  iffy()", "  ");
213
   _indent_check(file, "  fi()", "  ");
214
   _indent_check(file, "  elihw", "  ");
215

216
   _indent_check(file, "   if", "   ");
217
   _indent_check(file, "   while", "   ");
218

219
   elm_code_free(code);
220
   elm_shutdown();
221
}
222
EFL_END_TEST
223

224
void elm_code_test_indent(TCase *tc)
225
{
226
   tcase_add_test(tc, elm_code_indent_whitespace_test);
227
   tcase_add_test(tc, elm_code_indent_comments_test);
228
   tcase_add_test(tc, elm_code_indent_tab_simple_braces);
229
   tcase_add_test(tc, elm_code_indent_simple_braces);
230
   tcase_add_test(tc, elm_code_indent_matching_braces);
231
   tcase_add_test(tc, elm_code_indent_tab_matching_braces);
232
   tcase_add_test(tc, elm_code_indent_startswith_keyword);
233
}
234

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.