summaryrefslogtreecommitdiff
path: root/src/tests/eolian_cxx/eolian_cxx_test_documentation.cc
blob: 961519d16e84c9f915f2775d07967f78c73d754b (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
 * Copyright 2019 by its authors. See AUTHORS.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <iostream>
#include <cassert>
#include <iterator>
#include <algorithm>

#include <Eina.hh>
#include <Eolian_Cxx.hh>

#include "eolian_cxx_suite.h"

#include "grammar/klass_def.hpp"

using efl::eolian::grammar::attributes::klass_def;
using efl::eolian::grammar::attributes::documentation_def;
using efl::eolian::grammar::attributes::function_def;
using efl::eolian::grammar::attributes::enum_def;
using efl::eolian::grammar::attributes::struct_def;

klass_def init_test_data(efl::eolian::eolian_state const& state)
{
   ck_assert(::eolian_state_directory_add(state.value, TESTS_SRC_DIR));
   ck_assert(::eolian_state_all_eot_files_parse(state.value));
   ck_assert(::eolian_state_file_parse(state.value, "docs.eo"));

   const Eolian_Class *c_klass = ::eolian_state_class_by_name_get(state.value, "Docs");
   ck_assert_ptr_ne(c_klass, NULL);

   klass_def klass(c_klass, state.as_unit());
   return klass;
}

EFL_START_TEST(eolian_cxx_test_class_docs)
{
   efl::eina::eina_init eina_init;
   efl::eolian::eolian_init eolian_init;
   efl::eolian::eolian_state eolian_state;

   klass_def klass = init_test_data(eolian_state);
   documentation_def doc = klass.documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Docs for class.");
   ck_assert_str_eq(doc.description.c_str(),
           "More docs for class. Testing references now. "
           "@Foo "
           "@Bar "
           "@Alias "
           "@pants "
           "@Docs.meth "
           "@Docs.prop "
           "@Docs.prop.get "
           "@Docs.prop.set "
           "@Foo.field1 "
           "@Bar.foo "
           "@Docs");
   ck_assert_str_eq(doc.since.c_str(), "1.17");
}
EFL_END_TEST

EFL_START_TEST(eolian_cxx_test_function_docs)
{
   efl::eina::eina_init eina_init;
   efl::eolian::eolian_init eolian_init;
   efl::eolian::eolian_state eolian_state;

   klass_def klass = init_test_data(eolian_state);
   function_def func = *std::find_if(klass.functions.begin(), klass.functions.end(),
           [](const function_def& f) {
             return f.name == "meth";
           });

   documentation_def doc = func.documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Method documentation.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "1.17"); // Since is inherited from parent if not present, except when no doc is present ofr this member.

   doc = func.return_documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Return documentation.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "1.17");

   auto param_iter = func.parameters.begin();

   // a int
   doc = param_iter->documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Param documentation.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "1.17");

   param_iter++;

   // b float (no doc)
   doc = param_iter->documentation;
   ck_assert_str_eq(doc.summary.c_str(), "");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "");

   param_iter++;

   // c long
   doc = param_iter->documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Another param documentation.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "1.17");
}
EFL_END_TEST

EFL_START_TEST(eolian_cxx_test_property_docs)
{
   efl::eina::eina_init eina_init;
   efl::eolian::eolian_init eolian_init;
   efl::eolian::eolian_state eolian_state;

   klass_def klass = init_test_data(eolian_state);
   auto func_iter = std::find_if(klass.functions.begin(), klass.functions.end(),
           [](const function_def& f) {
             return f.name == "prop_get";
           });

   ck_assert_msg(func_iter != klass.functions.end(), "Failed to find prop_get function");
   function_def func = *func_iter;

   documentation_def doc = func.property_documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Property common documentation.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "1.18");

   doc = func.documentation; // Actual getdocumentation.
   ck_assert_str_eq(doc.summary.c_str(), "Get documentation.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "1.17"); // Members inherit from parent *class*

   func_iter = std::find_if(klass.functions.begin(), klass.functions.end(),
           [](const function_def& f) {
             return f.name == "prop_set";
           });

   ck_assert_msg(func_iter != klass.functions.end(), "Failed to find prop_set function");
   func = *func_iter;

   doc = func.documentation; // Actual getdocumentation.
   ck_assert_str_eq(doc.summary.c_str(), "Set documentation.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "1.17"); // Members inherit from parent *class*

   auto property_iter = klass.properties.begin();
   auto property = *property_iter;
   doc = property.documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Property common documentation.");
   ck_assert_str_eq(doc.since.c_str(), "1.18");
}
EFL_END_TEST

EFL_START_TEST(eolian_cxx_test_event_docs)
{
   efl::eina::eina_init eina_init;
   efl::eolian::eolian_init eolian_init;
   efl::eolian::eolian_state eolian_state;

   klass_def klass = init_test_data(eolian_state);

   auto event = klass.events.front();
   documentation_def doc = event.documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Event docs.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "1.17"); // Members inherit from parent *class*
}
EFL_END_TEST

EFL_START_TEST(eolian_cxx_test_enum_docs)
{
   efl::eina::eina_init eina_init;
   efl::eolian::eolian_init eolian_init;
   efl::eolian::eolian_state eolian_state;

   klass_def klass = init_test_data(eolian_state);

   auto unit = eolian_state.as_unit();
   enum_def _enum(::eolian_state_enum_by_name_get(eolian_state.value, "Bar"), unit);

   documentation_def doc = _enum.documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Docs for enum Bar.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "");

   // fields
   auto field_iter = _enum.fields.begin();

   // blah - no docs
   doc = field_iter->documentation;
   ck_assert_str_eq(doc.summary.c_str(), "");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "");

   field_iter++;

   // foo - docs
   doc = field_iter->documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Docs for foo.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "");

   field_iter++;

   // bar - docs
   doc = field_iter->documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Docs for bar.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "");
}
EFL_END_TEST

EFL_START_TEST(eolian_cxx_test_struct_docs)
{
   efl::eina::eina_init eina_init;
   efl::eolian::eolian_init eolian_init;
   efl::eolian::eolian_state eolian_state;

   klass_def klass = init_test_data(eolian_state);

   auto unit = eolian_state.as_unit();
   struct_def _struct(::eolian_state_struct_by_name_get(eolian_state.value, "Foo"), unit);

   documentation_def doc = _struct.documentation;
   ck_assert_str_eq(doc.summary.c_str(), "This is struct Foo. "
                                         "It does stuff.");
   ck_assert_str_eq(doc.description.c_str(),
                    "Note: This is a note.\n"
                    "\n"
                    "This is a longer description for struct Foo.\n"
                    "\n"
                    "Warning: This is a warning. You can only use Warning: and "
                    "Note: at the beginning of a paragraph.\n"
                    "\n"
                    "This is another paragraph.");
   ck_assert_str_eq(doc.since.c_str(), "1.66");

   std::vector<std::string> ref_paragraphs = {
       "Note: This is a note.",
       "This is a longer description for struct Foo.",
       "Warning: This is a warning. You can only use Warning: and "
       "Note: at the beginning of a paragraph.",
       "This is another paragraph."
   };

   auto paragraph_it = doc.desc_paragraphs.begin();
   auto ref_paragraph_it = ref_paragraphs.begin();

   while (ref_paragraph_it != ref_paragraphs.end())
     {
        ck_assert_str_eq(paragraph_it->c_str(), ref_paragraph_it->c_str());
        paragraph_it++;
        ref_paragraph_it++;
     }

   ck_assert(paragraph_it == doc.desc_paragraphs.end());


   // fields
   auto field_iter = _struct.fields.begin();

   doc = field_iter->documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Field documentation.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "");

   field_iter++;

   doc = field_iter->documentation;
   ck_assert_str_eq(doc.summary.c_str(), "");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "");

   field_iter++;

   doc = field_iter->documentation;
   ck_assert_str_eq(doc.summary.c_str(), "Another field documentation.");
   ck_assert_str_eq(doc.description.c_str(), "");
   ck_assert_str_eq(doc.since.c_str(), "");
}
EFL_END_TEST

void
eolian_cxx_test_documentation(TCase* tc)
{
   tcase_add_test(tc, eolian_cxx_test_class_docs);
   tcase_add_test(tc, eolian_cxx_test_function_docs);
   tcase_add_test(tc, eolian_cxx_test_property_docs);
   tcase_add_test(tc, eolian_cxx_test_event_docs);
   tcase_add_test(tc, eolian_cxx_test_enum_docs);
   tcase_add_test(tc, eolian_cxx_test_struct_docs);
}