efl
233 строки · 5.9 Кб
1#ifdef HAVE_CONFIG_H2# include "elementary_config.h"3#endif4
5#include "elm_suite.h"6#include "Elementary.h"7#include "elm_code_indent.h"8
9static void10_indent_check(Elm_Code_File *file, const char *prev, const char *expected)11{
12Elm_Code_Line *line;13char *str;14
15elm_code_file_clear(file);16
17elm_code_file_line_append(file, prev, strlen(prev), NULL);18elm_code_file_line_append(file, "", 0, NULL);19line = elm_code_file_line_get(file, 2);20
21str = elm_code_line_indent_get(line);22ck_assert_str_eq(expected, str);23
24free(str);25}
26
27EFL_START_TEST(elm_code_indent_whitespace_test)28{
29Elm_Code *code;30Elm_Code_File *file;31
32char *args[] = { "exe" };33elm_init(1, args);34code = elm_code_create();35file = 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
42elm_shutdown();43}
44EFL_END_TEST
45
46EFL_START_TEST(elm_code_indent_comments_test)47{
48Elm_Code *code;49Elm_Code_File *file;50
51char *args[] = { "exe" };52elm_init(1, args);53code = elm_code_create();54file = 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 comments62_indent_check(file, " / ", " ");63_indent_check(file, " hi//", " ");64
65elm_shutdown();66}
67EFL_END_TEST
68
69EFL_START_TEST(elm_code_indent_simple_braces)70{
71Elm_Code *code;72Elm_Code_File *file;73
74char *args[] = { "exe" };75elm_init(1, args);76code = elm_code_create();77file = elm_code_file_new(code);78code->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
86elm_shutdown();87}
88EFL_END_TEST
89
90EFL_START_TEST(elm_code_indent_tab_simple_braces)91{
92Elm_Code *code;93Elm_Code_File *file;94
95elm_init(1, NULL);96code = elm_code_create();97file = elm_code_file_new(code);98code->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
106elm_shutdown();107}
108EFL_END_TEST
109
110EFL_START_TEST(elm_code_indent_matching_braces)111{
112Elm_Code_File *file;113Elm_Code_Line *line;114Elm_Code *code;115const char *str;116unsigned int str_len;117
118char *args[] = { "exe" };119elm_init(1, args);120code = elm_code_create();121file = elm_code_file_new(code);122
123elm_code_file_line_append(file, "", 0, NULL);124line = elm_code_file_line_get(file, 1);125
126elm_code_file_line_insert(file, 1, " if ()", 8, NULL);127str = elm_code_line_indent_matching_braces_get(line, &str_len);128ck_assert_strn_eq(str, "", str_len);129
130elm_code_file_line_insert(file, 2, " {", 6, NULL);131str = elm_code_line_indent_matching_braces_get(line, &str_len);132ck_assert_int_eq(str_len, 5);133ck_assert_strn_eq(str, " ", str_len);134
135elm_code_file_line_insert(file, 3, " if (){", 14, NULL);136str = elm_code_line_indent_matching_braces_get(line, &str_len);137ck_assert_int_eq(str_len, 8);138ck_assert_strn_eq(str, " ", str_len);139
140elm_code_file_line_insert(file, 4, " }", 9, NULL);141str = elm_code_line_indent_matching_braces_get(line, &str_len);142ck_assert_int_eq(str_len, 5);143ck_assert_strn_eq(str, " ", str_len);144
145elm_code_file_line_insert(file, 5, " }", 6, NULL);146str = elm_code_line_indent_matching_braces_get(line, &str_len);147ck_assert_strn_eq(str, "", str_len);148
149elm_code_free(code);150elm_shutdown();151}
152EFL_END_TEST
153
154EFL_START_TEST(elm_code_indent_tab_matching_braces)155{
156Elm_Code_File *file;157Elm_Code_Line *line;158Elm_Code *code;159const char *str;160unsigned int str_len;161
162elm_init(1, NULL);163code = elm_code_create();164file = elm_code_file_new(code);165
166elm_code_file_line_append(file, "", 0, NULL);167line = elm_code_file_line_get(file, 1);168
169elm_code_file_line_insert(file, 1, "\tif ()", 6, NULL);170str = elm_code_line_indent_matching_braces_get(line, &str_len);171ck_assert_strn_eq(str, "", str_len);172
173elm_code_file_line_insert(file, 2, "\t{", 2, NULL);174str = elm_code_line_indent_matching_braces_get(line, &str_len);175ck_assert_int_eq(str_len, 1);176ck_assert_strn_eq(str, "\t", str_len);177
178elm_code_file_line_insert(file, 3, "\t}", 2, NULL);179str = elm_code_line_indent_matching_braces_get(line, &str_len);180ck_assert_strn_eq(str, "", str_len);181
182elm_code_free(code);183elm_shutdown();184}
185EFL_END_TEST
186
187EFL_START_TEST(elm_code_indent_startswith_keyword)188{
189Elm_Code_File *file;190Elm_Code *code;191
192char *args[] = { "exe" };193elm_init(1, args);194code = elm_code_create();195file = 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
219elm_code_free(code);220elm_shutdown();221}
222EFL_END_TEST
223
224void elm_code_test_indent(TCase *tc)225{
226tcase_add_test(tc, elm_code_indent_whitespace_test);227tcase_add_test(tc, elm_code_indent_comments_test);228tcase_add_test(tc, elm_code_indent_tab_simple_braces);229tcase_add_test(tc, elm_code_indent_simple_braces);230tcase_add_test(tc, elm_code_indent_matching_braces);231tcase_add_test(tc, elm_code_indent_tab_matching_braces);232tcase_add_test(tc, elm_code_indent_startswith_keyword);233}
234