docurium 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -459,6 +459,7 @@ div.sidebar-module ul ul li span {
459
459
  .content .verseblock-content,
460
460
  .content .sectionbody .dlist dt,
461
461
  .content p > tt,
462
+ .content table tr td code,
462
463
  .content dl code,
463
464
  .content ul code,
464
465
  p code {
@@ -25,6 +25,8 @@
25
25
  #ifndef INCLUDE_git_errors_h__
26
26
  #define INCLUDE_git_errors_h__
27
27
 
28
+ #include "common.h"
29
+
28
30
  /**
29
31
  * @file git2/errors.h
30
32
  * @brief Git error handling routines and variables
@@ -1,21 +1,20 @@
1
1
  require 'minitest/autorun'
2
2
  require 'docurium'
3
+ require 'pp'
3
4
 
4
5
  class TestParser < Minitest::Unit::TestCase
5
6
 
6
7
  def setup
7
- @parser = Docurium::CParser.new
8
+ @parser = Docurium::DocParser.new
8
9
  end
9
10
 
10
11
  # e.g. parse('git2/refs.h')
11
- def parse(path)
12
- realpath = File.dirname(__FILE__) + '/fixtures/' + path
13
-
14
- parser = Docurium::CParser.new
15
- parser.parse_text(path, File.read(realpath))
12
+ def parse(path, contents)
13
+ @parser.parse_file(path, [[path, contents]])
16
14
  end
17
15
 
18
16
  def test_single_function
17
+
19
18
  name = 'function.h'
20
19
  contents = <<EOF
21
20
  /**
@@ -29,21 +28,17 @@ class TestParser < Minitest::Unit::TestCase
29
28
  int some_function(char *string);
30
29
  EOF
31
30
 
32
- raw_comments = <<EOF
33
- Do something
34
-
35
- More explanation of what we do
36
-
37
- @param string a sequence of characters
38
- @return an integer value
39
- EOF
40
-
41
- actual = @parser.parse_text(name, contents)
31
+ actual = parse(name, contents)
42
32
  expected = [{:file => "function.h",
43
33
  :line => 9,
44
- :body => 'int some_function(char *string);',
45
- :rawComments => raw_comments.strip,
34
+ :lineto => 9,
35
+ :tdef => nil,
46
36
  :type => :function,
37
+ :name => 'some_function',
38
+ :body => 'int some_function(char *string);',
39
+ :description => ' Do something',
40
+ :comments => " More explanation of what we do\n\n ",
41
+ :sig => 'char *',
47
42
  :args => [{
48
43
  :name => 'string',
49
44
  :type => 'char *',
@@ -51,22 +46,20 @@ EOF
51
46
  }],
52
47
  :return => {
53
48
  :type => 'int',
54
- :comment => 'an integer value'
49
+ :comment => ' an integer value'
55
50
  },
56
- :argline => 'char *string',
57
- :sig => 'char *',
58
- :description => 'Do something',
59
- :lineto => 9,
60
- :comments => "More explanation of what we do\n",
61
51
  :decl => 'int some_function(char *string)',
62
- :name => 'some_function'}]
52
+ :argline => 'char *string',
53
+ }]
63
54
 
64
55
  assert_equal expected, actual
65
56
  end
66
57
 
67
58
  def test_single_multiline_function
59
+
68
60
  name = 'function.h'
69
61
  contents = <<EOF
62
+ #include <stdlib.h>
70
63
  /**
71
64
  * Do something
72
65
  *
@@ -80,22 +73,17 @@ int some_function(
80
73
  size_t len);
81
74
  EOF
82
75
 
83
- raw_comments = <<EOF
84
- Do something
85
-
86
- More explanation of what we do
87
-
88
- @param string a sequence of characters
89
- @return an integer value
90
- EOF
91
-
92
- actual = @parser.parse_text(name, contents)
76
+ actual = parse(name, contents)
93
77
  expected = [{:file => "function.h",
94
- :line => 9,
95
- :decl => "int some_function(\n char *string,\n size_t len)",
96
- :body => "int some_function(\n char *string,\n size_t len);",
97
- :rawComments => raw_comments.strip,
78
+ :line => 10,
79
+ :lineto => 12,
80
+ :tdef => nil,
98
81
  :type => :function,
82
+ :name => 'some_function',
83
+ :body => "int some_function(char *string, size_t len);",
84
+ :description => ' Do something',
85
+ :comments => " More explanation of what we do\n\n ",
86
+ :sig => 'char *::size_t',
99
87
  :args => [{
100
88
  :name => 'string',
101
89
  :type => 'char *',
@@ -104,19 +92,318 @@ EOF
104
92
  {
105
93
  :name => 'len',
106
94
  :type => 'size_t',
95
+ :comment => nil
107
96
  }],
108
97
  :return => {
109
98
  :type => 'int',
110
- :comment => 'an integer value'
99
+ :comment => ' an integer value'
111
100
  },
112
- :argline => "char *string,\n size_t len",
113
- :sig => 'char *::size_t',
114
- :description => 'Do something',
115
- :lineto => 11,
116
- :comments => "More explanation of what we do\n",
117
- :name => 'some_function'}]
101
+ :decl => "int some_function(char *string, size_t len)",
102
+ :argline => "char *string, size_t len",
103
+ }]
104
+
105
+ assert_equal expected, actual
106
+ end
107
+
108
+ def test_parsing_with_extern
109
+
110
+ name_a = 'common.h'
111
+ contents_a = <<EOF
112
+ # define GIT_EXTERN(type) extern type
113
+ EOF
114
+
115
+ name_b = 'function.h'
116
+ contents_b = <<EOF
117
+ #include "common.h"
118
+
119
+ /**
120
+ * Awesomest API
121
+ */
122
+ GIT_EXTERN(int) some_public_function(int val);
123
+ EOF
124
+
125
+ actual = @parser.parse_file(name_b, [[name_a, contents_a], [name_b, contents_b]])
126
+ # "Fix" the path so we remove the temp dir
127
+ actual[0][:file] = File.split(actual[0][:file])[-1]
128
+
129
+ expected = [{
130
+ :file => "function.h",
131
+ :line => 6,
132
+ :lineto => 6,
133
+ :tdef => nil,
134
+ :type => :function,
135
+ :name => "some_public_function",
136
+ :body => "int some_public_function(int val);",
137
+ :description => " Awesomest API",
138
+ :comments => "",
139
+ :sig => "int",
140
+ :args => [{
141
+ :name=>"val",
142
+ :type=>"int",
143
+ :comment=>nil
144
+ }],
145
+ :return => {
146
+ :type=>"int",
147
+ :comment=>nil
148
+ },
149
+ :decl =>"int some_public_function(int val)",
150
+ :argline =>"int val"
151
+ }]
152
+
153
+ assert_equal expected, actual
154
+
155
+ end
156
+
157
+
158
+ def test_return_struct
159
+ name = 'tree.h'
160
+ contents = <<EOF
161
+ typedef struct git_repository git_repository;
162
+ typedef struct git_tree git_tree;
163
+
164
+ /**
165
+ * Weak owner ref
166
+ */
167
+ git_repository *git_tree_owner(git_tree *tree);
168
+ EOF
169
+
170
+ actual = parse(name, contents)
171
+ expected = [{
172
+ :file => "tree.h",
173
+ :line => 7,
174
+ :lineto => 7,
175
+ :tdef => nil,
176
+ :type => :function,
177
+ :name => "git_tree_owner",
178
+ :body => "git_repository * git_tree_owner(git_tree *tree);",
179
+ :description => " Weak owner ref",
180
+ :comments => "",
181
+ :sig => "git_tree *",
182
+ :args => [{
183
+ :name => "tree",
184
+ :type => "git_tree *",
185
+ :comment => nil
186
+ }],
187
+ :return => {
188
+ :type => "git_repository *",
189
+ :comment => nil
190
+ },
191
+ :decl => "git_repository * git_tree_owner(git_tree *tree)",
192
+ :argline => "git_tree *tree"
193
+ }]
194
+
195
+ assert_equal actual, expected
196
+
197
+ end
198
+
199
+ def test_parse_struct
200
+
201
+ name = 'struct.h'
202
+
203
+ contents = <<EOF
204
+ /**
205
+ * Foo to the bar
206
+ */
207
+ typedef struct {
208
+ int val;
209
+ char *name;
210
+ } git_foo;
211
+ EOF
212
+
213
+ actual = parse(name, contents)
214
+
215
+ expected = [{
216
+ :file => "struct.h",
217
+ :line => 4,
218
+ :lineto => 7,
219
+ :tdef => :typedef,
220
+ :type => :struct,
221
+ :name => "git_foo",
222
+ :underlying_type => 'struct git_foo',
223
+ :description => " Foo to the bar",
224
+ :comments => "",
225
+ :fields => [
226
+ {
227
+ :type => "int",
228
+ :name => "val",
229
+ :comments => "",
230
+ },
231
+ {
232
+ :type => "char *",
233
+ :name => "name",
234
+ :comments => "",
235
+ }
236
+ ],
237
+ :decl => ["int val", "char * name"],
238
+ :block => "int val\nchar * name"
239
+ }]
240
+
241
+ assert_equal expected, actual
242
+
243
+ end
244
+
245
+ def test_parse_struct_with_field_docs
246
+
247
+ name = 'struct.h'
248
+
249
+ contents = <<EOF
250
+ /**
251
+ * Foo to the bar
252
+ */
253
+ typedef struct {
254
+ /**
255
+ * This stores a value
256
+ */
257
+ int val;
258
+ /**
259
+ * And this stores its name
260
+ *
261
+ * Which should be pretty descriptive
262
+ */
263
+ char *name;
264
+ } git_foo;
265
+ EOF
266
+
267
+ actual = parse(name, contents)
268
+ expected = [{
269
+ :file => "struct.h",
270
+ :line => 4,
271
+ :lineto => 15,
272
+ :tdef => :typedef,
273
+ :type => :struct,
274
+ :name => "git_foo",
275
+ :underlying_type => 'struct git_foo',
276
+ :description => " Foo to the bar",
277
+ :comments => "",
278
+ :fields => [
279
+ {
280
+ :type => "int",
281
+ :name => "val",
282
+ :comments => " This stores a value",
283
+ },
284
+ {
285
+ :type => "char *",
286
+ :name => "name",
287
+ :comments => " And this stores its name\n\n Which should be pretty descriptive",
288
+ }
289
+ ],
290
+ :decl => ["int val", "char * name"],
291
+ :block => "int val\nchar * name"
292
+ }]
293
+
294
+ assert_equal expected, actual
295
+
296
+ end
297
+
298
+ def test_parse_enum
299
+
300
+ name = 'enum.h'
301
+ contents = <<EOF
302
+ /**
303
+ * Magical enum of power
304
+ */
305
+ typedef enum {
306
+ FF = 0,
307
+ /** Do not allow fast-forwards */
308
+ NO_FF = 1 << 2
309
+ } git_merge_action;
310
+ EOF
311
+
312
+ actual = parse(name, contents)
313
+ expected = [{
314
+ :file => 'enum.h',
315
+ :line => 4,
316
+ :lineto => 8,
317
+ :tdef => :typedef,
318
+ :type => :enum,
319
+ :name => "git_merge_action",
320
+ :underlying_type => 'enum git_merge_action',
321
+ :description => " Magical enum of power",
322
+ :comments => "",
323
+ :fields => [{
324
+ :type => "int",
325
+ :name => "FF",
326
+ :comments => "",
327
+ :value => 0,
328
+ },
329
+ {
330
+ :type => "int",
331
+ :name => "NO_FF",
332
+ :comments => " Do not allow fast-forwards ",
333
+ :value => 4,
334
+ }],
335
+ :block => "FF\nNO_FF",
336
+ :decl => ["FF", "NO_FF"]
337
+ }]
118
338
 
119
339
  assert_equal expected, actual
340
+
341
+ end
342
+
343
+ def test_parse_define
344
+
345
+ name = 'define.h'
346
+ contents = <<EOF
347
+ /**
348
+ * Path separator
349
+ */
350
+ #define PATH_SEPARATOR '/'
351
+ EOF
352
+
353
+ actual = parse(name, contents)
354
+
355
+ #Clang won't let us do comments on defines :("
356
+ assert_equal [], actual
357
+
358
+ end
359
+
360
+ def test_type_reference
361
+
362
+ name = 'typeref.h'
363
+ contents = <<EOF
364
+ /**
365
+ * My very own type
366
+ */
367
+ typedef int my_type;
368
+ EOF
369
+
370
+ actual = parse(name, contents)
371
+ expected = [{
372
+ :file => "typeref.h",
373
+ :line => 4,
374
+ :lineto => 4,
375
+ :tdef => :typedef,
376
+ :name => "my_type",
377
+ :underlying_type => "int"
378
+ }]
379
+
380
+ assert_equal actual, expected
381
+
382
+ name = 'typeref.h'
383
+ contents = <<EOF
384
+ /**
385
+ * My very own type
386
+ */
387
+ typedef struct my_type my_type;
388
+ EOF
389
+
390
+ actual = parse(name, contents)
391
+ expected = [{
392
+ :file => "typeref.h",
393
+ :line => 4,
394
+ :lineto => 4,
395
+ :tdef => :typedef,
396
+ :name => "my_type",
397
+ :decl => 'my_type',
398
+ :underlying_type => "struct my_type",
399
+ :type => :struct,
400
+ :description => ' My very own type',
401
+ :comments => '',
402
+ }]
403
+
404
+ assert_equal actual, expected
405
+
406
+
120
407
  end
121
408
 
122
409
  end