summaryrefslogtreecommitdiff
path: root/src/tests/elementary/elm_code_test_text.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-06-02 17:19:08 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-06-02 17:19:08 -0700
commitd384012307881898a2df49f68fa6b46a4cd9972d (patch)
tree31706c65b8c56083a151470721cf36e8bb46939d /src/tests/elementary/elm_code_test_text.c
parent9f129a8711f9bb71ee7cf6c13f7965926255c975 (diff)
elementary: merging in elm_code widget.
Theme is not there as it should be manually merged into the elementary default theme.
Diffstat (limited to 'src/tests/elementary/elm_code_test_text.c')
-rw-r--r--src/tests/elementary/elm_code_test_text.c177
1 files changed, 177 insertions, 0 deletions
diff --git a/src/tests/elementary/elm_code_test_text.c b/src/tests/elementary/elm_code_test_text.c
new file mode 100644
index 0000000..934b98b
--- /dev/null
+++ b/src/tests/elementary/elm_code_test_text.c
@@ -0,0 +1,177 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#define ELM_INTERNAL_API_ARGESFSDFEFC
6
7#include "elm_suite.h"
8#include "Elementary.h"
9#include "elm_code_text.h"
10
11START_TEST (elm_code_text_get_test)
12{
13 Elm_Code *code;
14 Elm_Code_File *file;
15 Elm_Code_Line *line;
16
17 elm_init(1, NULL);
18 code = elm_code_create();
19 file = elm_code_file_new(code);
20
21 elm_code_file_line_append(file, "test", 4, NULL);
22 line = elm_code_file_line_get(file, 1);
23 ck_assert_str_eq("test", elm_code_line_text_get(line, NULL));
24 elm_shutdown();
25}
26END_TEST
27
28START_TEST (elm_code_text_insert_test)
29{
30 Elm_Code *code;
31 Elm_Code_File *file;
32 Elm_Code_Line *line;
33
34 elm_init(1, NULL);
35 code = elm_code_create();
36 file = elm_code_file_new(code);
37
38 elm_code_file_line_append(file, "test", 4, NULL);
39 line = elm_code_file_line_get(file, 1);
40
41 elm_code_line_text_insert(line, 4, "ing", 3);
42 ck_assert_str_eq("testing", elm_code_line_text_get(line, NULL));
43 elm_shutdown();
44}
45END_TEST
46
47START_TEST (elm_code_text_contains_test)
48{
49 Elm_Code *code;
50 Elm_Code_File *file;
51 Elm_Code_Line *line;
52
53 elm_init(1, NULL);
54 code = elm_code_create();
55 file = elm_code_file_new(code);
56
57 elm_code_file_line_append(file, "a test string...", 16, NULL);
58 line = elm_code_file_line_get(file, 1);
59
60 ck_assert_int_eq(EINA_TRUE, elm_code_line_text_contains(line, "test"));
61 ck_assert_int_eq(EINA_FALSE, elm_code_line_text_contains(line, "text"));
62
63 ck_assert_int_eq(EINA_TRUE, elm_code_line_text_contains(line, "a t"));
64 ck_assert_int_eq(EINA_TRUE, elm_code_line_text_contains(line, "..."));
65 elm_shutdown();
66}
67END_TEST
68
69START_TEST (elm_code_text_strpos_test)
70{
71 Elm_Code *code;
72 Elm_Code_File *file;
73 Elm_Code_Line *line;
74
75 elm_init(1, NULL);
76 code = elm_code_create();
77 file = elm_code_file_new(code);
78
79 elm_code_file_line_append(file, "a test string...", 16, NULL);
80 line = elm_code_file_line_get(file, 1);
81
82 ck_assert_int_eq(2, elm_code_line_text_strpos(line, "test", 0));
83 ck_assert_int_eq(2, elm_code_line_text_strpos(line, "test", 1));
84 ck_assert_int_eq(2, elm_code_line_text_strpos(line, "test", 2));
85 ck_assert_int_eq(ELM_CODE_TEXT_NOT_FOUND, elm_code_line_text_strpos(line, "test", 5));
86 ck_assert_int_eq(ELM_CODE_TEXT_NOT_FOUND, elm_code_line_text_strpos(line, "text", 0));
87
88 ck_assert_int_eq(0, elm_code_line_text_strpos(line, "a t", 0));
89 ck_assert_int_eq(ELM_CODE_TEXT_NOT_FOUND, elm_code_line_text_strpos(line, "a t", 2));
90 ck_assert_int_eq(13, elm_code_line_text_strpos(line, "...", 0));
91 elm_shutdown();
92}
93END_TEST
94
95START_TEST (elm_code_text_newline_position_test)
96{
97 short nllen;
98 const char *unixtext = "a test\nwith newline";
99 const char *wintext = "a windows\r\nnewline";
100
101 elm_init(1, NULL);
102 ck_assert_int_eq(6, elm_code_text_newlinenpos(unixtext, strlen(unixtext), &nllen));
103 ck_assert_int_eq(1, nllen);
104 ck_assert_int_eq(9, elm_code_text_newlinenpos(wintext, strlen(wintext), &nllen));
105 ck_assert_int_eq(2, nllen);
106 elm_shutdown();
107}
108END_TEST
109
110START_TEST (elm_code_text_leading_whitespace_test)
111{
112 const char *text;
113
114 elm_init(1, NULL);
115 text = "testing";
116 ck_assert_int_eq(0, elm_code_text_leading_whitespace_length(text, strlen(text)));
117
118 text = " spaces";
119 ck_assert_int_eq(2, elm_code_text_leading_whitespace_length(text, strlen(text)));
120
121 text = "\t\ttabs";
122 ck_assert_int_eq(2, elm_code_text_leading_whitespace_length(text, strlen(text)));
123
124 text = " \t mix";
125 ck_assert_int_eq(3, elm_code_text_leading_whitespace_length(text, strlen(text)));
126 elm_shutdown();
127}
128END_TEST
129
130START_TEST (elm_code_text_trailing_whitespace_test)
131{
132 const char *text;
133
134 elm_init(1, NULL);
135 text = "testing";
136 ck_assert_int_eq(0, elm_code_text_trailing_whitespace_length(text, strlen(text)));
137
138 text = "spaces ";
139 ck_assert_int_eq(2, elm_code_text_trailing_whitespace_length(text, strlen(text)));
140
141 text = "tabs\t\t";
142 ck_assert_int_eq(2, elm_code_text_trailing_whitespace_length(text, strlen(text)));
143
144 text = "mix \t ";
145 ck_assert_int_eq(3, elm_code_text_trailing_whitespace_length(text, strlen(text)));
146 elm_shutdown();
147}
148END_TEST
149
150START_TEST (elm_code_text_is_whitespace_test)
151{
152 const char *text;
153
154 elm_init(1, NULL);
155 text = " ";
156 ck_assert_int_eq(1, elm_code_text_is_whitespace(text, strlen(text)));
157
158 text = " \t\t ";
159 ck_assert_int_eq(1, elm_code_text_is_whitespace(text, strlen(text)));
160
161 text = " . ";
162 ck_assert_int_eq(0, elm_code_text_is_whitespace(text, strlen(text)));
163 elm_shutdown();
164}
165END_TEST
166
167void elm_code_test_text(TCase *tc)
168{
169 tcase_add_test(tc, elm_code_text_get_test);
170 tcase_add_test(tc, elm_code_text_insert_test);
171 tcase_add_test(tc, elm_code_text_contains_test);
172 tcase_add_test(tc, elm_code_text_strpos_test);
173 tcase_add_test(tc, elm_code_text_newline_position_test);
174 tcase_add_test(tc, elm_code_text_leading_whitespace_test);
175 tcase_add_test(tc, elm_code_text_trailing_whitespace_test);
176 tcase_add_test(tc, elm_code_text_is_whitespace_test);
177}