ffi-clang 0.7.0 → 0.9.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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +3 -0
  3. data/ext/rakefile.rb +4 -0
  4. data/ext/teapot.rb +4 -3
  5. data/lib/ffi/clang/clang_version.rb +10 -19
  6. data/lib/ffi/clang/code_completion.rb +8 -20
  7. data/lib/ffi/clang/comment.rb +7 -19
  8. data/lib/ffi/clang/compilation_database.rb +4 -18
  9. data/lib/ffi/clang/cursor.rb +117 -35
  10. data/lib/ffi/clang/diagnostic.rb +11 -23
  11. data/lib/ffi/clang/file.rb +4 -18
  12. data/lib/ffi/clang/index.rb +19 -23
  13. data/lib/ffi/clang/lib/clang_version.rb +5 -19
  14. data/lib/ffi/clang/lib/code_completion.rb +13 -26
  15. data/lib/ffi/clang/lib/comment.rb +7 -20
  16. data/lib/ffi/clang/lib/compilation_database.rb +4 -18
  17. data/lib/ffi/clang/lib/cursor.rb +102 -28
  18. data/lib/ffi/clang/lib/diagnostic.rb +7 -20
  19. data/lib/ffi/clang/lib/file.rb +7 -20
  20. data/lib/ffi/clang/lib/inclusions.rb +5 -19
  21. data/lib/ffi/clang/lib/index.rb +25 -20
  22. data/lib/ffi/clang/lib/printing_policy.rb +47 -0
  23. data/lib/ffi/clang/lib/source_location.rb +5 -20
  24. data/lib/ffi/clang/lib/source_range.rb +5 -22
  25. data/lib/ffi/clang/lib/string.rb +4 -20
  26. data/lib/ffi/clang/lib/token.rb +4 -18
  27. data/lib/ffi/clang/lib/translation_unit.rb +19 -21
  28. data/lib/ffi/clang/lib/type.rb +87 -22
  29. data/lib/ffi/clang/lib.rb +24 -28
  30. data/lib/ffi/clang/printing_policy.rb +36 -0
  31. data/lib/ffi/clang/source_location.rb +42 -38
  32. data/lib/ffi/clang/source_range.rb +7 -22
  33. data/lib/ffi/clang/token.rb +4 -18
  34. data/lib/ffi/clang/translation_unit.rb +10 -20
  35. data/lib/ffi/clang/type.rb +52 -25
  36. data/lib/ffi/clang/unsaved_file.rb +6 -20
  37. data/lib/ffi/clang/version.rb +7 -21
  38. data/lib/ffi/clang.rb +9 -20
  39. data/license.md +39 -0
  40. data/readme.md +56 -0
  41. data.tar.gz.sig +0 -0
  42. metadata +62 -116
  43. metadata.gz.sig +0 -0
  44. data/.editorconfig +0 -23
  45. data/.gitignore +0 -19
  46. data/.rspec +0 -5
  47. data/.travis.yml +0 -30
  48. data/Gemfile +0 -12
  49. data/README.md +0 -74
  50. data/Rakefile +0 -12
  51. data/examples/docs.cpp +0 -25
  52. data/examples/docs.rb +0 -31
  53. data/ffi-clang.gemspec +0 -25
  54. data/spec/ffi/clang/code_completion_spec.rb +0 -181
  55. data/spec/ffi/clang/comment_spec.rb +0 -453
  56. data/spec/ffi/clang/compilation_database_spec.rb +0 -180
  57. data/spec/ffi/clang/cursor_spec.rb +0 -741
  58. data/spec/ffi/clang/diagnostic_spec.rb +0 -89
  59. data/spec/ffi/clang/file_spec.rb +0 -82
  60. data/spec/ffi/clang/fixtures/a.c +0 -7
  61. data/spec/ffi/clang/fixtures/canonical.c +0 -5
  62. data/spec/ffi/clang/fixtures/class.cpp +0 -8
  63. data/spec/ffi/clang/fixtures/compile_commands.json +0 -17
  64. data/spec/ffi/clang/fixtures/completion.cxx +0 -8
  65. data/spec/ffi/clang/fixtures/docs.c +0 -1
  66. data/spec/ffi/clang/fixtures/docs.cc +0 -1
  67. data/spec/ffi/clang/fixtures/docs.h +0 -54
  68. data/spec/ffi/clang/fixtures/list.c +0 -11
  69. data/spec/ffi/clang/fixtures/location1.c +0 -7
  70. data/spec/ffi/clang/fixtures/simple.ast +0 -0
  71. data/spec/ffi/clang/fixtures/simple.c +0 -3
  72. data/spec/ffi/clang/fixtures/test.cxx +0 -62
  73. data/spec/ffi/clang/index_spec.rb +0 -90
  74. data/spec/ffi/clang/source_location_spec.rb +0 -138
  75. data/spec/ffi/clang/source_range_spec.rb +0 -74
  76. data/spec/ffi/clang/token_spec.rb +0 -82
  77. data/spec/ffi/clang/translation_unit_spec.rb +0 -220
  78. data/spec/ffi/clang/type_spec.rb +0 -273
  79. data/spec/ffi/clang/version_spec.rb +0 -28
  80. data/spec/spec_helper.rb +0 -51
@@ -1,181 +0,0 @@
1
- # Copyright, 2014, by Masahiro Sano.
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- describe CodeCompletion do
22
- let(:filename) { fixture_path("completion.cxx") }
23
- let(:translation_unit) { Index.new.parse_translation_unit(filename) }
24
- let(:line) { 7 }
25
- let(:column) { 6 }
26
- let(:results) { translation_unit.code_complete(filename, line, column) }
27
-
28
- describe "self.default_code_completion_options" do
29
- let(:options) { FFI::Clang::CodeCompletion.default_code_completion_options }
30
- it "returns a default set of code-completion options" do
31
- expect(options).to be_kind_of(Hash)
32
- options.keys.each { |key|
33
- expect(FFI::Clang::Lib::CodeCompleteFlags.symbols).to include(key)
34
- }
35
- end
36
- end
37
-
38
- describe CodeCompletion::Results do
39
- it "can be obtained from a translation unit" do
40
- expect(results).to be_kind_of(CodeCompletion::Results)
41
-
42
- # At least 40 results, depends on standard library implementation:
43
- expect(results.size).to be >= 40
44
-
45
- expect(results.results).to be_kind_of(Array)
46
- expect(results.results.first).to be_kind_of(CodeCompletion::Result)
47
- end
48
-
49
- it "calls dispose_code_complete_results on GC" do
50
- expect(Lib).to receive(:dispose_code_complete_results).at_least(:once)
51
- expect{results.free}.not_to raise_error
52
- end
53
-
54
- it "#each" do
55
- spy = double(stub: nil)
56
- expect(spy).to receive(:stub).exactly(results.size).times
57
- results.each { spy.stub }
58
- end
59
-
60
- it "#num_diagnostics" do
61
- expect(results.num_diagnostics).to eq(2)
62
- end
63
-
64
- it "#diagnostic" do
65
- expect(results.diagnostic(0)).to be_kind_of(Diagnostic)
66
- end
67
-
68
- it "#diagnostics" do
69
- expect(results.diagnostics).to be_kind_of(Array)
70
- expect(results.diagnostics.first).to be_kind_of(Diagnostic)
71
- expect(results.diagnostics.size).to eq(results.num_diagnostics)
72
- end
73
-
74
- it "#contexts" do
75
- expect(results.contexts).to be_kind_of(Hash)
76
- results.contexts.keys.each { |key|
77
- expect(FFI::Clang::Lib::CompletionContext.symbols).to include(key)
78
- }
79
- end
80
-
81
- it "#container_usr" do
82
- expect(results.container_usr).to be_kind_of(String)
83
- expect(results.container_usr).to match(/std.+vector/)
84
- end
85
-
86
- it "#container_kind" do
87
- expect(results.container_kind).to be_kind_of(Symbol)
88
- expect(results.container_kind).to eq(:cursor_class_decl)
89
- end
90
-
91
- it "#incomplete?" do
92
- expect(results.incomplete?).to be false
93
- end
94
-
95
- it "#objc_selector" do
96
- #TODO
97
- end
98
-
99
- it "#sort!" do
100
- results.sort!
101
-
102
- possibilities = results.first.string.chunks.select{|x| x[:kind] == :typed_text}.collect{|chunk| chunk[:text]}
103
-
104
- # may be sorted with typed_text kind, first result will start with 'a'.. not necessarily
105
- expect(possibilities).to be == possibilities.sort
106
- end
107
- end
108
-
109
- describe CodeCompletion::Result do
110
- let(:result) { results.results.first }
111
- it "#string" do
112
- expect(result.string).to be_kind_of(CodeCompletion::String)
113
- end
114
-
115
- it "#kind" do
116
- expect(result.kind).to be_kind_of(Symbol)
117
- end
118
- end
119
-
120
- describe CodeCompletion::String do
121
- let(:str) { results.sort!; results.find{|x| x.string.chunk_text(1) == 'assign'}.string }
122
-
123
- it "#num_chunks" do
124
- expect(str.num_chunks).to be >= 5
125
- end
126
-
127
- it "#chunk_kind" do
128
- expect(str.chunk_kind(0)).to eq(:result_type)
129
- expect(str.chunk_kind(1)).to eq(:typed_text)
130
- end
131
-
132
- it "#chunk_text" do
133
- expect(str.chunk_text(0)).to be =~ /void/
134
- expect(str.chunk_text(1)).to eq('assign')
135
- end
136
-
137
- it "#chunk_completion" do
138
- expect(str.chunk_completion(0)).to be_kind_of(CodeCompletion::String)
139
- end
140
-
141
- it "#chunks" do
142
- expect(str.chunks).to be_kind_of(Array)
143
- expect(str.chunks.first).to be_kind_of(Hash)
144
- expect(str.chunks.size).to eq(str.num_chunks)
145
- end
146
-
147
- it "#priority" do
148
- expect(str.priority).to be_kind_of(Integer)
149
- end
150
-
151
- it "#availability" do
152
- expect(str.availability).to be_kind_of(Symbol)
153
- expect(str.availability).to eq(:available)
154
- end
155
-
156
- it "#num_annotations" do
157
- expect(str.num_annotations).to be_kind_of(Integer)
158
- expect(str.num_annotations).to eq(0)
159
- end
160
-
161
- it "#annotation" do
162
- expect(str.annotation(100)).to be_nil
163
- # TODO: need tests for String which has annotation
164
- end
165
-
166
- it "#annotations" do
167
- expect(str.annotations).to be_kind_of(Array)
168
- # TODO: need tests for String which has annotation
169
- end
170
-
171
- it "#parent" do
172
- expect(str.parent).to be_kind_of(String)
173
- expect(str.parent).to be =~ /std.+vector/
174
- end
175
-
176
- it "#comment" do
177
- expect(str.comment).to be_nil
178
- # TODO: need tests for String which has real comment
179
- end
180
- end
181
- end
@@ -1,453 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # Copyright, 2013, by Carlos Martín Nieto <cmn@dwim.me>
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
-
22
- describe Comment do
23
- let(:cursor) { Index.new.parse_translation_unit(fixture_path("docs.cc")).cursor }
24
- let (:comment) { find_first(cursor, :cursor_function).comment }
25
-
26
- it "can be obtained from a cursor" do
27
- expect(comment).to be_kind_of(Comment)
28
- expect(comment).to be_kind_of(FullComment)
29
- expect(comment.kind).to equal(:comment_full)
30
- end
31
-
32
- it "can parse the brief description" do
33
- para = comment.child
34
- expect(para.kind).to equal(:comment_paragraph)
35
- expect(para).to be_kind_of(ParagraphComment)
36
- text = para.child
37
- expect(text.kind).to equal(:comment_text)
38
- expect(text).to be_kind_of(TextComment)
39
- expect(text.text.strip).to eq("Short explanation")
40
- end
41
-
42
- it "can parse the longer description" do
43
- para = comment.child(1)
44
- expect(para.kind).to equal(:comment_paragraph)
45
- expect(para.num_children).to equal(2)
46
-
47
- lines = (0..para.num_children-1).map do |i|
48
- para.child(i).text
49
- end
50
-
51
- expect(lines).to eq([" This is a longer explanation",
52
- " that spans multiple lines"])
53
- end
54
-
55
- it "has working helpers" do
56
- expect(comment.num_children).to equal(8)
57
-
58
- para = comment.child(1)
59
- expect(para.text).to eq(" This is a longer explanation\n that spans multiple lines")
60
- end
61
-
62
- it "understands params" do
63
- [['input', " some input\n "], ['flags', " some flags\n "]].each_with_index do |v, child_idx|
64
- param = comment.child(3 + child_idx)
65
- expect(param).to be_kind_of(ParamCommandComment)
66
-
67
- expect(param.valid_index?).to be_truthy
68
- expect(param.index).to be == child_idx
69
- expect(param.name).to be == v[0]
70
- expect(param.child.text).to be == v[1]
71
- expect(param.comment).to be == v[1]
72
- end
73
- end
74
-
75
- describe "#whitespace?" do
76
- it "checks the comment is whitespace" do
77
- expect(comment.child.whitespace?).to be false
78
- end
79
- end
80
-
81
- describe "#has_trailing_newline?" do
82
- it "checks the content has a traling newline" do
83
- expect(comment.child.has_trailing_newline?).to be false
84
- end
85
- end
86
-
87
- context 'comment_null' do
88
- let(:comment_cursor) { find_matching(cursor) { |child, parent|
89
- child.kind == :cursor_function and child.spelling == 'no_comment_function' } }
90
- let(:comment) { comment_cursor.comment }
91
-
92
- it "is null comment" do
93
- expect(comment).to be_kind_of(Comment)
94
- expect(comment.kind).to eq(:comment_null)
95
- expect(comment.text).to eq('')
96
- end
97
- end
98
-
99
- context 'unknown comment type' do
100
- let(:comment) { 'foobar' }
101
- it "raises NotImplementedError" do
102
- expect(Lib).to receive(:comment_get_kind).with(comment).and_return(:xxx_yyy_zzzz)
103
- expect{Comment.build_from(comment)}.to raise_error(NotImplementedError)
104
- end
105
- end
106
-
107
- describe HTMLStartTagComment do
108
- let(:comment_cursor) { find_matching(cursor) { |child, parent|
109
- child.kind == :cursor_function and child.spelling == 'b_function' } }
110
- let(:comment) { comment_cursor.comment }
111
- let(:paragraph) { comment_cursor.comment.child }
112
- let(:html_start_tag_comments) { paragraph.children.select{|c| c.kind == :comment_html_start_tag} }
113
-
114
- it "can be obtained from cursor" do
115
- expect(comment).to be_kind_of(FullComment)
116
- expect(comment.kind).to equal(:comment_full)
117
- expect(paragraph).to be_kind_of(ParagraphComment)
118
- expect(html_start_tag_comments.first).to be_kind_of(HTMLStartTagComment)
119
- expect(html_start_tag_comments.size).to eq(2)
120
- end
121
-
122
- describe "#tag" do
123
- it "returns HTML tag name" do
124
- expect(html_start_tag_comments[0].tag).to eq('br')
125
- expect(html_start_tag_comments[1].tag).to eq('a')
126
- end
127
-
128
- it "is alias method of #name" do
129
- expect(html_start_tag_comments[0].name).to eq('br')
130
- expect(html_start_tag_comments[1].name).to eq('a')
131
- end
132
- end
133
-
134
- describe "#text" do
135
- it "returns HTML tag as string" do
136
- expect(html_start_tag_comments[0].text.strip).to eq('<br/>')
137
- expect(html_start_tag_comments[1].text.strip).to eq('<a href="http://example.org/">')
138
- end
139
- end
140
-
141
- describe "#self_closing?" do
142
- it "checks the tag is self-closing" do
143
- expect(html_start_tag_comments[0].self_closing?).to be true
144
- expect(html_start_tag_comments[1].self_closing?).to be false
145
- end
146
- end
147
-
148
- describe "#num_attrs" do
149
- it "returns the number of attributes" do
150
- expect(html_start_tag_comments[0].num_attrs).to eq(0)
151
- expect(html_start_tag_comments[1].num_attrs).to eq(1)
152
- end
153
- end
154
-
155
- describe "#attrs" do
156
- it "returns attributes as Array of Hash" do
157
- expect(html_start_tag_comments[0].attrs).to eq([])
158
- expect(html_start_tag_comments[1].attrs).to eq([{name: 'href', value: 'http://example.org/'}])
159
- end
160
- end
161
- end
162
-
163
- describe HTMLEndTagComment do
164
- let(:comment_cursor) { find_matching(cursor) { |child, parent|
165
- child.kind == :cursor_function and child.spelling == 'b_function' } }
166
- let(:comment) { comment_cursor.comment }
167
- let(:paragraph) { comment_cursor.comment.child }
168
- let(:html_end_tag_comment) { paragraph.children.select{|c| c.kind == :comment_html_end_tag}.first }
169
-
170
- it "can be obtained from cursor" do
171
- expect(comment).to be_kind_of(FullComment)
172
- expect(comment.kind).to equal(:comment_full)
173
- expect(paragraph).to be_kind_of(ParagraphComment)
174
- expect(html_end_tag_comment).to be_kind_of(HTMLEndTagComment)
175
- end
176
-
177
- describe "#tag" do
178
- it "returns HTML tag name" do
179
- expect(html_end_tag_comment.tag).to eq('a')
180
- end
181
-
182
- it "is alias method of #name" do
183
- expect(html_end_tag_comment.name).to eq('a')
184
- end
185
- end
186
-
187
- describe "#text" do
188
- it "returns HTML tag as string" do
189
- expect(html_end_tag_comment.text.strip).to eq('</a>')
190
- end
191
- end
192
- end
193
-
194
- describe FullComment do
195
- let(:comment_cursor) { find_matching(cursor) { |child, parent|
196
- child.kind == :cursor_function and child.spelling == 'f_function' } }
197
- let(:comment) { comment_cursor.comment }
198
-
199
- it "can be obtained from cursor" do
200
- expect(comment).to be_kind_of(FullComment)
201
- expect(comment.kind).to equal(:comment_full)
202
- end
203
-
204
- describe "#to_html" do
205
- it "converts a given full parsed comment to an HTML fragment" do
206
- expect(comment.to_html).to be_kind_of(String)
207
- expect(comment.to_html).to eq('<p class="para-brief"> this is a function.</p>')
208
- end
209
- end
210
-
211
- describe "#to_xml" do
212
- it "converts a given full parsed comment to an XML document" do
213
- expect(comment.to_xml).to be_kind_of(String)
214
- end
215
- end
216
- end
217
-
218
- describe BlockCommandComment do
219
- let(:comment_cursor) { find_matching(cursor) { |child, parent|
220
- child.kind == :cursor_function and child.spelling == 'f_function' } }
221
- let(:comment) { comment_cursor.comment }
222
- let(:block_cmd_comment) { comment.children.select{|c| c.kind == :comment_block_command}.first }
223
-
224
- it "can be obtained from cursor" do
225
- expect(comment).to be_kind_of(FullComment)
226
- expect(comment.kind).to equal(:comment_full)
227
- expect(block_cmd_comment).to be_kind_of(BlockCommandComment)
228
- expect(block_cmd_comment.child).to be_kind_of(ParagraphComment)
229
- end
230
-
231
- describe "#name" do
232
- it "returns the name of the block command" do
233
- expect(block_cmd_comment.name).to eq("brief")
234
- end
235
- end
236
-
237
- describe "#paragraph" do
238
- it "returns the paragraph" do
239
- expect(block_cmd_comment.paragraph).to be_kind_of(ParagraphComment)
240
- end
241
- end
242
-
243
- describe "#num_args" do
244
- it "returns the number of word-like arguments" do
245
- expect(block_cmd_comment.num_args).to eq(0)
246
- end
247
- end
248
-
249
- describe "#args" do
250
- it "returns word-like arguments" do
251
- expect(block_cmd_comment.args).to be_kind_of(Array)
252
- expect(block_cmd_comment.args).to eq([])
253
- end
254
-
255
- #TODO: needs tests with comments which have arguments
256
- end
257
-
258
- describe "#text" do
259
- it "returns readble text that includes children's comments" do
260
- expect(block_cmd_comment.text).to be_kind_of(String)
261
- expect(block_cmd_comment.text.strip).to eq('this is a function.')
262
- end
263
-
264
- it "is a alias method of #comment" do
265
- expect(block_cmd_comment.comment).to eq(block_cmd_comment.text)
266
- end
267
- end
268
- end
269
-
270
- describe InlineCommandComment do
271
- let(:comment_cursor) { find_matching(cursor) { |child, parent|
272
- child.kind == :cursor_function and child.spelling == 'd_function' } }
273
- let(:comment) { comment_cursor.comment }
274
- let(:inline_command_comments) { comment.child.children.select{|c| c.kind == :comment_inline_command} }
275
-
276
- it "can be obtained from cursor" do
277
- expect(comment).to be_kind_of(FullComment)
278
- expect(comment.kind).to equal(:comment_full)
279
- expect(comment.child).to be_kind_of(ParagraphComment)
280
- expect(inline_command_comments.size).to eq(2)
281
- end
282
-
283
- describe "#name" do
284
- it "returns the name of the inline command" do
285
- expect(inline_command_comments[0].name).to eq("em")
286
- expect(inline_command_comments[1].name).to eq("b")
287
- end
288
- end
289
-
290
- describe "#render_kind" do
291
- it "returns the most appropriate rendering mode" do
292
- expect(inline_command_comments[0].render_kind).to eq(:emphasized)
293
- expect(inline_command_comments[1].render_kind).to eq(:bold)
294
- end
295
- end
296
-
297
- describe "#num_args" do
298
- it "returns number of command arguments" do
299
- expect(inline_command_comments[0].num_args).to eq(1)
300
- expect(inline_command_comments[1].num_args).to eq(1)
301
- end
302
- end
303
-
304
- describe "#args" do
305
- it "returns arguments as Array" do
306
- expect(inline_command_comments[0].args).to eq(["foo"])
307
- expect(inline_command_comments[1].args).to eq(["bar"])
308
- end
309
- end
310
-
311
- describe "#text" do
312
- it "returns readble text" do
313
- expect(inline_command_comments[0].text.strip).to eq("foo")
314
- expect(inline_command_comments[1].text.strip).to eq("bar")
315
- end
316
- end
317
- end
318
-
319
- describe VerbatimBlockCommandComment do
320
- let(:comment_cursor) { find_matching(cursor) { |child, parent|
321
- child.kind == :cursor_function and child.spelling == 'e_function' } }
322
- let(:comment) { comment_cursor.comment }
323
- let(:verb_block_cmd_comment) { comment.children.select{|c| c.kind == :comment_verbatim_block_command}.first }
324
-
325
- it "can be obtained from cursor" do
326
- expect(comment).to be_kind_of(FullComment)
327
- expect(comment.kind).to equal(:comment_full)
328
- expect(verb_block_cmd_comment).to be_kind_of(VerbatimBlockCommandComment)
329
- end
330
-
331
- describe "#text" do
332
- it "returns readble text" do
333
- expect(verb_block_cmd_comment.text).to eq(" foo bar\n baz")
334
- end
335
- end
336
- end
337
-
338
- describe VerbatimBlockLineComment do
339
- let(:comment_cursor) { find_matching(cursor) { |child, parent|
340
- child.kind == :cursor_function and child.spelling == 'e_function' } }
341
- let(:comment) { comment_cursor.comment }
342
- let(:verb_block_cmd_comment) { comment.children.select{|c| c.kind == :comment_verbatim_block_command}.first }
343
- let(:verb_block_line_comments) { verb_block_cmd_comment.children }
344
-
345
- it "can be obtained from cursor" do
346
- expect(comment).to be_kind_of(FullComment)
347
- expect(comment.kind).to equal(:comment_full)
348
- expect(verb_block_cmd_comment).to be_kind_of(VerbatimBlockCommandComment)
349
- expect(verb_block_line_comments.first).to be_kind_of(VerbatimBlockLineComment)
350
- expect(verb_block_line_comments.size).to eq(2)
351
- end
352
-
353
- describe "#text" do
354
- it "returns readble text" do
355
- expect(verb_block_line_comments[0].text.strip).to eq("foo bar")
356
- expect(verb_block_line_comments[1].text.strip).to eq("baz")
357
- end
358
- end
359
- end
360
-
361
- describe VerbatimLine do
362
- # TODO: how to generate this comment?
363
- end
364
-
365
- describe ParamCommandComment do
366
- let(:comment_cursor) { find_matching(cursor) { |child, parent|
367
- child.kind == :cursor_function and child.spelling == 'a_function' } }
368
- let(:comment) { comment_cursor.comment }
369
- let(:param_cmd_comments) { comment.children.select{|c| c.kind == :comment_param_command} }
370
-
371
- it "can be obtained from cursor" do
372
- expect(comment).to be_kind_of(FullComment)
373
- expect(comment.kind).to equal(:comment_full)
374
- expect(param_cmd_comments.first).to be_kind_of(ParamCommandComment)
375
- expect(param_cmd_comments.size).to eq(4)
376
- end
377
-
378
- describe "#text" do
379
- it "returns readble text" do
380
- expect(param_cmd_comments[0].text.strip).to eq("some input")
381
- expect(param_cmd_comments[1].text.strip).to eq("some flags")
382
- end
383
- end
384
-
385
- describe "#direction_explicit?" do
386
- it "checks the direction is specified explicitly" do
387
- expect(param_cmd_comments[0].direction_explicit?).to be true
388
- expect(param_cmd_comments[3].direction_explicit?).to be false
389
- end
390
- end
391
-
392
- describe "#direction" do
393
- it "returns parameter passing direction" do
394
- expect(param_cmd_comments[0].direction).to eq(:pass_direction_in)
395
- expect(param_cmd_comments[1].direction).to eq(:pass_direction_out)
396
- expect(param_cmd_comments[2].direction).to eq(:pass_direction_inout)
397
- expect(param_cmd_comments[3].direction).to eq(:pass_direction_in)
398
- end
399
- end
400
- end
401
-
402
- describe TParamCommandComment do
403
- let(:comment_cursor) { find_matching(cursor) { |child, parent|
404
- child.kind == :cursor_function_template and child.spelling == 'c_function' } }
405
- let(:comment) { comment_cursor.comment }
406
- let(:tparam_cmd_comments) { comment.children.select{|c| c.kind == :comment_tparam_command} }
407
-
408
- it "can be obtained from cursor" do
409
- expect(comment).to be_kind_of(FullComment)
410
- expect(comment.kind).to equal(:comment_full)
411
- expect(tparam_cmd_comments.first).to be_kind_of(TParamCommandComment)
412
- expect(tparam_cmd_comments.size).to eq(3)
413
- end
414
-
415
- describe "#text" do
416
- it "returns readble text" do
417
- expect(tparam_cmd_comments[0].text.strip).to eq("some type of foo")
418
- expect(tparam_cmd_comments[1].text.strip).to eq("some type of bar")
419
- end
420
- end
421
-
422
- describe "#name" do
423
- it "returns template parameter name" do
424
- expect(tparam_cmd_comments[0].name).to eq("T1")
425
- expect(tparam_cmd_comments[1].name).to eq("T2")
426
- expect(tparam_cmd_comments[2].name).to eq("T3")
427
- end
428
- end
429
-
430
- describe "#valid_position?" do
431
- it "checks this parameter has valid position" do
432
- expect(tparam_cmd_comments[0].valid_position?).to be true
433
- end
434
- end
435
-
436
- describe "#depth" do
437
- it "returns nesting depth of this parameter" do
438
- expect(tparam_cmd_comments[0].depth).to eq(1)
439
- expect(tparam_cmd_comments[1].depth).to eq(2)
440
- expect(tparam_cmd_comments[2].depth).to eq(1)
441
- end
442
- end
443
-
444
- describe "#index" do
445
- it "returns index of the parameter at the given nesting depth" do
446
- expect(tparam_cmd_comments[0].index(0)).to eq(0)
447
- expect(tparam_cmd_comments[1].index(0)).to eq(1)
448
- expect(tparam_cmd_comments[1].index(1)).to eq(0)
449
- expect(tparam_cmd_comments[2].index(0)).to eq(1)
450
- end
451
- end
452
- end
453
- end