summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2016-06-05 11:12:13 +0100
committerTom Hacohen <tom@stosb.com>2016-06-06 14:28:16 +0100
commit8809ed16298e0a72e869ba781b34fe10766eaeb6 (patch)
treef180bb44a248a89f6bb9f1c9490193b0ea4dc15e /src/tests
parent14c8ddc678ccc9c7eea06429692e80d312ae5d6b (diff)
parent412071497d507715387c19ea5e0aab4c4964b99f (diff)
Merge elm code, a code editing widget into the efl
It was decided to merge this and mark the code as BETA for now. It's currently being used by EDI and should also be used by enventor and etc.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/elementary/elm_code_file_test_load.c162
-rw-r--r--src/tests/elementary/elm_code_file_test_memory.c49
-rw-r--r--src/tests/elementary/elm_code_test_basic.c28
-rw-r--r--src/tests/elementary/elm_code_test_line.c83
-rw-r--r--src/tests/elementary/elm_code_test_parse.c102
-rw-r--r--src/tests/elementary/elm_code_test_text.c177
-rw-r--r--src/tests/elementary/elm_code_test_widget.c93
-rw-r--r--src/tests/elementary/elm_code_test_widget_selection.c643
-rw-r--r--src/tests/elementary/elm_code_test_widget_text.c62
-rw-r--r--src/tests/elementary/elm_code_test_widget_undo.c165
-rw-r--r--src/tests/elementary/elm_suite.c9
-rw-r--r--src/tests/elementary/elm_suite.h11
-rw-r--r--src/tests/elementary/elm_test_helper.h13
-rw-r--r--src/tests/elementary/testdiff.diff10
-rw-r--r--src/tests/elementary/testfile-windows.txt4
-rw-r--r--src/tests/elementary/testfile-withblanks.txt8
-rw-r--r--src/tests/elementary/testfile.txt4
17 files changed, 1623 insertions, 0 deletions
diff --git a/src/tests/elementary/elm_code_file_test_load.c b/src/tests/elementary/elm_code_file_test_load.c
new file mode 100644
index 0000000000..7e21b235f1
--- /dev/null
+++ b/src/tests/elementary/elm_code_file_test_load.c
@@ -0,0 +1,162 @@
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
10START_TEST (elm_code_file_load)
11{
12 char *path = TESTS_SRC_DIR "/testfile.txt";
13 char real[EINA_PATH_MAX];
14 Elm_Code_File *file;
15 Elm_Code *code;
16
17 elm_init(1, NULL);
18 code = elm_code_create();
19 file = elm_code_file_open(code, path);
20 realpath(path, real);
21
22 ck_assert_str_eq(basename(path), elm_code_file_filename_get(file));
23 ck_assert_str_eq(real, elm_code_file_path_get(file));
24 elm_code_file_close(file);
25 elm_code_free(code);
26 elm_shutdown();
27}
28END_TEST
29
30START_TEST (elm_code_file_load_lines)
31{
32 char *path = TESTS_SRC_DIR "/testfile.txt";
33 Elm_Code_File *file;
34 Elm_Code *code;
35
36 elm_init(1, NULL);
37 code = elm_code_create();
38 file = elm_code_file_open(code, path);
39
40 ck_assert_uint_eq(4, elm_code_file_lines_get(file));
41 elm_code_file_close(file);
42 elm_code_free(code);
43 elm_shutdown();
44}
45END_TEST
46
47START_TEST (elm_code_file_load_blank_lines)
48{
49 char *path = TESTS_SRC_DIR "/testfile-withblanks.txt";
50 Elm_Code_File *file;
51 Elm_Code *code;
52
53 elm_init(1, NULL);
54 code = elm_code_create();
55 file = elm_code_file_open(code, path);
56
57 ck_assert_uint_eq(8, elm_code_file_lines_get(file));
58 elm_code_file_close(file);
59 elm_code_free(code);
60 elm_shutdown();
61}
62END_TEST
63
64START_TEST (elm_code_file_load_windows)
65{
66 char *path = TESTS_SRC_DIR "/testfile-windows.txt";
67 Elm_Code_File *file;
68 Elm_Code *code;
69
70 elm_init(1, NULL);
71 code = elm_code_create();
72 file = elm_code_file_open(code, path);
73
74 ck_assert_uint_eq(4, elm_code_file_lines_get(file));
75 elm_code_file_close(file);
76 elm_code_free(code);
77 elm_shutdown();
78}
79END_TEST
80
81static void _assert_line_content_eq(const char *content, Elm_Code_Line *line)
82{
83 int length;
84 int c;
85
86 length = strlen(content);
87 ck_assert_int_eq(length, line->length);
88
89 for (c = 0; c < length; c++)
90 ck_assert_uint_eq(content[c], line->content[c]);
91}
92
93START_TEST (elm_code_file_load_content)
94{
95 char *path = TESTS_SRC_DIR "/testfile.txt";
96 Elm_Code_File *file;
97 Elm_Code *code;
98
99 elm_init(1, NULL);
100 code = elm_code_create();
101 file = elm_code_file_open(code, path);
102
103 _assert_line_content_eq("line2", elm_code_file_line_get(file, 2));
104 _assert_line_content_eq("another line", elm_code_file_line_get(file, 4));
105 elm_code_file_close(file);
106 elm_code_free(code);
107 elm_shutdown();
108}
109END_TEST
110
111START_TEST (elm_code_file_line_ending_unix)
112{
113 char *path = TESTS_SRC_DIR "/testfile.txt";
114 Elm_Code_File *file;
115 Elm_Code *code;
116 short len;
117
118 elm_init(1, NULL);
119 code = elm_code_create();
120 file = elm_code_file_open(code, path);
121
122 ck_assert_int_eq(ELM_CODE_FILE_LINE_ENDING_UNIX, elm_code_file_line_ending_get(file));
123 ck_assert_str_eq("\n", elm_code_file_line_ending_chars_get(file, &len));
124 ck_assert_int_eq(1, len);
125
126 elm_code_file_close(file);
127 elm_code_free(code);
128 elm_shutdown();
129}
130END_TEST
131
132START_TEST (elm_code_file_line_ending_windows)
133{
134 char *path = TESTS_SRC_DIR "/testfile-windows.txt";
135 Elm_Code_File *file;
136 Elm_Code *code;
137 short len;
138
139 elm_init(1, NULL);
140 code = elm_code_create();
141 file = elm_code_file_open(code, path);
142
143 ck_assert_int_eq(ELM_CODE_FILE_LINE_ENDING_WINDOWS, elm_code_file_line_ending_get(file));
144 ck_assert_str_eq("\r\n", elm_code_file_line_ending_chars_get(file, &len));
145 ck_assert_int_eq(2, len);
146
147 elm_code_file_close(file);
148 elm_code_free(code);
149 elm_shutdown();
150}
151END_TEST
152
153void elm_code_file_test_load(TCase *tc)
154{
155 tcase_add_test(tc, elm_code_file_load);
156 tcase_add_test(tc, elm_code_file_load_lines);
157 tcase_add_test(tc, elm_code_file_load_blank_lines);
158 tcase_add_test(tc, elm_code_file_load_windows);
159 tcase_add_test(tc, elm_code_file_load_content);
160 tcase_add_test(tc, elm_code_file_line_ending_unix);
161 tcase_add_test(tc, elm_code_file_line_ending_windows);
162}
diff --git a/src/tests/elementary/elm_code_file_test_memory.c b/src/tests/elementary/elm_code_file_test_memory.c
new file mode 100644
index 0000000000..f39228d427
--- /dev/null
+++ b/src/tests/elementary/elm_code_file_test_memory.c
@@ -0,0 +1,49 @@
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
10START_TEST (elm_code_file_memory_lines)
11{
12 Elm_Code *code;
13
14 elm_init(1, NULL);
15 code = elm_code_create();
16 ck_assert_uint_eq(0, elm_code_file_lines_get(code->file));
17
18 elm_code_file_line_append(code->file, "a line", 6, NULL);
19
20 ck_assert_uint_eq(1, elm_code_file_lines_get(code->file));
21 elm_code_free(code);
22 elm_shutdown();
23}
24END_TEST
25
26START_TEST (elm_code_file_memory_tokens)
27{
28 Elm_Code_File *file;
29 Elm_Code_Line *line;
30 Elm_Code *code;
31
32 elm_init(1, NULL);
33 code = elm_code_create();
34 file = code->file;
35 elm_code_file_line_append(file, "a line", 6, NULL);
36
37 line = elm_code_file_line_get(file, 1);
38 elm_code_line_token_add(line, 2, 5, 1, ELM_CODE_TOKEN_TYPE_COMMENT);
39 ck_assert_uint_eq(1, eina_list_count(line->tokens));
40 elm_code_free(code);
41 elm_shutdown();
42}
43END_TEST
44
45void elm_code_file_test_memory(TCase *tc)
46{
47 tcase_add_test(tc, elm_code_file_memory_lines);
48 tcase_add_test(tc, elm_code_file_memory_tokens);
49}
diff --git a/src/tests/elementary/elm_code_test_basic.c b/src/tests/elementary/elm_code_test_basic.c
new file mode 100644
index 0000000000..9805a7508b
--- /dev/null
+++ b/src/tests/elementary/elm_code_test_basic.c
@@ -0,0 +1,28 @@
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
10START_TEST (elm_code_create_test)
11{
12 char *path = TESTS_SRC_DIR "/testfile.txt";
13 Elm_Code *code;
14
15 elm_init(1, NULL);
16 code = elm_code_create();
17 elm_code_file_open(code, path);
18
19 ck_assert(!!code);
20 elm_code_free(code);
21 elm_shutdown();
22}
23END_TEST
24
25void elm_code_test_basic(TCase *tc)
26{
27 tcase_add_test(tc, elm_code_create_test);
28}
diff --git a/src/tests/elementary/elm_code_test_line.c b/src/tests/elementary/elm_code_test_line.c
new file mode 100644
index 0000000000..cdbc628079
--- /dev/null
+++ b/src/tests/elementary/elm_code_test_line.c
@@ -0,0 +1,83 @@
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
10START_TEST (elm_code_line_create_test)
11{
12 Elm_Code *code;
13 Elm_Code_File *file;
14 Elm_Code_Line *line;
15
16 elm_init(1, NULL);
17 code = elm_code_create();
18 file = elm_code_file_new(code);
19
20 elm_code_file_line_append(file, "a test string...", 16, NULL);
21 line = elm_code_file_line_get(file, 1);
22
23 ck_assert(!!line);
24
25 elm_code_free(code);
26 elm_shutdown();
27}
28END_TEST
29
30START_TEST (elm_code_line_token_count_test)
31{
32 Elm_Code *code;
33 Elm_Code_File *file;
34 Elm_Code_Line *line;
35
36 elm_init(1, NULL);
37 code = elm_code_create();
38 file = elm_code_file_new(code);
39
40 elm_code_file_line_append(file, "a test string...", 16, NULL);
41 line = elm_code_file_line_get(file, 1);
42
43 ck_assert_int_eq(0, eina_list_count(line->tokens));
44 elm_code_line_token_add(line, 2, 5, 1, ELM_CODE_TOKEN_TYPE_COMMENT);
45 ck_assert_int_eq(1, eina_list_count(line->tokens));
46 elm_code_line_tokens_clear(line);
47 ck_assert_int_eq(0, eina_list_count(line->tokens));
48
49 elm_code_free(code);
50 elm_shutdown();
51}
52END_TEST
53
54START_TEST (elm_code_line_split_test)
55{
56 Elm_Code *code;
57 Elm_Code_File *file;
58 Elm_Code_Line *line, *newline;
59
60 elm_init(1, NULL);
61 code = elm_code_create();
62 file = elm_code_file_new(code);
63
64 elm_code_file_line_append(file, "line1line2", 10, NULL);
65 line = elm_code_file_line_get(file, 1);
66 ck_assert_int_eq(1, elm_code_file_lines_get(file));
67 ck_assert_int_eq(10, line->length);
68
69 elm_code_line_split_at(line, 5);
70 ck_assert_int_eq(2, elm_code_file_lines_get(file));
71 newline = elm_code_file_line_get(file, 2);
72 ck_assert_int_eq(5, line->length);
73 ck_assert_int_eq(5, newline->length);
74 elm_shutdown();
75}
76END_TEST
77
78void elm_code_test_line(TCase *tc)
79{
80 tcase_add_test(tc, elm_code_line_create_test);
81 tcase_add_test(tc, elm_code_line_token_count_test);
82 tcase_add_test(tc, elm_code_line_split_test);
83}
diff --git a/src/tests/elementary/elm_code_test_parse.c b/src/tests/elementary/elm_code_test_parse.c
new file mode 100644
index 0000000000..4bd35b4b88
--- /dev/null
+++ b/src/tests/elementary/elm_code_test_parse.c
@@ -0,0 +1,102 @@
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_parse.h"
10
11static int line_calls, file_calls;
12
13static void _parser_line_callback(Elm_Code_Line *line EINA_UNUSED, void *data EINA_UNUSED)
14{
15 line_calls++;
16}
17
18static void _parser_file_callback(Elm_Code_File *file EINA_UNUSED, void *data EINA_UNUSED)
19{
20 file_calls++;
21}
22
23START_TEST (elm_code_parse_hook_memory_test)
24{
25 Elm_Code *code;
26 Elm_Code_File *file;
27
28 line_calls = 0;
29 file_calls = 0;
30
31 elm_init(1, NULL);
32 code = elm_code_create();
33 file = elm_code_file_new(code);
34
35 elm_code_parser_add(code, _parser_line_callback, _parser_file_callback, NULL);
36 elm_code_file_line_append(file, "some \"test content\" for parsing", 31, NULL);
37
38 ck_assert_int_eq(1, line_calls);
39 ck_assert_int_eq(0, file_calls);
40
41 elm_code_free(code);
42 elm_shutdown();
43}
44END_TEST
45
46START_TEST (elm_code_parse_hook_file_test)
47{
48 Elm_Code *code;
49 Elm_Code_File *file;
50 char *path = TESTS_SRC_DIR "testfile.txt";
51
52 line_calls = 0;
53 file_calls = 0;
54
55 elm_init(1, NULL);
56 code = elm_code_create();
57
58 elm_code_parser_add(code, _parser_line_callback, _parser_file_callback, NULL);
59 file = elm_code_file_open(code, path);
60
61 ck_assert_int_eq(4, line_calls);
62 ck_assert_int_eq(1, file_calls);
63
64 elm_code_file_close(file);
65 elm_code_free(code);
66 elm_shutdown();
67}
68END_TEST
69
70START_TEST (elm_code_parse_todo_test)
71{
72 Elm_Code *code;
73 Elm_Code_File *file;
74 Elm_Code_Line *line;
75
76 elm_init(1, NULL);
77 elm_code_init();
78
79 code = elm_code_create();
80 elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_TODO);
81 file = elm_code_file_new(code);
82
83 elm_code_file_line_append(file, "xxx TODO line", 13, NULL);
84 line = elm_code_file_line_get(file, 1);
85 ck_assert_int_eq(ELM_CODE_STATUS_TYPE_TODO, line->status);
86
87 elm_code_line_text_set(line, "FIXME too", 9);
88 ck_assert_int_eq(ELM_CODE_STATUS_TYPE_TODO, line->status);
89
90 elm_code_line_text_set(line, "TOFIX", 5);
91 ck_assert_int_eq(ELM_CODE_STATUS_TYPE_DEFAULT, line->status);
92 elm_code_shutdown();
93 elm_shutdown();
94}
95END_TEST
96
97void elm_code_test_parse(TCase *tc)
98{
99 tcase_add_test(tc, elm_code_parse_hook_memory_test);
100 tcase_add_test(tc, elm_code_parse_hook_file_test);
101 tcase_add_test(tc, elm_code_parse_todo_test);
102}
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 0000000000..934b98b425
--- /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}
diff --git a/src/tests/elementary/elm_code_test_widget.c b/src/tests/elementary/elm_code_test_widget.c
new file mode 100644
index 0000000000..660015363e
--- /dev/null
+++ b/src/tests/elementary/elm_code_test_widget.c
@@ -0,0 +1,93 @@
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_widget.c"
10
11static void _assert_cell_type(Evas_Textgrid_Cell cell, Elm_Code_Token_Type type, int id)
12{
13 ck_assert_msg(cell.fg == type, "Wrong type for cell %d", id);
14}
15
16START_TEST (elm_code_widget_token_render_simple_test)
17{
18 Elm_Code_File *file;
19 Elm_Code_Line *line;
20 Elm_Code *code;
21 Elm_Code_Widget *widget;
22 Evas_Object *win;
23
24 int length;
25
26 Evas_Textgrid_Cell cells[25];
27
28 elm_init(1, NULL);
29 code = elm_code_create();
30
31 win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
32 widget = elm_code_widget_add(win, code);
33
34 file = code->file;
35 elm_code_file_line_append(file, "some \"test content\", 45", 23, NULL);
36 line = elm_code_file_line_get(file, 1);
37 length = line->length;
38
39 elm_code_line_token_add(line, 6, 17, 1, ELM_CODE_TOKEN_TYPE_COMMENT);
40 elm_code_line_token_add(line, 21, 22, 1, ELM_CODE_TOKEN_TYPE_COMMENT);
41
42 _elm_code_widget_fill_line_tokens(widget, cells, length+1, line);
43 _assert_cell_type(cells[1], ELM_CODE_TOKEN_TYPE_DEFAULT, 1);
44 _assert_cell_type(cells[4], ELM_CODE_TOKEN_TYPE_DEFAULT, 4);
45 _assert_cell_type(cells[5], ELM_CODE_TOKEN_TYPE_DEFAULT, 5);
46 _assert_cell_type(cells[16], ELM_CODE_TOKEN_TYPE_COMMENT, 16);
47 _assert_cell_type(cells[20], ELM_CODE_TOKEN_TYPE_DEFAULT, 20);
48 _assert_cell_type(cells[22], ELM_CODE_TOKEN_TYPE_COMMENT, 22);
49
50 elm_code_free(code);
51 elm_shutdown();
52}
53END_TEST
54
55START_TEST (elm_code_widget_construct)
56{
57 Elm_Code *code;
58 Elm_Code_Widget *widget;
59 Evas_Object *win;
60
61 elm_init(1, NULL);
62 code = elm_code_create();
63
64 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
65 widget = elm_code_widget_add(win, code);
66
67 ck_assert(!!widget);
68 elm_code_free(code);
69 elm_shutdown();
70}
71END_TEST
72
73START_TEST (elm_code_widget_construct_nocode)
74{
75 Elm_Code_Widget *widget;
76 Evas_Object *win;
77
78 elm_init(1, NULL);
79
80 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
81 widget = eo_add(ELM_CODE_WIDGET_CLASS, win);
82 ck_assert(!widget);
83
84 elm_shutdown();
85}
86END_TEST
87
88void elm_code_test_widget(TCase *tc)
89{
90 tcase_add_test(tc, elm_code_widget_token_render_simple_test);
91 tcase_add_test(tc, elm_code_widget_construct);
92 tcase_add_test(tc, elm_code_widget_construct_nocode);
93}
diff --git a/src/tests/elementary/elm_code_test_widget_selection.c b/src/tests/elementary/elm_code_test_widget_selection.c
new file mode 100644
index 0000000000..e181e6e14d
--- /dev/null
+++ b/src/tests/elementary/elm_code_test_widget_selection.c
@@ -0,0 +1,643 @@
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_widget_private.h"
10#include "elm_code_widget_selection.h"
11
12START_TEST (elm_code_test_widget_selection_set)
13{
14 Elm_Code *code;
15 Elm_Code_File *file;
16 Elm_Code_Widget *widget;
17 Evas_Object *win;
18
19 elm_init(1, NULL);
20 code = elm_code_create();
21 file = elm_code_file_new(code);
22 elm_code_file_line_append(file, "test", 4, NULL);
23
24 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
25 widget = elm_code_widget_add(win, code);
26
27 elm_code_widget_selection_start(widget, 1, 2);
28 elm_code_widget_selection_end(widget, 1, 3);
29 elm_code_widget_selection_clear(widget);
30
31 elm_code_free(code);
32 elm_shutdown();
33}
34END_TEST
35
36START_TEST (elm_code_test_widget_selection_normalized_get)
37{
38 Elm_Code *code;
39 Elm_Code_File *file;
40 Elm_Code_Widget *widget;
41 Elm_Code_Widget_Selection_Data *selection;
42 Evas_Object *win;
43
44 elm_init(1, NULL);
45 code = elm_code_create();
46 file = elm_code_file_new(code);
47 elm_code_file_line_append(file, "test", 4, NULL);
48
49 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
50 widget = elm_code_widget_add(win, code);
51
52 elm_code_widget_selection_start(widget, 1, 3);
53 elm_code_widget_selection_end(widget, 1, 2);
54 selection = elm_code_widget_selection_normalized_get(widget);
55
56 ck_assert_int_eq(selection->start_col, 2);
57 ck_assert_int_eq(selection->end_col, 3);
58 elm_code_widget_selection_clear(widget);
59 free(selection);
60
61 elm_code_file_line_append(file, "another", 7, NULL);
62 elm_code_widget_selection_start(widget, 2, 2);
63 elm_code_widget_selection_end(widget, 1, 3);
64 selection = elm_code_widget_selection_normalized_get(widget);
65
66 ck_assert_int_eq(selection->start_line, 1);
67 ck_assert_int_eq(selection->start_col, 3);
68 ck_assert_int_eq(selection->end_line, 2);
69 ck_assert_int_eq(selection->end_col, 2);
70 elm_code_widget_selection_clear(widget);
71 free(selection);
72
73 elm_code_free(code);
74 elm_shutdown();
75}
76END_TEST
77
78START_TEST (elm_code_test_widget_selection_text_get)
79{
80 Elm_Code *code;
81 Elm_Code_File *file;
82 Elm_Code_Widget *widget;
83 Evas_Object *win;
84 char *selection;
85
86 elm_init(1, NULL);
87 code = elm_code_create();
88 file = elm_code_file_new(code);
89 elm_code_file_line_append(file, "test", 4, NULL);
90
91 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
92 widget = elm_code_widget_add(win, code);
93
94 ck_assert_str_eq("", elm_code_widget_selection_text_get(widget));
95
96 elm_code_widget_selection_start(widget, 1, 2);
97 elm_code_widget_selection_end(widget, 1, 3);
98
99 selection = elm_code_widget_selection_text_get(widget);
100 ck_assert_str_eq("es", selection);
101 free(selection);
102
103 elm_code_widget_selection_clear(widget);
104 ck_assert_str_eq("", elm_code_widget_selection_text_get(widget));
105
106 elm_code_free(code);
107 elm_shutdown();
108}
109END_TEST
110
111START_TEST (elm_code_test_widget_selection_reverse_text_get)
112{
113 Elm_Code *code;
114 Elm_Code_File *file;
115 Elm_Code_Widget *widget;
116 Evas_Object *win;
117 char *selection;
118
119 elm_init(1, NULL);
120 code = elm_code_create();
121 file = elm_code_file_new(code);
122 elm_code_file_line_append(file, "test", 4, NULL);
123
124 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
125 widget = elm_code_widget_add(win, code);
126
127 ck_assert_str_eq("", elm_code_widget_selection_text_get(widget));
128
129 elm_code_widget_selection_start(widget, 1, 3);
130 elm_code_widget_selection_end(widget, 1, 2);
131
132 selection = elm_code_widget_selection_text_get(widget);
133 ck_assert_str_eq("es", selection);
134 free(selection);
135
136 elm_code_widget_selection_clear(widget);
137 ck_assert_str_eq("", elm_code_widget_selection_text_get(widget));
138
139 elm_code_free(code);
140 elm_shutdown();
141}
142END_TEST
143
144START_TEST (elm_code_test_widget_selection_text_get_twoline)
145{
146 Elm_Code *code;
147 Elm_Code_File *file;
148 Elm_Code_Widget *widget;
149 Evas_Object *win;
150 char *selection;
151
152 elm_init(1, NULL);
153 code = elm_code_create();
154 file = elm_code_file_new(code);
155 elm_code_file_line_append(file, "test", 4, NULL);
156 elm_code_file_line_append(file, "test", 4, NULL);
157
158 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
159 widget = elm_code_widget_add(win, code);
160
161 elm_code_widget_selection_start(widget, 1, 3);
162 elm_code_widget_selection_end(widget, 2, 2);
163
164 selection = elm_code_widget_selection_text_get(widget);
165 ck_assert_str_eq("st\nte", selection);
166 free(selection);
167
168 elm_code_free(code);
169 elm_shutdown();
170}
171END_TEST
172
173START_TEST (elm_code_test_widget_selection_reverse_text_get_twoline)
174{
175 Elm_Code *code;
176 Elm_Code_File *file;
177 Elm_Code_Widget *widget;
178 Evas_Object *win;
179 char *selection;
180
181 elm_init(1, NULL);
182 code = elm_code_create();
183 file = elm_code_file_new(code);
184 elm_code_file_line_append(file, "test", 4, NULL);
185 elm_code_file_line_append(file, "test", 4, NULL);
186
187 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
188 widget = elm_code_widget_add(win, code);
189
190 elm_code_widget_selection_start(widget, 2, 2);
191 elm_code_widget_selection_end(widget, 1, 3);
192
193 selection = elm_code_widget_selection_text_get(widget);
194 ck_assert_str_eq("st\nte", selection);
195 free(selection);
196
197 elm_code_free(code);
198 elm_shutdown();
199}
200END_TEST
201
202START_TEST (elm_code_test_widget_selection_text_get_multiline)
203{
204 Elm_Code *code;
205 Elm_Code_File *file;
206 Elm_Code_Widget *widget;
207 Evas_Object *win;
208 char *selection;
209
210 elm_init(1, NULL);
211 code = elm_code_create();
212 file = elm_code_file_new(code);
213 elm_code_file_line_append(file, "test", 4, NULL);
214 elm_code_file_line_append(file, "test", 4, NULL);
215 elm_code_file_line_append(file, "test", 4, NULL);
216
217 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
218 widget = elm_code_widget_add(win, code);
219
220 elm_code_widget_selection_start(widget, 1, 3);
221 elm_code_widget_selection_end(widget, 3, 2);
222
223 selection = elm_code_widget_selection_text_get(widget);
224 ck_assert_str_eq("st\ntest\nte", selection);
225 free(selection);
226
227 elm_code_free(code);
228 elm_shutdown();
229}
230END_TEST
231
232START_TEST (elm_code_test_widget_selection_reverse_text_get_multiline)
233{
234 Elm_Code *code;
235 Elm_Code_File *file;
236 Elm_Code_Widget *widget;
237 Evas_Object *win;
238 char *selection;
239
240 elm_init(1, NULL);
241 code = elm_code_create();
242 file = elm_code_file_new(code);
243 elm_code_file_line_append(file, "test", 4, NULL);
244 elm_code_file_line_append(file, "test", 4, NULL);
245 elm_code_file_line_append(file, "test", 4, NULL);
246
247 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
248 widget = elm_code_widget_add(win, code);
249
250 elm_code_widget_selection_start(widget, 3, 2);
251 elm_code_widget_selection_end(widget, 1, 3);
252
253 selection = elm_code_widget_selection_text_get(widget);
254 ck_assert_str_eq("st\ntest\nte", selection);
255 free(selection);
256
257 elm_code_free(code);
258 elm_shutdown();
259}
260END_TEST
261
262START_TEST (elm_code_test_widget_selection_delete)
263{
264 Elm_Code *code;
265 Elm_Code_File *file;
266 Elm_Code_Line *line;
267 Elm_Code_Widget *widget;
268 Evas_Object *win;
269 const char *text;
270 unsigned int length;
271
272 elm_init(1, NULL);
273 code = elm_code_create();
274 file = elm_code_file_new(code);
275 elm_code_file_line_append(file, "text", 4, NULL);
276
277 win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
278 widget = elm_code_widget_add(win, code);
279 line = elm_code_file_line_get(file, 1);
280 text = elm_code_line_text_get(line, &length);
281 ck_assert_int_eq(4, length);
282 ck_assert_strn_eq("text", text, length);
283
284 elm_code_widget_selection_start(widget, 1, 2);
285 elm_code_widget_selection_end(widget, 1, 3);
286 elm_code_widget_selection_delete(widget);
287
288 line = elm_code_file_line_get(file, 1);
289 text = elm_code_line_text_get(line, &length);
290 ck_assert_int_eq(2, length);
291 ck_assert_strn_eq("tt", text, length);
292
293 elm_code_free(code);
294 elm_shutdown();
295}
296END_TEST
297
298START_TEST (elm_code_test_widget_selection_reverse_delete)
299{
300 Elm_Code *code;
301 Elm_Code_File *file;
302 Elm_Code_Line *line;
303 Elm_Code_Widget *widget;
304 Evas_Object *win;
305 const char *text;
306 unsigned int length;
307
308 elm_init(1, NULL);
309 code = elm_code_create();
310 file = elm_code_file_new(code);
311 elm_code_file_line_append(file, "text", 4, NULL);
312
313 win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
314 widget = elm_code_widget_add(win, code);
315 line = elm_code_file_line_get(file, 1);
316 text = elm_code_line_text_get(line, &length);
317 ck_assert_int_eq(4, length);
318 ck_assert_strn_eq("text", text, length);
319
320 elm_code_widget_selection_start(widget, 1, 3);
321 elm_code_widget_selection_end(widget, 1, 2);
322 elm_code_widget_selection_delete(widget);
323
324 line = elm_code_file_line_get(file, 1);
325 text = elm_code_line_text_get(line, &length);
326 ck_assert_int_eq(2, length);
327 ck_assert_strn_eq("tt", text, length);
328
329 elm_code_free(code);
330 elm_shutdown();
331}
332END_TEST
333
334START_TEST (elm_code_test_widget_selection_delete_twoline)
335{
336 Elm_Code *code;
337 Elm_Code_File *file;
338 Elm_Code_Line *line;
339 Elm_Code_Widget *widget;
340 Evas_Object *win;
341 const char *text;
342
343 elm_init(1, NULL);
344 code = elm_code_create();
345 file = elm_code_file_new(code);
346 elm_code_file_line_append(file, "text", 4, NULL);
347 elm_code_file_line_append(file, "TEXT", 4, NULL);
348
349 win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
350 widget = elm_code_widget_add(win, code);
351 line = elm_code_file_line_get(file, 1);
352 text = elm_code_line_text_get(line, NULL);
353 ck_assert_str_eq("text", text);
354 ck_assert_int_eq(2, elm_code_file_lines_get(file));
355
356 elm_code_widget_selection_start(widget, 1, 3);
357 elm_code_widget_selection_end(widget, 2, 2);
358 elm_code_widget_selection_delete(widget);
359
360 line = elm_code_file_line_get(file, 1);
361 text = elm_code_line_text_get(line, NULL);
362 ck_assert_str_eq("teXT", text);
363 ck_assert_int_eq(1, elm_code_file_lines_get(file));
364
365 elm_code_free(code);
366 elm_shutdown();
367}
368END_TEST
369
370START_TEST (elm_code_test_widget_selection_reverse_delete_twoline)
371{
372 Elm_Code *code;
373 Elm_Code_File *file;
374 Elm_Code_Line *line;
375 Elm_Code_Widget *widget;
376 Evas_Object *win;
377 const char *text;
378
379 elm_init(1, NULL);
380 code = elm_code_create();
381 file = elm_code_file_new(code);
382 elm_code_file_line_append(file, "text", 4, NULL);
383 elm_code_file_line_append(file, "TEXT", 4, NULL);
384
385 win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
386 widget = elm_code_widget_add(win, code);
387 line = elm_code_file_line_get(file, 1);
388 text = elm_code_line_text_get(line, NULL);
389 ck_assert_str_eq("text", text);
390 ck_assert_int_eq(2, elm_code_file_lines_get(file));
391
392 elm_code_widget_selection_start(widget, 2, 2);
393 elm_code_widget_selection_end(widget, 1, 3);
394 elm_code_widget_selection_delete(widget);
395
396 line = elm_code_file_line_get(file, 1);
397 text = elm_code_line_text_get(line, NULL);
398 ck_assert_str_eq("teXT", text);
399 ck_assert_int_eq(1, elm_code_file_lines_get(file));
400
401 elm_code_free(code);
402 elm_shutdown();
403}
404END_TEST
405
406START_TEST (elm_code_test_widget_selection_delete_multiline)
407{
408 Elm_Code *code;
409 Elm_Code_File *file;
410 Elm_Code_Line *line;
411 Elm_Code_Widget *widget;
412 Evas_Object *win;
413 const char *text;
414
415 elm_init(1, NULL);
416 code = elm_code_create();
417 file = elm_code_file_new(code);
418 elm_code_file_line_append(file, "text", 4, NULL);
419 elm_code_file_line_append(file, "remove", 6, NULL);
420 elm_code_file_line_append(file, "TEXT", 4, NULL);
421
422 win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
423 widget = elm_code_widget_add(win, code);
424 line = elm_code_file_line_get(file, 1);
425 text = elm_code_line_text_get(line, NULL);
426 ck_assert_str_eq("text", text);
427 ck_assert_int_eq(3, elm_code_file_lines_get(file));
428
429 elm_code_widget_selection_start(widget, 1, 3);
430 elm_code_widget_selection_end(widget, 3, 2);
431 elm_code_widget_selection_delete(widget);
432
433 line = elm_code_file_line_get(file, 1);
434 text = elm_code_line_text_get(line, NULL);
435 ck_assert_str_eq("teXT", text);
436 ck_assert_int_eq(1, elm_code_file_lines_get(file));
437
438 elm_code_free(code);
439 elm_shutdown();
440}
441END_TEST
442
443START_TEST (elm_code_test_widget_selection_reverse_delete_multiline)
444{
445 Elm_Code *code;
446 Elm_Code_File *file;
447 Elm_Code_Line *line;
448 Elm_Code_Widget *widget;
449 Evas_Object *win;
450 const char *text;
451
452 elm_init(1, NULL);
453 code = elm_code_create();
454 file = elm_code_file_new(code);
455 elm_code_file_line_append(file, "text", 4, NULL);
456 elm_code_file_line_append(file, "remove", 6, NULL);
457 elm_code_file_line_append(file, "TEXT", 4, NULL);
458
459 win = elm_win_add(NULL, "code", ELM_WIN_BASIC);
460 widget = elm_code_widget_add(win, code);
461 line = elm_code_file_line_get(file, 1);
462 text = elm_code_line_text_get(line, NULL);
463 ck_assert_str_eq("text", text);
464 ck_assert_int_eq(3, elm_code_file_lines_get(file));
465
466 elm_code_widget_selection_start(widget, 3, 2);
467 elm_code_widget_selection_end(widget, 1, 3);
468 elm_code_widget_selection_delete(widget);
469
470 line = elm_code_file_line_get(file, 1);
471 text = elm_code_line_text_get(line, NULL);
472 ck_assert_str_eq("teXT", text);
473 ck_assert_int_eq(1, elm_code_file_lines_get(file));
474
475 elm_code_free(code);
476 elm_shutdown();
477}
478END_TEST
479
480START_TEST (elm_code_test_widget_selection_select_line)
481{
482 Elm_Code *code;
483 Elm_Code_File *file;
484 Elm_Code_Widget *widget;
485 Evas_Object *win;
486 char *selection;
487
488 elm_init(1, NULL);
489 code = elm_code_create();
490 file = elm_code_file_new(code);
491 elm_code_file_line_append(file, "line selection", 14, NULL);
492 elm_code_file_line_append(file, "line2", 5, NULL);
493
494 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
495 widget = elm_code_widget_add(win, code);
496
497 elm_code_widget_selection_select_line(widget, 1);
498 selection = elm_code_widget_selection_text_get(widget);
499 ck_assert_str_eq("line selection", selection);
500 free(selection);
501
502 elm_code_widget_selection_select_line(widget, 2);
503 selection = elm_code_widget_selection_text_get(widget);
504 ck_assert_str_eq("line2", selection);
505 free(selection);
506 elm_shutdown();
507}
508END_TEST
509
510START_TEST (elm_code_test_widget_selection_select_word)
511{
512 Elm_Code *code;
513 Elm_Code_File *file;
514 Elm_Code_Widget *widget;
515 Evas_Object *win;
516 char *selection;
517
518 elm_init(1, NULL);
519 code = elm_code_create();
520 file = elm_code_file_new(code);
521 elm_code_file_line_append(file, "word selection test", 19, NULL);
522 elm_code_file_line_append(file, "more stuff\tto test", 18, NULL);
523
524 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
525 widget = elm_code_widget_add(win, code);
526
527 elm_code_widget_selection_select_word(widget, 1, 3);
528 selection = elm_code_widget_selection_text_get(widget);
529 ck_assert_str_eq("word", selection);
530 free(selection);
531
532 elm_code_widget_selection_select_word(widget, 1, 16);
533 selection = elm_code_widget_selection_text_get(widget);
534 ck_assert_str_eq("test", selection);
535 free(selection);
536
537 elm_code_widget_selection_select_word(widget, 2, 9);
538 selection = elm_code_widget_selection_text_get(widget);
539 ck_assert_str_eq("stuff", selection);
540 free(selection);
541 elm_shutdown();
542}
543END_TEST
544
545START_TEST (elm_code_test_widget_selection_select_word_punctuation)
546{
547 Elm_Code *code;
548 Elm_Code_File *file;
549 Elm_Code_Widget *widget;
550 Evas_Object *win;
551 char *selection;
552
553 elm_init(1, NULL);
554 code = elm_code_create();
555 file = elm_code_file_new(code);
556 elm_code_file_line_append(file, "comma, stop. question? mark!", 38, NULL);
557
558 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
559 widget = elm_code_widget_add(win, code);
560
561 elm_code_widget_selection_select_word(widget, 1, 3);
562 selection = elm_code_widget_selection_text_get(widget);
563 ck_assert_str_eq("comma", selection);
564 free(selection);
565
566 elm_code_widget_selection_select_word(widget, 1, 10);
567 selection = elm_code_widget_selection_text_get(widget);
568 ck_assert_str_eq("stop", selection);
569 free(selection);
570
571 elm_code_widget_selection_select_word(widget, 1, 20);
572 selection = elm_code_widget_selection_text_get(widget);
573 ck_assert_str_eq("question", selection);
574 free(selection);
575
576 elm_code_widget_selection_select_word(widget, 1, 25);
577 selection = elm_code_widget_selection_text_get(widget);
578 ck_assert_str_eq("mark", selection);
579 free(selection);
580 elm_shutdown();
581}
582END_TEST
583
584START_TEST (elm_code_test_widget_selection_select_word_symbols)
585{
586 Elm_Code *code;
587 Elm_Code_File *file;
588 Elm_Code_Widget *widget;
589 Evas_Object *win;
590 char *selection;
591
592 elm_init(1, NULL);
593 code = elm_code_create();
594 file = elm_code_file_new(code);
595 elm_code_file_line_append(file, "colon: [array] (brackets) {braces}", 38, NULL);
596
597 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
598 widget = elm_code_widget_add(win, code);
599
600 elm_code_widget_selection_select_word(widget, 1, 3);
601 selection = elm_code_widget_selection_text_get(widget);
602 ck_assert_str_eq("colon", selection);
603 free(selection);
604
605 elm_code_widget_selection_select_word(widget, 1, 10);
606 selection = elm_code_widget_selection_text_get(widget);
607 ck_assert_str_eq("array", selection);
608 free(selection);
609
610 elm_code_widget_selection_select_word(widget, 1, 20);
611 selection = elm_code_widget_selection_text_get(widget);
612 ck_assert_str_eq("brackets", selection);
613 free(selection);
614
615 elm_code_widget_selection_select_word(widget, 1, 30);
616 selection = elm_code_widget_selection_text_get(widget);
617 ck_assert_str_eq("braces", selection);
618 free(selection);
619 elm_shutdown();
620}
621END_TEST
622
623void elm_code_test_widget_selection(TCase *tc)
624{
625 tcase_add_test(tc, elm_code_test_widget_selection_set);
626 tcase_add_test(tc, elm_code_test_widget_selection_normalized_get);
627 tcase_add_test(tc, elm_code_test_widget_selection_text_get);
628 tcase_add_test(tc, elm_code_test_widget_selection_reverse_text_get);
629 tcase_add_test(tc, elm_code_test_widget_selection_text_get_twoline);
630 tcase_add_test(tc, elm_code_test_widget_selection_reverse_text_get_twoline);
631 tcase_add_test(tc, elm_code_test_widget_selection_text_get_multiline);
632 tcase_add_test(tc, elm_code_test_widget_selection_reverse_text_get_multiline);
633 tcase_add_test(tc, elm_code_test_widget_selection_delete);
634 tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete);
635 tcase_add_test(tc, elm_code_test_widget_selection_delete_twoline);
636 tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete_twoline);
637 tcase_add_test(tc, elm_code_test_widget_selection_delete_multiline);
638 tcase_add_test(tc, elm_code_test_widget_selection_reverse_delete_multiline);
639 tcase_add_test(tc, elm_code_test_widget_selection_select_line);
640 tcase_add_test(tc, elm_code_test_widget_selection_select_word);
641 tcase_add_test(tc, elm_code_test_widget_selection_select_word_punctuation);
642 tcase_add_test(tc, elm_code_test_widget_selection_select_word_symbols);
643}
diff --git a/src/tests/elementary/elm_code_test_widget_text.c b/src/tests/elementary/elm_code_test_widget_text.c
new file mode 100644
index 0000000000..e11ce6fad4
--- /dev/null
+++ b/src/tests/elementary/elm_code_test_widget_text.c
@@ -0,0 +1,62 @@
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
10START_TEST (elm_code_test_widget_text_tab_width)
11{
12 Elm_Code *code;
13 Elm_Code_Widget *widget;
14 Evas_Object *win;
15
16 elm_init(1, NULL);
17 code = elm_code_create();
18 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
19 widget = elm_code_widget_add(win, code);
20 elm_code_widget_tabstop_set(widget, 8);
21
22 ck_assert_int_eq(8, elm_code_widget_text_tabwidth_at_column_get(widget, 1));
23 ck_assert_int_eq(8, elm_code_widget_text_tabwidth_at_column_get(widget, 9));
24 ck_assert_int_eq(6, elm_code_widget_text_tabwidth_at_column_get(widget, 3));
25
26 elm_code_free(code);
27 elm_shutdown();
28}
29END_TEST
30
31START_TEST (elm_code_test_widget_text_position)
32{
33 Elm_Code *code;
34 Elm_Code_File *file;
35 Elm_Code_Line *line;
36 Elm_Code_Widget *widget;
37 Evas_Object *win;
38
39 elm_init(1, NULL);
40 code = elm_code_create();
41 file = elm_code_file_new(code);
42 elm_code_file_line_append(file, "a\tb", 4, NULL);
43 line = elm_code_file_line_get(file, 1);
44
45 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
46 widget = elm_code_widget_add(win, code);
47 elm_code_widget_tabstop_set(widget, 8);
48
49 ck_assert_int_eq(0, elm_code_widget_line_text_position_for_column_get(widget, line, 1));
50 ck_assert_int_eq(1, elm_code_widget_line_text_position_for_column_get(widget, line, 2));
51
52 ck_assert_int_eq(2, elm_code_widget_line_text_position_for_column_get(widget, line, 9));
53 ck_assert_int_eq(1, elm_code_widget_line_text_position_for_column_get(widget, line, 7));
54 elm_shutdown();
55}
56END_TEST
57
58void elm_code_test_widget_text(TCase *tc)
59{
60 tcase_add_test(tc, elm_code_test_widget_text_tab_width);
61 tcase_add_test(tc, elm_code_test_widget_text_position);
62}
diff --git a/src/tests/elementary/elm_code_test_widget_undo.c b/src/tests/elementary/elm_code_test_widget_undo.c
new file mode 100644
index 0000000000..b07a294eb5
--- /dev/null
+++ b/src/tests/elementary/elm_code_test_widget_undo.c
@@ -0,0 +1,165 @@
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_widget_private.h"
10
11START_TEST (elm_code_test_widget_undo_text_insert)
12{
13 Elm_Code *code;
14 Elm_Code_File *file;
15 Elm_Code_Line *line;
16 Elm_Code_Widget *widget;
17 Evas_Object *win;
18 unsigned int length;
19 const char *content;
20
21 elm_init(1, NULL);
22 code = elm_code_create();
23 file = elm_code_file_new(code);
24 elm_code_file_line_append(file, "test", 4, NULL);
25
26 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
27 widget = elm_code_widget_add(win, code);
28
29 _elm_code_widget_text_at_cursor_insert(widget, "a", 1);
30 line = elm_code_file_line_get(file, 1);
31 content = elm_code_line_text_get(line, &length);
32 ck_assert_strn_eq("atest", content, length);
33
34 elm_code_widget_undo(widget);
35 content = elm_code_line_text_get(line, &length);
36 ck_assert_strn_eq("test", content, length);
37
38 elm_code_widget_cursor_position_set(widget, 3, 1);
39 _elm_code_widget_text_at_cursor_insert(widget, "r", 1);
40 content = elm_code_line_text_get(line, &length);
41 ck_assert_strn_eq("terst", content, length);
42
43 elm_code_widget_undo(widget);
44 content = elm_code_line_text_get(line, &length);
45 ck_assert_strn_eq("test", content, length);
46
47 elm_code_widget_cursor_position_set(widget, 4, 1);
48 _elm_code_widget_text_at_cursor_insert(widget, "\t", 1);
49 content = elm_code_line_text_get(line, &length);
50 ck_assert_strn_eq("tes\tt", content, length);
51
52 elm_code_widget_undo(widget);
53 content = elm_code_line_text_get(line, &length);
54 ck_assert_strn_eq("test", content, length);
55
56 elm_code_free(code);
57 elm_shutdown();
58}
59END_TEST
60
61START_TEST (elm_code_test_widget_undo_newline)
62{
63 Elm_Code *code;
64 Elm_Code_File *file;
65 Elm_Code_Line *line;
66 Elm_Code_Widget *widget;
67 Evas_Object *win;
68 unsigned int length;
69 const char *content;
70
71 elm_init(1, NULL);
72 code = elm_code_create();
73 file = elm_code_file_new(code);
74 elm_code_file_line_append(file, "test", 4, NULL);
75
76 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
77 widget = elm_code_widget_add(win, code);
78
79 elm_code_widget_cursor_position_set(widget, 5, 1);
80 _elm_code_widget_newline(widget);
81 ck_assert_int_eq(2, elm_code_file_lines_get(file));
82 line = elm_code_file_line_get(file, 1);
83 content = elm_code_line_text_get(line, &length);
84 ck_assert_strn_eq("test", content, 1);
85
86 elm_code_widget_undo(widget);
87
88 ck_assert_int_eq(1, elm_code_file_lines_get(file));
89 line = elm_code_file_line_get(file, 1);
90 content = elm_code_line_text_get(line, &length);
91 ck_assert_strn_eq("test", content, 4);
92
93 elm_code_free(code);
94 elm_shutdown();
95}
96END_TEST
97
98START_TEST (elm_code_test_widget_undo_delete)
99{
100 Elm_Code *code;
101 Elm_Code_File *file;
102 Elm_Code_Line *line;
103 Elm_Code_Widget *widget;
104 Evas_Object *win;
105 unsigned int length;
106 const char *content;
107
108 elm_init(1, NULL);
109 code = elm_code_create();
110 file = elm_code_file_new(code);
111 elm_code_file_line_append(file, "test", 4, NULL);
112
113 win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
114 widget = elm_code_widget_add(win, code);
115
116 elm_code_widget_cursor_position_set(widget, 4, 1);
117 _elm_code_widget_backspace(widget);
118
119 line = elm_code_file_line_get(file, 1);
120 content = elm_code_line_text_get(line, &length);
121 ck_assert_strn_eq("tet", content, length);
122
123 elm_code_widget_undo(widget);
124 content = elm_code_line_text_get(line, &length);
125 ck_assert_strn_eq("test", content, length);
126
127 elm_code_widget_cursor_position_set(widget, 2, 1);
128 _elm_code_widget_delete(widget);
129
130 line = elm_code_file_line_get(file, 1);
131 content = elm_code_line_text_get(line, &length);
132 ck_assert_strn_eq("tst", content, length);
133
134 elm_code_widget_undo(widget);
135 content = elm_code_line_text_get(line, &length);
136 ck_assert_strn_eq("test", content, length);
137
138 elm_code_widget_cursor_position_set(widget, 4, 1);
139 _elm_code_widget_text_at_cursor_insert(widget, "\t", 1);
140 _elm_code_widget_backspace(widget);
141 content = elm_code_line_text_get(line, &length);
142 ck_assert_strn_eq("test", content, length);
143 elm_code_widget_undo(widget);
144 content = elm_code_line_text_get(line, &length);
145 ck_assert_strn_eq("tes\tt", content, length);
146
147 elm_code_widget_cursor_position_set(widget, 4, 1);
148 _elm_code_widget_delete(widget);
149 content = elm_code_line_text_get(line, &length);
150 ck_assert_strn_eq("test", content, length);
151 elm_code_widget_undo(widget);
152 content = elm_code_line_text_get(line, &length);
153 ck_assert_strn_eq("tes\tt", content, length);
154
155 elm_code_free(code);
156 elm_shutdown();
157}
158END_TEST
159
160void elm_code_test_widget_undo(TCase *tc)
161{
162 tcase_add_test(tc, elm_code_test_widget_undo_text_insert);
163 tcase_add_test(tc, elm_code_test_widget_undo_newline);
164 tcase_add_test(tc, elm_code_test_widget_undo_delete);
165}
diff --git a/src/tests/elementary/elm_suite.c b/src/tests/elementary/elm_suite.c
index 75facc6e37..a612e7edc3 100644
--- a/src/tests/elementary/elm_suite.c
+++ b/src/tests/elementary/elm_suite.c
@@ -71,6 +71,15 @@ static const Efl_Test_Case etc[] = {
71 { "elm_slideshow", elm_test_slideshow}, 71 { "elm_slideshow", elm_test_slideshow},
72 { "elm_spinner", elm_test_spinner}, 72 { "elm_spinner", elm_test_spinner},
73 { "elm_plug", elm_test_plug}, 73 { "elm_plug", elm_test_plug},
74 { "file_load", elm_code_file_test_load },
75 { "file_memory", elm_code_file_test_memory },
76 { "parse", elm_code_test_parse },
77 { "text", elm_code_test_text },
78 { "basic", elm_code_test_basic },
79 { "widget", elm_code_test_widget },
80 { "widget_text", elm_code_test_widget_text },
81 { "widget_selection", elm_code_test_widget_selection },
82 { "widget_undo", elm_code_test_widget_undo },
74 { NULL, NULL } 83 { NULL, NULL }
75}; 84};
76 85
diff --git a/src/tests/elementary/elm_suite.h b/src/tests/elementary/elm_suite.h
index 1a191793bf..bf87d1b622 100644
--- a/src/tests/elementary/elm_suite.h
+++ b/src/tests/elementary/elm_suite.h
@@ -69,4 +69,15 @@ void elm_test_slideshow(TCase *tc);
69void elm_test_spinner(TCase *tc); 69void elm_test_spinner(TCase *tc);
70void elm_test_plug(TCase *tc); 70void elm_test_plug(TCase *tc);
71 71
72void elm_code_file_test_load(TCase *tc);
73void elm_code_file_test_memory(TCase *tc);
74void elm_code_test_basic(TCase *tc);
75void elm_code_test_line(TCase *tc);
76void elm_code_test_parse(TCase *tc);
77void elm_code_test_text(TCase *tc);
78void elm_code_test_widget(TCase *tc);
79void elm_code_test_widget_text(TCase *tc);
80void elm_code_test_widget_selection(TCase *tc);
81void elm_code_test_widget_undo(TCase *tc);
82
72#endif /* _ELM_SUITE_H */ 83#endif /* _ELM_SUITE_H */
diff --git a/src/tests/elementary/elm_test_helper.h b/src/tests/elementary/elm_test_helper.h
index 0bfc5ca0e6..f0b44bb8ed 100644
--- a/src/tests/elementary/elm_test_helper.h
+++ b/src/tests/elementary/elm_test_helper.h
@@ -3,6 +3,19 @@
3 3
4#include <Eina.h> 4#include <Eina.h>
5 5
6#define ck_assert_strn_eq(s1, s2, len) \
7 { \
8 char expected[len+1], actual[len+1]; \
9 \
10 strncpy(expected, s1, len); \
11 expected[len] = '\0'; \
12 strncpy(actual, s2, len); \
13 actual[len] = '\0'; \
14 \
15 ck_assert_str_eq(expected, actual); \
16 }
17
18
6Eina_Bool elm_test_helper_wait_flag(double in, Eina_Bool *done); 19Eina_Bool elm_test_helper_wait_flag(double in, Eina_Bool *done);
7 20
8#endif /* _ELM_TEST_HELPER_H */ 21#endif /* _ELM_TEST_HELPER_H */
diff --git a/src/tests/elementary/testdiff.diff b/src/tests/elementary/testdiff.diff
new file mode 100644
index 0000000000..157cbb7b98
--- /dev/null
+++ b/src/tests/elementary/testdiff.diff
@@ -0,0 +1,10 @@
1--- testdiff1.txt 2014-11-22 21:16:16.279872989 +0000
2+++ testdiff2.txt 2014-11-22 21:16:34.406052375 +0000
3@@ -1,5 +1,5 @@
4 Some content to diff
5+added
6 more
7-removed
8-will change
9+changed
10 unchanged
diff --git a/src/tests/elementary/testfile-windows.txt b/src/tests/elementary/testfile-windows.txt
new file mode 100644
index 0000000000..c397f82dcb
--- /dev/null
+++ b/src/tests/elementary/testfile-windows.txt
@@ -0,0 +1,4 @@
1line 1
2line2
3a third
4another line
diff --git a/src/tests/elementary/testfile-withblanks.txt b/src/tests/elementary/testfile-withblanks.txt
new file mode 100644
index 0000000000..0f2ead3796
--- /dev/null
+++ b/src/tests/elementary/testfile-withblanks.txt
@@ -0,0 +1,8 @@
1line 1
2line2
3
4another link
5
6
7double blank
88
diff --git a/src/tests/elementary/testfile.txt b/src/tests/elementary/testfile.txt
new file mode 100644
index 0000000000..8fd6a8b140
--- /dev/null
+++ b/src/tests/elementary/testfile.txt
@@ -0,0 +1,4 @@
1line 1
2line2
3a third
4another line