summaryrefslogtreecommitdiff
path: root/src/tests/elementary/elm_code_test_parse.c
blob: 3858898e81f0c30058fb141e614fbd9964c3cfa3 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include "elm_suite.h"
#include "Elementary.h"
#include "elm_code_parse.h"

static int line_calls, file_calls;

static void _parser_line_callback(Elm_Code_Line *line EINA_UNUSED, void *data EINA_UNUSED)
{
   line_calls++;
}

static void _parser_file_callback(Elm_Code_File *file EINA_UNUSED, void *data EINA_UNUSED)
{
   file_calls++;
}

EFL_START_TEST(elm_code_parse_hook_memory_test)
{
   Elm_Code *code;
   Elm_Code_File *file;

   line_calls = 0;
   file_calls = 0;

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

   elm_code_parser_add(code, _parser_line_callback, _parser_file_callback, NULL);
   elm_code_file_line_append(file, "some \"test content\" for parsing", 31, NULL);

   ck_assert_int_eq(1, line_calls);
   ck_assert_int_eq(0, file_calls);

   elm_code_free(code);
   elm_shutdown();
}
EFL_END_TEST

EFL_START_TEST(elm_code_parse_hook_file_test)
{
   Elm_Code *code;
   Elm_Code_File *file;
   char *path = TESTS_SRC_DIR "/testfile.txt";

   line_calls = 0;
   file_calls = 0;

   char *args[] = { "exe" };
   elm_init(1, args);
   code = elm_code_create();

   elm_code_parser_add(code, _parser_line_callback, _parser_file_callback, NULL);
   file = elm_code_file_open(code, path);

   ck_assert_int_eq(4, line_calls);
   ck_assert_int_eq(1, file_calls);

   elm_code_file_close(file);
   elm_code_free(code);
   elm_shutdown();
}
EFL_END_TEST

EFL_START_TEST(elm_code_parse_todo_test)
{
   Elm_Code *code;
   Elm_Code_File *file;
   Elm_Code_Line *line;

   char *args[] = { "exe" };
   elm_init(1, args);
   code = elm_code_create();
   elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_TODO);
   file = elm_code_file_new(code);

   elm_code_file_line_append(file, "xxx TODO line", 13, NULL);
   line = elm_code_file_line_get(file, 1);
   ck_assert_int_eq(ELM_CODE_STATUS_TYPE_TODO, line->status);

   elm_code_line_text_set(line, "FIXME too", 9);
   ck_assert_int_eq(ELM_CODE_STATUS_TYPE_TODO, line->status);

   elm_code_line_text_set(line, "TOFIX", 5);
   ck_assert_int_eq(ELM_CODE_STATUS_TYPE_DEFAULT, line->status);
   elm_shutdown();
}
EFL_END_TEST

void elm_code_test_parse(TCase *tc)
{
   tcase_add_test(tc, elm_code_parse_hook_memory_test);
   tcase_add_test(tc, elm_code_parse_hook_file_test);
   tcase_add_test(tc, elm_code_parse_todo_test);
}