yard 0.9.23 → 0.9.27
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.dockerignore +0 -0
- data/.gitattributes +4 -0
- data/.github/FUNDING.yml +3 -0
- data/.github/ISSUE_TEMPLATE.md +6 -6
- data/.github/PULL_REQUEST_TEMPLATE.md +5 -5
- data/.github/workflows/ci.yml +30 -0
- data/.github/workflows/gem.yml +19 -0
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/.rubocop.yml +37 -24
- data/.yardopts +0 -0
- data/.yardopts_guide +0 -0
- data/.yardopts_i18n +0 -0
- data/CHANGELOG.md +50 -4
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +5 -3
- data/README.md +97 -102
- data/Rakefile +2 -3
- data/lib/yard/cli/diff.rb +4 -1
- data/lib/yard/cli/server.rb +22 -13
- data/lib/yard/cli/stats.rb +2 -0
- data/lib/yard/cli/yardoc.rb +2 -1
- data/lib/yard/code_objects/method_object.rb +1 -1
- data/lib/yard/code_objects/namespace_mapper.rb +30 -3
- data/lib/yard/code_objects/proxy.rb +2 -1
- data/lib/yard/globals.rb +1 -1
- data/lib/yard/handlers/c/base.rb +35 -0
- data/lib/yard/handlers/ruby/method_handler.rb +1 -1
- data/lib/yard/handlers/ruby/mixin_handler.rb +7 -2
- data/lib/yard/handlers/ruby/module_function_handler.rb +15 -3
- data/lib/yard/parser/ruby/ast_node.rb +2 -2
- data/lib/yard/parser/ruby/ruby_parser.rb +7 -5
- data/lib/yard/parser/ruby/token_resolver.rb +3 -1
- data/lib/yard/parser/source_parser.rb +1 -1
- data/lib/yard/registry_resolver.rb +10 -24
- data/lib/yard/registry_store.rb +1 -1
- data/lib/yard/serializers/yardoc_serializer.rb +1 -1
- data/lib/yard/server/commands/base.rb +2 -2
- data/lib/yard/server/commands/library_command.rb +1 -1
- data/lib/yard/tags/directives.rb +10 -1
- data/lib/yard/templates/helpers/html_helper.rb +15 -5
- data/lib/yard/templates/helpers/markup/rdoc_markup.rb +5 -4
- data/lib/yard/templates/helpers/markup_helper.rb +2 -1
- data/lib/yard/templates/section.rb +1 -3
- data/lib/yard/version.rb +1 -1
- data/lib/yard.rb +3 -0
- data/samus.json +15 -46
- data/tasks/prepare_tag.rake +45 -0
- data/tasks/update_error_map.rake +53 -0
- data/templates/default/fulldoc/html/css/style.css +1 -0
- data/yard.gemspec +3 -2
- metadata +23 -207
- data/.travis.yml +0 -52
- data/spec/cli/command_parser_spec.rb +0 -43
- data/spec/cli/command_spec.rb +0 -36
- data/spec/cli/config_spec.rb +0 -148
- data/spec/cli/diff_spec.rb +0 -254
- data/spec/cli/display_spec.rb +0 -30
- data/spec/cli/gems_spec.rb +0 -81
- data/spec/cli/graph_spec.rb +0 -18
- data/spec/cli/help_spec.rb +0 -22
- data/spec/cli/i18n_spec.rb +0 -107
- data/spec/cli/list_spec.rb +0 -8
- data/spec/cli/markup_types_spec.rb +0 -22
- data/spec/cli/server_spec.rb +0 -324
- data/spec/cli/stats_spec.rb +0 -96
- data/spec/cli/yard_on_yard_spec.rb +0 -38
- data/spec/cli/yardoc_spec.rb +0 -896
- data/spec/cli/yri_spec.rb +0 -101
- data/spec/code_objects/base_spec.rb +0 -485
- data/spec/code_objects/class_object_spec.rb +0 -226
- data/spec/code_objects/code_object_list_spec.rb +0 -36
- data/spec/code_objects/constants_spec.rb +0 -116
- data/spec/code_objects/extra_file_object_spec.rb +0 -161
- data/spec/code_objects/macro_object_spec.rb +0 -150
- data/spec/code_objects/method_object_spec.rb +0 -184
- data/spec/code_objects/module_object_spec.rb +0 -142
- data/spec/code_objects/namespace_object_spec.rb +0 -171
- data/spec/code_objects/proxy_spec.rb +0 -147
- data/spec/code_objects/spec_helper.rb +0 -3
- data/spec/config_spec.rb +0 -171
- data/spec/core_ext/array_spec.rb +0 -13
- data/spec/core_ext/file_spec.rb +0 -72
- data/spec/core_ext/hash_spec.rb +0 -14
- data/spec/core_ext/insertion_spec.rb +0 -37
- data/spec/core_ext/module_spec.rb +0 -9
- data/spec/core_ext/string_spec.rb +0 -42
- data/spec/core_ext/symbol_hash_spec.rb +0 -89
- data/spec/docstring_parser_spec.rb +0 -280
- data/spec/docstring_spec.rb +0 -373
- data/spec/handlers/alias_handler_spec.rb +0 -82
- data/spec/handlers/attribute_handler_spec.rb +0 -96
- data/spec/handlers/base_spec.rb +0 -216
- data/spec/handlers/c/alias_handler_spec.rb +0 -34
- data/spec/handlers/c/attribute_handler_spec.rb +0 -41
- data/spec/handlers/c/class_handler_spec.rb +0 -78
- data/spec/handlers/c/constant_handler_spec.rb +0 -71
- data/spec/handlers/c/init_handler_spec.rb +0 -48
- data/spec/handlers/c/method_handler_spec.rb +0 -327
- data/spec/handlers/c/mixin_handler_spec.rb +0 -44
- data/spec/handlers/c/module_handler_spec.rb +0 -71
- data/spec/handlers/c/override_comment_handler_spec.rb +0 -47
- data/spec/handlers/c/path_handler_spec.rb +0 -36
- data/spec/handlers/c/spec_helper.rb +0 -23
- data/spec/handlers/c/struct_handler_spec.rb +0 -16
- data/spec/handlers/class_condition_handler_spec.rb +0 -87
- data/spec/handlers/class_handler_spec.rb +0 -247
- data/spec/handlers/class_method_handler_shared_examples.rb +0 -133
- data/spec/handlers/class_variable_handler_spec.rb +0 -12
- data/spec/handlers/constant_handler_spec.rb +0 -112
- data/spec/handlers/decorator_handler_methods_spec.rb +0 -393
- data/spec/handlers/dsl_handler_spec.rb +0 -226
- data/spec/handlers/examples/alias_handler_001.rb.txt +0 -46
- data/spec/handlers/examples/attribute_handler_001.rb.txt +0 -32
- data/spec/handlers/examples/class_condition_handler_001.rb.txt +0 -69
- data/spec/handlers/examples/class_handler_001.rb.txt +0 -120
- data/spec/handlers/examples/class_variable_handler_001.rb.txt +0 -10
- data/spec/handlers/examples/constant_handler_001.rb.txt +0 -35
- data/spec/handlers/examples/dsl_handler_001.rb.txt +0 -156
- data/spec/handlers/examples/exception_handler_001.rb.txt +0 -59
- data/spec/handlers/examples/extend_handler_001.rb.txt +0 -19
- data/spec/handlers/examples/method_condition_handler_001.rb.txt +0 -10
- data/spec/handlers/examples/method_handler_001.rb.txt +0 -128
- data/spec/handlers/examples/mixin_handler_001.rb.txt +0 -40
- data/spec/handlers/examples/module_handler_001.rb.txt +0 -29
- data/spec/handlers/examples/private_constant_handler_001.rb.txt +0 -8
- data/spec/handlers/examples/process_handler_001.rb.txt +0 -11
- data/spec/handlers/examples/visibility_handler_001.rb.txt +0 -36
- data/spec/handlers/examples/yield_handler_001.rb.txt +0 -54
- data/spec/handlers/exception_handler_spec.rb +0 -49
- data/spec/handlers/extend_handler_spec.rb +0 -28
- data/spec/handlers/legacy_base_spec.rb +0 -128
- data/spec/handlers/method_condition_handler_spec.rb +0 -15
- data/spec/handlers/method_handler_spec.rb +0 -214
- data/spec/handlers/mixin_handler_spec.rb +0 -60
- data/spec/handlers/module_function_handler_spec.rb +0 -106
- data/spec/handlers/module_handler_spec.rb +0 -35
- data/spec/handlers/private_class_method_handler_spec.rb +0 -11
- data/spec/handlers/private_constant_handler_spec.rb +0 -25
- data/spec/handlers/processor_spec.rb +0 -35
- data/spec/handlers/public_class_method_handler_spec.rb +0 -11
- data/spec/handlers/ruby/base_spec.rb +0 -95
- data/spec/handlers/ruby/legacy/base_spec.rb +0 -84
- data/spec/handlers/spec_helper.rb +0 -33
- data/spec/handlers/visibility_handler_spec.rb +0 -44
- data/spec/handlers/yield_handler_spec.rb +0 -52
- data/spec/i18n/locale_spec.rb +0 -81
- data/spec/i18n/message_spec.rb +0 -52
- data/spec/i18n/messages_spec.rb +0 -67
- data/spec/i18n/pot_generator_spec.rb +0 -295
- data/spec/i18n/text_spec.rb +0 -184
- data/spec/logging_spec.rb +0 -44
- data/spec/options_spec.rb +0 -171
- data/spec/parser/base_spec.rb +0 -24
- data/spec/parser/c_parser_spec.rb +0 -236
- data/spec/parser/examples/array.c.txt +0 -6267
- data/spec/parser/examples/example1.rb.txt +0 -8
- data/spec/parser/examples/extrafile.c.txt +0 -8
- data/spec/parser/examples/file.c.txt +0 -28
- data/spec/parser/examples/multifile.c.txt +0 -22
- data/spec/parser/examples/namespace.cpp.txt +0 -68
- data/spec/parser/examples/override.c.txt +0 -424
- data/spec/parser/examples/parse_in_order_001.rb.txt +0 -2
- data/spec/parser/examples/parse_in_order_002.rb.txt +0 -2
- data/spec/parser/examples/tag_handler_001.rb.txt +0 -8
- data/spec/parser/ruby/ast_node_spec.rb +0 -33
- data/spec/parser/ruby/legacy/statement_list_spec.rb +0 -299
- data/spec/parser/ruby/legacy/token_list_spec.rb +0 -79
- data/spec/parser/ruby/ruby_parser_spec.rb +0 -508
- data/spec/parser/ruby/token_resolver_spec.rb +0 -165
- data/spec/parser/source_parser_spec.rb +0 -727
- data/spec/parser/tag_parsing_spec.rb +0 -17
- data/spec/rake/yardoc_task_spec.rb +0 -118
- data/spec/registry_spec.rb +0 -463
- data/spec/registry_store_spec.rb +0 -327
- data/spec/rubygems/doc_manager_spec.rb +0 -112
- data/spec/serializers/data/serialized_yardoc/checksums +0 -1
- data/spec/serializers/data/serialized_yardoc/objects/Foo/bar_i.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/Foo/baz_i.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/Foo.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/objects/root.dat +0 -0
- data/spec/serializers/data/serialized_yardoc/proxy_types +0 -2
- data/spec/serializers/file_system_serializer_spec.rb +0 -145
- data/spec/serializers/spec_helper.rb +0 -2
- data/spec/serializers/yardoc_serializer_spec.rb +0 -78
- data/spec/server/adapter_spec.rb +0 -39
- data/spec/server/commands/base_spec.rb +0 -91
- data/spec/server/commands/library_command_spec.rb +0 -39
- data/spec/server/doc_server_helper_spec.rb +0 -72
- data/spec/server/doc_server_serializer_spec.rb +0 -60
- data/spec/server/rack_adapter_spec.rb +0 -21
- data/spec/server/router_spec.rb +0 -123
- data/spec/server/spec_helper.rb +0 -22
- data/spec/server/static_caching_spec.rb +0 -47
- data/spec/server/webrick_servlet_spec.rb +0 -20
- data/spec/server_spec.rb +0 -19
- data/spec/spec_helper.rb +0 -212
- data/spec/tags/default_factory_spec.rb +0 -168
- data/spec/tags/default_tag_spec.rb +0 -11
- data/spec/tags/directives_spec.rb +0 -463
- data/spec/tags/library_spec.rb +0 -48
- data/spec/tags/overload_tag_spec.rb +0 -53
- data/spec/tags/ref_tag_list_spec.rb +0 -53
- data/spec/tags/types_explainer_spec.rb +0 -203
- data/spec/templates/class_spec.rb +0 -45
- data/spec/templates/constant_spec.rb +0 -41
- data/spec/templates/engine_spec.rb +0 -131
- data/spec/templates/examples/class001.html +0 -308
- data/spec/templates/examples/class001.txt +0 -36
- data/spec/templates/examples/class002.html +0 -39
- data/spec/templates/examples/constant001.txt +0 -25
- data/spec/templates/examples/constant002.txt +0 -7
- data/spec/templates/examples/constant003.txt +0 -11
- data/spec/templates/examples/method001.html +0 -137
- data/spec/templates/examples/method001.txt +0 -35
- data/spec/templates/examples/method002.html +0 -91
- data/spec/templates/examples/method002.txt +0 -20
- data/spec/templates/examples/method003.html +0 -165
- data/spec/templates/examples/method003.txt +0 -45
- data/spec/templates/examples/method004.html +0 -48
- data/spec/templates/examples/method004.txt +0 -10
- data/spec/templates/examples/method005.html +0 -105
- data/spec/templates/examples/method005.txt +0 -33
- data/spec/templates/examples/method006.html +0 -108
- data/spec/templates/examples/method006.txt +0 -20
- data/spec/templates/examples/module001.dot +0 -33
- data/spec/templates/examples/module001.html +0 -833
- data/spec/templates/examples/module001.txt +0 -33
- data/spec/templates/examples/module002.html +0 -341
- data/spec/templates/examples/module003.html +0 -202
- data/spec/templates/examples/module004.html +0 -394
- data/spec/templates/examples/module005.html +0 -82
- data/spec/templates/examples/tag001.txt +0 -82
- data/spec/templates/helpers/base_helper_spec.rb +0 -171
- data/spec/templates/helpers/html_helper_spec.rb +0 -687
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +0 -65
- data/spec/templates/helpers/markup/rdoc_markup_spec.rb +0 -84
- data/spec/templates/helpers/markup_helper_spec.rb +0 -136
- data/spec/templates/helpers/method_helper_spec.rb +0 -107
- data/spec/templates/helpers/module_helper_spec.rb +0 -35
- data/spec/templates/helpers/shared_signature_examples.rb +0 -126
- data/spec/templates/helpers/text_helper_spec.rb +0 -65
- data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +0 -60
- data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +0 -46
- data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +0 -59
- data/spec/templates/markup_processor_integrations/rdoc_spec.rb +0 -39
- data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +0 -59
- data/spec/templates/markup_processor_integrations/redcloth_spec.rb +0 -48
- data/spec/templates/method_spec.rb +0 -118
- data/spec/templates/module_spec.rb +0 -203
- data/spec/templates/onefile_spec.rb +0 -66
- data/spec/templates/section_spec.rb +0 -144
- data/spec/templates/spec_helper.rb +0 -76
- data/spec/templates/tag_spec.rb +0 -52
- data/spec/templates/template_spec.rb +0 -410
- data/spec/verifier_spec.rb +0 -106
@@ -1,508 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe YARD::Parser::Ruby::RubyParser do
|
4
|
-
def stmt(stmt)
|
5
|
-
YARD::Parser::Ruby::RubyParser.new(stmt, nil).parse.root.first
|
6
|
-
end
|
7
|
-
|
8
|
-
def stmts(stmts)
|
9
|
-
YARD::Parser::Ruby::RubyParser.new(stmts, nil).parse.root
|
10
|
-
end
|
11
|
-
|
12
|
-
def tokenize(stmt)
|
13
|
-
YARD::Parser::Ruby::RubyParser.new(stmt, nil).parse.tokens
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "#parse" do
|
17
|
-
it "gets comment line numbers" do
|
18
|
-
s = stmt <<-eof
|
19
|
-
# comment
|
20
|
-
# comment
|
21
|
-
# comment
|
22
|
-
def method; end
|
23
|
-
eof
|
24
|
-
expect(s.comments).to eq "comment\ncomment\ncomment"
|
25
|
-
expect(s.comments_range).to eq(1..3)
|
26
|
-
|
27
|
-
s = stmt <<-eof
|
28
|
-
|
29
|
-
# comment
|
30
|
-
# comment
|
31
|
-
def method; end
|
32
|
-
eof
|
33
|
-
expect(s.comments).to eq "comment\ncomment"
|
34
|
-
expect(s.comments_range).to eq(2..3)
|
35
|
-
|
36
|
-
s = stmt <<-eof
|
37
|
-
# comment
|
38
|
-
# comment
|
39
|
-
|
40
|
-
def method; end
|
41
|
-
eof
|
42
|
-
expect(s.comments).to eq "comment\ncomment"
|
43
|
-
expect(s.comments_range).to eq(1..2)
|
44
|
-
|
45
|
-
s = stmt <<-eof
|
46
|
-
# comment
|
47
|
-
def method; end
|
48
|
-
eof
|
49
|
-
expect(s.comments).to eq "comment"
|
50
|
-
expect(s.comments_range).to eq(1..1)
|
51
|
-
|
52
|
-
s = stmt <<-eof
|
53
|
-
def method; end # comment
|
54
|
-
eof
|
55
|
-
expect(s.comments).to eq "comment"
|
56
|
-
expect(s.comments_range).to eq(1..1)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "only looks up to two lines back for comments" do
|
60
|
-
s = stmts <<-eof
|
61
|
-
# comments
|
62
|
-
|
63
|
-
# comments
|
64
|
-
|
65
|
-
def method; end
|
66
|
-
eof
|
67
|
-
expect(s[1].comments).to eq "comments"
|
68
|
-
|
69
|
-
s = stmts <<-eof
|
70
|
-
# comments
|
71
|
-
|
72
|
-
|
73
|
-
def method; end
|
74
|
-
eof
|
75
|
-
expect(s[1].comments).to eq nil
|
76
|
-
|
77
|
-
ss = stmts <<-eof
|
78
|
-
# comments
|
79
|
-
|
80
|
-
|
81
|
-
def method; end
|
82
|
-
|
83
|
-
# hello
|
84
|
-
def method2; end
|
85
|
-
eof
|
86
|
-
expect(ss[1].comments).to eq nil
|
87
|
-
expect(ss[2].comments).to eq 'hello'
|
88
|
-
end
|
89
|
-
|
90
|
-
it "handles block comment followed by line comment" do
|
91
|
-
ss = stmts <<-eof
|
92
|
-
# comments1
|
93
|
-
|
94
|
-
=begin
|
95
|
-
comments2
|
96
|
-
=end
|
97
|
-
# comments3
|
98
|
-
def hello; end
|
99
|
-
eof
|
100
|
-
expect(ss.last.comments).to eq "comments3"
|
101
|
-
end
|
102
|
-
|
103
|
-
it "handles block comment followed by block comment" do
|
104
|
-
ss = stmts <<-eof
|
105
|
-
=begin
|
106
|
-
comments1
|
107
|
-
=end
|
108
|
-
=begin
|
109
|
-
comments2
|
110
|
-
=end
|
111
|
-
def hello; end
|
112
|
-
eof
|
113
|
-
expect(ss.last.comments.strip).to eq "comments2"
|
114
|
-
end
|
115
|
-
|
116
|
-
it "handles 1.9 lambda syntax with args" do
|
117
|
-
src = "->(a,b,c=1,*args,&block) { hello_world }"
|
118
|
-
expect(stmt(src).source).to eq src
|
119
|
-
end
|
120
|
-
|
121
|
-
it "handles 1.9 lambda syntax" do
|
122
|
-
src = "-> { hello_world }"
|
123
|
-
expect(stmt(src).source).to eq src
|
124
|
-
end
|
125
|
-
|
126
|
-
it "handles standard lambda syntax" do
|
127
|
-
src = "lambda { hello_world }"
|
128
|
-
expect(stmt(src).source).to eq src
|
129
|
-
end
|
130
|
-
|
131
|
-
it "throws a ParserSyntaxError on invalid code" do
|
132
|
-
expect { stmt("Foo, bar.") }.to raise_error(YARD::Parser::ParserSyntaxError)
|
133
|
-
end
|
134
|
-
|
135
|
-
it "handles bare hashes as method parameters" do
|
136
|
-
src = "command :a => 1, :b => 2, :c => 3"
|
137
|
-
expect(stmt(src).jump(:command)[1].source).to eq ":a => 1, :b => 2, :c => 3"
|
138
|
-
|
139
|
-
src = "command a: 1, b: 2, c: 3"
|
140
|
-
expect(stmt(src).jump(:command)[1].source).to eq "a: 1, b: 2, c: 3"
|
141
|
-
end
|
142
|
-
|
143
|
-
it "handles source for hash syntax" do
|
144
|
-
src = "{ :a => 1, :b => 2, :c => 3 }"
|
145
|
-
expect(stmt(src).jump(:hash).source).to eq "{ :a => 1, :b => 2, :c => 3 }"
|
146
|
-
end
|
147
|
-
|
148
|
-
it "handles an empty hash" do
|
149
|
-
expect(stmt("{}").jump(:hash).source).to eq "{}"
|
150
|
-
end
|
151
|
-
|
152
|
-
it "new hash label syntax should show label without colon" do
|
153
|
-
ast = stmt("{ a: 1 }").jump(:label)
|
154
|
-
expect(ast[0]).to eq "a"
|
155
|
-
expect(ast.source).to eq "a:"
|
156
|
-
end
|
157
|
-
|
158
|
-
it "handles begin/rescue blocks" do
|
159
|
-
ast = stmt("begin; X; rescue => e; Y end").jump(:rescue)
|
160
|
-
expect(ast.source).to eq "rescue => e; Y end"
|
161
|
-
|
162
|
-
ast = stmt("begin; X; rescue A => e; Y end").jump(:rescue)
|
163
|
-
expect(ast.source).to eq "rescue A => e; Y end"
|
164
|
-
|
165
|
-
ast = stmt("begin; X; rescue A, B => e; Y end").jump(:rescue)
|
166
|
-
expect(ast.source).to eq "rescue A, B => e; Y end"
|
167
|
-
end
|
168
|
-
|
169
|
-
it "handles method rescue blocks" do
|
170
|
-
ast = stmt("def x; A; rescue Y; B end")
|
171
|
-
expect(ast.source).to eq "def x; A; rescue Y; B end"
|
172
|
-
expect(ast.jump(:rescue).source).to eq "rescue Y; B end"
|
173
|
-
end
|
174
|
-
|
175
|
-
it "handles defs with keywords as method name" do
|
176
|
-
ast = stmt("# docstring\nclass A;\ndef class; end\nend")
|
177
|
-
expect(ast.jump(:class).docstring).to eq "docstring"
|
178
|
-
expect(ast.jump(:class).line_range).to eq(2..4)
|
179
|
-
end
|
180
|
-
|
181
|
-
it "handles defs with unnamed argument with default values" do
|
182
|
-
ast = stmt('def hello(one, two = 2, three = 3) end').jump(:params)
|
183
|
-
expect(ast.source).to eq 'one, two = 2, three = 3'
|
184
|
-
end
|
185
|
-
|
186
|
-
it "handles defs with splats" do
|
187
|
-
ast = stmt('def hello(one, *two) end').jump(:params)
|
188
|
-
expect(ast.source).to eq 'one, *two'
|
189
|
-
end
|
190
|
-
|
191
|
-
if YARD.ruby2?
|
192
|
-
it "handles defs with named arguments with default values" do
|
193
|
-
ast = stmt('def hello(one, two: 2, three: 3) end').jump(:params)
|
194
|
-
expect(ast.source).to eq 'one, two: 2, three: 3'
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
if NAMED_OPTIONAL_ARGUMENTS
|
199
|
-
it "handles defs with named arguments without default values" do
|
200
|
-
ast = stmt('def hello(one, two:, three:) end').jump(:params)
|
201
|
-
expect(ast.source).to eq 'one, two:, three:'
|
202
|
-
end
|
203
|
-
|
204
|
-
it "handles defs with double splats" do
|
205
|
-
ast = stmt('def hello(one, **two) end').jump(:params)
|
206
|
-
expect(ast.source).to eq 'one, **two'
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
it "ends source properly on array reference" do
|
211
|
-
ast = stmt("AS[0, 1 ] ")
|
212
|
-
expect(ast.source).to eq 'AS[0, 1 ]'
|
213
|
-
|
214
|
-
ast = stmt('def x(a = S[1]) end').jump(:params)
|
215
|
-
expect(ast.source).to eq 'a = S[1]'
|
216
|
-
end
|
217
|
-
|
218
|
-
it "ends source properly on if/unless mod" do
|
219
|
-
%w(if unless while).each do |mod|
|
220
|
-
expect(stmt("A=1 #{mod} true").source).to eq "A=1 #{mod} true"
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
it "shows proper source for assignment" do
|
225
|
-
expect(stmt("A=1").jump(:assign).source).to eq "A=1"
|
226
|
-
end
|
227
|
-
|
228
|
-
it "shows proper source for a top_const_ref" do
|
229
|
-
s = stmt("::\nFoo::Bar")
|
230
|
-
expect(s.jump(:top_const_ref).source).to eq "::\nFoo"
|
231
|
-
expect(s).to be_ref
|
232
|
-
expect(s.jump(:top_const_ref)).to be_ref
|
233
|
-
expect(s.source).to eq "::\nFoo::Bar"
|
234
|
-
expect(s.line_range.to_a).to eq [1, 2]
|
235
|
-
end
|
236
|
-
|
237
|
-
it "shows proper source for inline heredoc" do
|
238
|
-
src = "def foo\n foo(<<-XML, 1, 2)\n bar\n\n XML\nend"
|
239
|
-
s = stmt(src)
|
240
|
-
t = tokenize(src)
|
241
|
-
expect(s.source).to eq src
|
242
|
-
expect(t.map {|x| x[1] }.join).to eq src
|
243
|
-
end
|
244
|
-
|
245
|
-
it "shows proper source for regular heredoc" do
|
246
|
-
src = "def foo\n x = <<-XML\n Hello \#{name}!\n Bye!\n XML\nend"
|
247
|
-
s = stmt(src)
|
248
|
-
t = tokenize(src)
|
249
|
-
expect(s.source).to eq src
|
250
|
-
expect(t.map {|x| x[1] }.join).to eq src
|
251
|
-
end
|
252
|
-
|
253
|
-
it "shows proper source for heredoc with comment" do
|
254
|
-
src = "def foo\n x = <<-XML # HI!\n Hello \#{name}!\n Bye!\n XML\nend"
|
255
|
-
s = stmt(src)
|
256
|
-
t = tokenize(src)
|
257
|
-
expect(s.source).to eq src
|
258
|
-
expect(t.map {|x| x[1] }.join).to eq src
|
259
|
-
end
|
260
|
-
|
261
|
-
it "shows proper source for string" do
|
262
|
-
["'", '"'].each do |q|
|
263
|
-
src = "#{q}hello\n\nworld#{q}"
|
264
|
-
s = stmt(src)
|
265
|
-
expect(s.jump(:string_content).source).to eq "hello\n\nworld"
|
266
|
-
expect(s.source).to eq src
|
267
|
-
end
|
268
|
-
|
269
|
-
src = '("this is a string")'
|
270
|
-
expect(stmt(src).jump(:string_literal).source).to eq '"this is a string"'
|
271
|
-
end
|
272
|
-
|
273
|
-
%w(w W i I).each do |tok|
|
274
|
-
it "shows proper source for %#{tok}() array" do
|
275
|
-
src = "%#{tok}(\na b c\n d e f\n)"
|
276
|
-
expect(stmt(src).source).to eq src
|
277
|
-
end
|
278
|
-
|
279
|
-
it "shows proper source for %#{tok}{} array" do
|
280
|
-
src = "%#{tok}{\na b c\n d e f\n}"
|
281
|
-
expect(stmt(src).source).to eq src
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
{'i' => :qsymbols_literal, 'I' => :symbols_literal,
|
286
|
-
'w' => :qwords_literal, 'W' => :words_literal}.each do |id, sym|
|
287
|
-
it "parses %#{id}(...) literals" do
|
288
|
-
[
|
289
|
-
"TEST = %#{id}(A B C)",
|
290
|
-
"TEST = %#{id}( A B C )",
|
291
|
-
"TEST = %#{id}( \nA \nB \nC \n)",
|
292
|
-
"TEST = %#{id}(\n\nAD\n\nB\n\nC\n\n)",
|
293
|
-
"TEST = %#{id}(\n A\n B\n C\n )"
|
294
|
-
].each do |str|
|
295
|
-
node = stmt(str).jump(sym)
|
296
|
-
expect(node.source).to eq(str[/(\%#{id}\(.+\))/m, 1])
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
it "tokenizing %#{id}(...) returns correct tokens" do
|
301
|
-
toks = tokenize("TEST = %#{id}(A B C)").flatten
|
302
|
-
expect(toks.count(:tstring_content)).to eq(3)
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
it "properly tokenizes symbols" do
|
307
|
-
tokens = tokenize(<<-eof)
|
308
|
-
class X
|
309
|
-
Foo = :''
|
310
|
-
Fuu = :bar
|
311
|
-
Bar = :BAR
|
312
|
-
Baz = :"B+z"
|
313
|
-
Qux = :if
|
314
|
-
end
|
315
|
-
eof
|
316
|
-
symbols = tokens.select {|t| t[0] == :symbol }.map {|t| t[1] }
|
317
|
-
expect(symbols).to eq %w(:'' :bar :BAR :"B+z" :if)
|
318
|
-
end
|
319
|
-
|
320
|
-
it "parses %w() array in constant declaration" do
|
321
|
-
s = stmt(<<-eof)
|
322
|
-
class Foo
|
323
|
-
FOO = %w( foo bar )
|
324
|
-
end
|
325
|
-
eof
|
326
|
-
expect(s.jump(:qwords_literal).source).to eq '%w( foo bar )'
|
327
|
-
if RUBY_VERSION >= '1.9.3' # ripper fix: array node encapsulates qwords
|
328
|
-
expect(s.jump(:array).source).to eq '%w( foo bar )'
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
it "parses %w() array source in object[] parsed context" do
|
333
|
-
s = stmts(<<-eof)
|
334
|
-
{}[:key]
|
335
|
-
FOO = %w( foo bar )
|
336
|
-
eof
|
337
|
-
expect(s[1].jump(:array).source).to eq '%w( foo bar )'
|
338
|
-
end
|
339
|
-
|
340
|
-
it "parses %w() array source in object[]= parsed context" do
|
341
|
-
s = stmts(<<-eof)
|
342
|
-
{}[:key] = :value
|
343
|
-
FOO = %w( foo bar )
|
344
|
-
eof
|
345
|
-
expect(s[1].jump(:array).source).to eq '%w( foo bar )'
|
346
|
-
end
|
347
|
-
|
348
|
-
it "parses [] as array" do
|
349
|
-
s = stmt(<<-eof)
|
350
|
-
class Foo
|
351
|
-
FOO = ['foo', 'bar']
|
352
|
-
end
|
353
|
-
eof
|
354
|
-
expect(s.jump(:array).source).to eq "['foo', 'bar']"
|
355
|
-
end
|
356
|
-
|
357
|
-
it "shows source for unary minus" do
|
358
|
-
expect(stmt("X = - 1").jump(:unary).source).to eq '- 1'
|
359
|
-
end
|
360
|
-
|
361
|
-
it "shows source for unary exclamation" do
|
362
|
-
expect(stmt("X = !1").jump(:unary).source).to eq '!1'
|
363
|
-
end
|
364
|
-
|
365
|
-
it "has the correct line range for class/modules" do
|
366
|
-
s = stmt(<<-eof)
|
367
|
-
class Foo
|
368
|
-
def foo; end
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
# Ending comment
|
373
|
-
end
|
374
|
-
eof
|
375
|
-
expect(s.jump(:class).line_range).to eq(1..7)
|
376
|
-
end
|
377
|
-
|
378
|
-
it "has the correct line range for blocks" do
|
379
|
-
Registry.clear
|
380
|
-
ast = YARD.parse_string(<<-eof).enumerator
|
381
|
-
module A
|
382
|
-
some_method
|
383
|
-
end
|
384
|
-
eof
|
385
|
-
expect(ast.first.block.source.strip).to eq "some_method"
|
386
|
-
end
|
387
|
-
|
388
|
-
it "finds lone comments" do
|
389
|
-
Registry.clear
|
390
|
-
ast = YARD.parse_string(<<-eof).enumerator
|
391
|
-
class Foo
|
392
|
-
##
|
393
|
-
# comment here
|
394
|
-
|
395
|
-
|
396
|
-
def foo; end
|
397
|
-
|
398
|
-
# end comment
|
399
|
-
end
|
400
|
-
eof
|
401
|
-
comment = ast.first.last.jump(:comment)
|
402
|
-
expect(comment.type).to eq :comment
|
403
|
-
expect(comment.docstring_hash_flag).to be true
|
404
|
-
expect(comment.docstring.strip).to eq "comment here"
|
405
|
-
|
406
|
-
expect(ast.first.last.last.type).to eq :comment
|
407
|
-
expect(ast.first.last.last.docstring).to eq "end comment"
|
408
|
-
end
|
409
|
-
|
410
|
-
it "does not group comments if they don't begin the line" do
|
411
|
-
Registry.clear
|
412
|
-
YARD.parse_string(<<-eof).enumerator
|
413
|
-
class Foo
|
414
|
-
CONST1 = 1 # Comment here
|
415
|
-
CONST2 = 2 # Another comment here
|
416
|
-
end
|
417
|
-
eof
|
418
|
-
expect(Registry.at("Foo::CONST1").docstring).to eq "Comment here"
|
419
|
-
expect(Registry.at("Foo::CONST2").docstring).to eq "Another comment here"
|
420
|
-
end
|
421
|
-
|
422
|
-
it "handles comments in the middle of a multi-line statement" do
|
423
|
-
Registry.clear
|
424
|
-
YARD.parse_string <<-eof
|
425
|
-
foo # BREAK
|
426
|
-
.bar
|
427
|
-
|
428
|
-
# Documentation
|
429
|
-
class Baz; end
|
430
|
-
eof
|
431
|
-
expect(Registry.at('Baz')).not_to be_nil
|
432
|
-
expect(Registry.at('Baz').docstring).to eq 'Documentation'
|
433
|
-
end
|
434
|
-
|
435
|
-
%w(if unless).each do |type|
|
436
|
-
it "does not get confused by modifier '#{type}' statements" do
|
437
|
-
Registry.clear
|
438
|
-
YARD.parse_string(<<-eof).enumerator
|
439
|
-
module Foo
|
440
|
-
#{type} test?
|
441
|
-
# Docstring
|
442
|
-
class Bar
|
443
|
-
# Docstring2
|
444
|
-
def foo
|
445
|
-
x #{type} true
|
446
|
-
end
|
447
|
-
end
|
448
|
-
end
|
449
|
-
end
|
450
|
-
eof
|
451
|
-
|
452
|
-
expect(Registry.at("Foo::Bar").docstring).to eq "Docstring"
|
453
|
-
expect(Registry.at("Foo::Bar#foo").docstring).to eq "Docstring2"
|
454
|
-
end
|
455
|
-
|
456
|
-
it "supports #{type} statements at start of source" do
|
457
|
-
Registry.clear
|
458
|
-
YARD.parse_string <<-eof
|
459
|
-
#{type} condition?
|
460
|
-
class Foo; def bar; #{type} true; end end end
|
461
|
-
end
|
462
|
-
eof
|
463
|
-
|
464
|
-
expect(log.io.string).to eq ""
|
465
|
-
expect(Registry.at('Foo#bar')).not_to eq nil
|
466
|
-
end
|
467
|
-
|
468
|
-
it "can handle complex non-modifier '#{type}' statements" do
|
469
|
-
Registry.clear
|
470
|
-
YARD.parse_string <<-eof
|
471
|
-
class Foo
|
472
|
-
def initialize(data, options = Hash.new)
|
473
|
-
#{type} true; raise "error" end
|
474
|
-
@x = ( #{type} 1; true end ) # This line should not blow up
|
475
|
-
end
|
476
|
-
end
|
477
|
-
eof
|
478
|
-
|
479
|
-
expect(log.io.string).to eq ""
|
480
|
-
expect(Registry.at('Foo#initialize')).not_to eq nil
|
481
|
-
end
|
482
|
-
|
483
|
-
it "does not add comment blocks to #{type}_mod nodes" do
|
484
|
-
Registry.clear
|
485
|
-
YARD.parse_string(<<-eof).enumerator
|
486
|
-
class Foo
|
487
|
-
# Docstring
|
488
|
-
def bar; end if true
|
489
|
-
end
|
490
|
-
eof
|
491
|
-
|
492
|
-
expect(Registry.at("Foo#bar").docstring).to eq "Docstring"
|
493
|
-
end
|
494
|
-
end
|
495
|
-
|
496
|
-
it "removes frozen string line from initial file comments" do
|
497
|
-
YARD.parse_string "# frozen_string_literal: true\n# this is a comment\nclass Foo; end"
|
498
|
-
YARD.parse_string "# Frozen-string-literal: true\n# this is a comment\nclass Bar; end"
|
499
|
-
|
500
|
-
expect(Registry.at(:Foo).docstring).to eq "this is a comment"
|
501
|
-
expect(Registry.at(:Bar).docstring).to eq "this is a comment"
|
502
|
-
end
|
503
|
-
|
504
|
-
it "handles compile errors" do
|
505
|
-
expect { stmt(":~$ Do not clobber") }.to raise_error(Parser::ParserSyntaxError)
|
506
|
-
end
|
507
|
-
end
|
508
|
-
end if HAVE_RIPPER
|
@@ -1,165 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe YARD::Parser::Ruby::TokenResolver do
|
4
|
-
before(:all) do
|
5
|
-
YARD.parse_string <<-eof
|
6
|
-
module A
|
7
|
-
def nomatch; end
|
8
|
-
|
9
|
-
module B
|
10
|
-
class C
|
11
|
-
def initialize; end
|
12
|
-
|
13
|
-
# @return [A::B::C]
|
14
|
-
def self.foo; end
|
15
|
-
|
16
|
-
# @return [self]
|
17
|
-
def self.foo2; end
|
18
|
-
|
19
|
-
def bar; end
|
20
|
-
|
21
|
-
# @return [nil, D<String>]
|
22
|
-
def baz; end
|
23
|
-
|
24
|
-
# @return [nil]
|
25
|
-
# @return [D<String>]
|
26
|
-
def baz2; end
|
27
|
-
|
28
|
-
# @overload qux(a)
|
29
|
-
# @return [nil]
|
30
|
-
# @overload qux(b)
|
31
|
-
# @return [D<String>]
|
32
|
-
def qux; end
|
33
|
-
end
|
34
|
-
|
35
|
-
class SubC < C
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
module D
|
41
|
-
def baz; end
|
42
|
-
end
|
43
|
-
|
44
|
-
class Q
|
45
|
-
def method; end
|
46
|
-
|
47
|
-
# @return [Q]
|
48
|
-
def self.q; end
|
49
|
-
end
|
50
|
-
eof
|
51
|
-
end
|
52
|
-
|
53
|
-
def tokens_match
|
54
|
-
expect(@resolved.map {|t| t.first.last }.join).to eq @src
|
55
|
-
end
|
56
|
-
|
57
|
-
def objs_match(*objects)
|
58
|
-
other_objs = @resolved.reject {|_, o| !o }.map {|_, o| o.path }
|
59
|
-
expect(other_objs).to eq objects.flatten
|
60
|
-
tokens_match
|
61
|
-
end
|
62
|
-
|
63
|
-
def tokenize(src, object = nil)
|
64
|
-
@src = src
|
65
|
-
@resolver = YARD::Parser::Ruby::TokenResolver.new(src, object)
|
66
|
-
@resolved = @resolver.map {|t, o| [t[0, 2], o] }
|
67
|
-
end
|
68
|
-
|
69
|
-
it "returns regular tokens" do
|
70
|
-
str = "def foo; Z::X::Y end"
|
71
|
-
tokenize(str)
|
72
|
-
tokens_match
|
73
|
-
end
|
74
|
-
|
75
|
-
it "resolves objects in compound constant paths" do
|
76
|
-
tokenize "A::B::C"
|
77
|
-
objs_match "A", "A::B", "A::B::C"
|
78
|
-
end
|
79
|
-
|
80
|
-
it "ignores full constant path if it breaks at beginning" do
|
81
|
-
tokenize "E::A::B::C"
|
82
|
-
objs_match []
|
83
|
-
end
|
84
|
-
|
85
|
-
it "ignores rest of constant path if sub-objects don't match" do
|
86
|
-
tokenize "D::A::B::C"
|
87
|
-
objs_match "D"
|
88
|
-
end
|
89
|
-
|
90
|
-
it "resets parsing at non-op tokens" do
|
91
|
-
tokenize "A::B::C < Q"
|
92
|
-
objs_match "A", "A::B", "A::B::C", "Q"
|
93
|
-
end
|
94
|
-
|
95
|
-
it "does not restart constant path" do
|
96
|
-
tokenize "A::B::D::A"
|
97
|
-
objs_match "A", "A::B"
|
98
|
-
end
|
99
|
-
|
100
|
-
it "resolves objects from base namespace" do
|
101
|
-
tokenize "A::B::C C", Registry.at("A::B")
|
102
|
-
objs_match "A", "A::B", "A::B::C", "A::B::C"
|
103
|
-
end
|
104
|
-
|
105
|
-
it "resolves methods" do
|
106
|
-
tokenize "A::B::C.foo"
|
107
|
-
objs_match "A", "A::B", "A::B::C", "A::B::C.foo"
|
108
|
-
end
|
109
|
-
|
110
|
-
it "supports 'new' constructor method" do
|
111
|
-
tokenize "A::B::C.new"
|
112
|
-
objs_match "A", "A::B", "A::B::C", "A::B::C#initialize"
|
113
|
-
end
|
114
|
-
|
115
|
-
it "skips constructor method if not found but continues resolving" do
|
116
|
-
tokenize "Q.new.method"
|
117
|
-
objs_match "Q", "Q#method"
|
118
|
-
end
|
119
|
-
|
120
|
-
it "resolves methods in inheritance tree" do
|
121
|
-
tokenize "A::B::SubC.new"
|
122
|
-
objs_match "A", "A::B", "A::B::SubC", "A::B::C#initialize"
|
123
|
-
end
|
124
|
-
|
125
|
-
it "parses compound method call chains based on return type" do
|
126
|
-
tokenize "A::B::C.foo.baz"
|
127
|
-
objs_match "A", "A::B", "A::B::C", "A::B::C.foo", "A::B::C#baz"
|
128
|
-
end
|
129
|
-
|
130
|
-
it "stops resolving if return types not found" do
|
131
|
-
tokenize "A::B::C.foo.bar.baz.baz"
|
132
|
-
objs_match "A", "A::B", "A::B::C", "A::B::C.foo", "A::B::C#bar"
|
133
|
-
end
|
134
|
-
|
135
|
-
it "handles multiple return types (returns first valid type match)" do
|
136
|
-
tokenize "A::B::C.foo.baz.baz"
|
137
|
-
objs_match "A", "A::B", "A::B::C", "A::B::C.foo", "A::B::C#baz", "D#baz"
|
138
|
-
end
|
139
|
-
|
140
|
-
it "doesn't perform lexical matching on methods" do
|
141
|
-
tokenize "A::B::C.nomatch"
|
142
|
-
objs_match "A", "A::B", "A::B::C"
|
143
|
-
end
|
144
|
-
|
145
|
-
it "handles multiple return tags (returns first valid type match)" do
|
146
|
-
tokenize "A::B::C.foo.baz2.baz"
|
147
|
-
objs_match "A", "A::B", "A::B::C", "A::B::C.foo", "A::B::C#baz2", "D#baz"
|
148
|
-
end
|
149
|
-
|
150
|
-
it "handles self as return type" do
|
151
|
-
tokenize "A::B::C.foo2.baz"
|
152
|
-
objs_match "A", "A::B", "A::B::C", "A::B::C.foo2", "A::B::C#baz"
|
153
|
-
end
|
154
|
-
|
155
|
-
it "handles multiple return tags inside overload tags" do
|
156
|
-
tokenize "A::B::C.foo.qux.baz"
|
157
|
-
objs_match "A", "A::B", "A::B::C", "A::B::C.foo", "A::B::C#qux", "D#baz"
|
158
|
-
end
|
159
|
-
|
160
|
-
it "resolves method calls with arguments" do
|
161
|
-
tokenize "Q.q(A::B, A::B::C.foo().bar).q.q"
|
162
|
-
objs_match "Q", "Q.q", "A", "A::B", "A", "A::B", "A::B::C",
|
163
|
-
"A::B::C.foo", "A::B::C#bar", "Q.q", "Q.q"
|
164
|
-
end
|
165
|
-
end if HAVE_RIPPER
|