yard 0.8.7.6 → 0.9.0
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/CHANGELOG.md +20 -1
- data/LICENSE +2 -2
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/bin/yard +0 -0
- data/bin/yardoc +0 -0
- data/bin/yri +0 -0
- data/docs/GettingStarted.md +88 -6
- data/docs/images/handlers-class-diagram.png +0 -0
- data/docs/images/overview-class-diagram.png +0 -0
- data/docs/images/parser-class-diagram.png +0 -0
- data/docs/templates/default/fulldoc/html/full_list_tag.erb +6 -4
- data/lib/yard/autoload.rb +3 -0
- data/lib/yard/cli/yardoc.rb +1 -1
- data/lib/yard/code_objects/base.rb +4 -1
- data/lib/yard/code_objects/extra_file_object.rb +3 -1
- data/lib/yard/code_objects/proxy.rb +2 -2
- data/lib/yard/docstring.rb +11 -6
- data/lib/yard/handlers/base.rb +1 -2
- data/lib/yard/handlers/c/base.rb +19 -0
- data/lib/yard/handlers/c/handler_methods.rb +42 -8
- data/lib/yard/handlers/c/init_handler.rb +1 -1
- data/lib/yard/handlers/c/method_handler.rb +3 -3
- data/lib/yard/handlers/ruby/decorator_handler_methods.rb +132 -0
- data/lib/yard/handlers/ruby/legacy/private_class_method_handler.rb +1 -1
- data/lib/yard/handlers/ruby/private_class_method_handler.rb +6 -39
- data/lib/yard/handlers/ruby/private_constant_handler.rb +36 -30
- data/lib/yard/handlers/ruby/public_class_method_handler.rb +13 -0
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +1 -0
- data/lib/yard/handlers/ruby/visibility_handler.rb +5 -8
- data/lib/yard/logging.rb +1 -0
- data/lib/yard/parser/ruby/ruby_parser.rb +2 -2
- data/lib/yard/parser/source_parser.rb +6 -6
- data/lib/yard/rake/yardoc_task.rb +2 -2
- data/lib/yard/serializers/file_system_serializer.rb +33 -1
- data/lib/yard/server/commands/display_file_command.rb +8 -3
- data/lib/yard/server/commands/display_object_command.rb +7 -3
- data/lib/yard/server/doc_server_helper.rb +2 -8
- data/lib/yard/server/doc_server_serializer.rb +2 -4
- data/lib/yard/server/router.rb +1 -1
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +57 -8
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -10
- data/lib/yard/server/templates/default/layout/html/script_setup.erb +1 -2
- data/lib/yard/server/templates/default/method_details/html/permalink.erb +3 -3
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +4 -4
- data/lib/yard/tags/directives.rb +1 -0
- data/lib/yard/tags/library.rb +9 -7
- data/lib/yard/tags/overload_tag.rb +4 -1
- data/lib/yard/templates/helpers/html_helper.rb +4 -3
- data/lib/yard/templates/template_options.rb +3 -0
- data/lib/yard/version.rb +1 -1
- data/spec/cli/command_parser_spec.rb +14 -14
- data/spec/cli/command_spec.rb +11 -11
- data/spec/cli/config_spec.rb +32 -32
- data/spec/cli/diff_spec.rb +86 -90
- data/spec/cli/display_spec.rb +6 -6
- data/spec/cli/gems_spec.rb +28 -28
- data/spec/cli/graph_spec.rb +8 -8
- data/spec/cli/help_spec.rb +8 -8
- data/spec/cli/i18n_spec.rb +33 -37
- data/spec/cli/list_spec.rb +2 -2
- data/spec/cli/markup_types_spec.rb +3 -3
- data/spec/cli/server_spec.rb +74 -88
- data/spec/cli/stats_spec.rb +14 -14
- data/spec/cli/yardoc_spec.rb +316 -321
- data/spec/cli/yri_spec.rb +45 -45
- data/spec/code_objects/base_spec.rb +174 -173
- data/spec/code_objects/class_object_spec.rb +65 -65
- data/spec/code_objects/code_object_list_spec.rb +13 -11
- data/spec/code_objects/constants_spec.rb +68 -58
- data/spec/code_objects/extra_file_object_spec.rb +71 -59
- data/spec/code_objects/macro_object_spec.rb +64 -64
- data/spec/code_objects/method_object_spec.rb +80 -72
- data/spec/code_objects/module_object_spec.rb +47 -47
- data/spec/code_objects/namespace_object_spec.rb +51 -51
- data/spec/code_objects/proxy_spec.rb +54 -54
- data/spec/config_spec.rb +104 -104
- data/spec/core_ext/array_spec.rb +5 -5
- data/spec/core_ext/file_spec.rb +33 -33
- data/spec/core_ext/hash_spec.rb +5 -5
- data/spec/core_ext/insertion_spec.rb +18 -18
- data/spec/core_ext/module_spec.rb +6 -6
- data/spec/core_ext/string_spec.rb +17 -17
- data/spec/core_ext/symbol_hash_spec.rb +42 -39
- data/spec/docstring_parser_spec.rb +65 -65
- data/spec/docstring_spec.rb +137 -130
- data/spec/handlers/alias_handler_spec.rb +39 -39
- data/spec/handlers/attribute_handler_spec.rb +35 -35
- data/spec/handlers/base_spec.rb +60 -51
- data/spec/handlers/c/alias_handler_spec.rb +6 -6
- data/spec/handlers/c/attribute_handler_spec.rb +12 -12
- data/spec/handlers/c/class_handler_spec.rb +35 -22
- data/spec/handlers/c/constant_handler_spec.rb +24 -22
- data/spec/handlers/c/init_handler_spec.rb +10 -10
- data/spec/handlers/c/method_handler_spec.rb +150 -65
- data/spec/handlers/c/mixin_handler_spec.rb +5 -5
- data/spec/handlers/c/module_handler_spec.rb +27 -15
- data/spec/handlers/c/override_comment_handler_spec.rb +14 -14
- data/spec/handlers/c/path_handler_spec.rb +8 -8
- data/spec/handlers/c/spec_helper.rb +10 -0
- data/spec/handlers/c/struct_handler_spec.rb +3 -3
- data/spec/handlers/class_condition_handler_spec.rb +18 -18
- data/spec/handlers/class_handler_spec.rb +97 -97
- data/spec/handlers/class_method_handler_shared_examples.rb +132 -0
- data/spec/handlers/class_variable_handler_spec.rb +3 -3
- data/spec/handlers/constant_handler_spec.rb +32 -29
- data/spec/handlers/decorator_handler_methods_spec.rb +405 -0
- data/spec/handlers/dsl_handler_spec.rb +108 -109
- data/spec/handlers/examples/constant_handler_001.rb.txt +4 -1
- data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
- data/spec/handlers/exception_handler_spec.rb +23 -23
- data/spec/handlers/extend_handler_spec.rb +9 -9
- data/spec/handlers/legacy_base_spec.rb +60 -60
- data/spec/handlers/method_condition_handler_spec.rb +5 -5
- data/spec/handlers/method_handler_spec.rb +92 -92
- data/spec/handlers/mixin_handler_spec.rb +25 -25
- data/spec/handlers/module_function_handler_spec.rb +24 -24
- data/spec/handlers/module_handler_spec.rb +15 -15
- data/spec/handlers/private_class_method_handler_spec.rb +4 -48
- data/spec/handlers/private_constant_handler_spec.rb +8 -8
- data/spec/handlers/processor_spec.rb +12 -12
- data/spec/handlers/public_class_method_handler_spec.rb +10 -0
- data/spec/handlers/ruby/base_spec.rb +16 -16
- data/spec/handlers/ruby/legacy/base_spec.rb +20 -18
- data/spec/handlers/spec_helper.rb +1 -1
- data/spec/handlers/visibility_handler_spec.rb +25 -21
- data/spec/handlers/yield_handler_spec.rb +28 -28
- data/spec/i18n/locale_spec.rb +16 -16
- data/spec/i18n/message_spec.rb +8 -8
- data/spec/i18n/messages_spec.rb +14 -14
- data/spec/i18n/pot_generator_spec.rb +32 -32
- data/spec/i18n/text_spec.rb +22 -22
- data/spec/logging_spec.rb +12 -12
- data/spec/options_spec.rb +56 -56
- data/spec/parser/base_spec.rb +9 -9
- data/spec/parser/c_parser_spec.rb +50 -50
- data/spec/parser/ruby/ast_node_spec.rb +7 -7
- data/spec/parser/ruby/legacy/statement_list_spec.rb +106 -106
- data/spec/parser/ruby/legacy/token_list_spec.rb +27 -27
- data/spec/parser/ruby/ruby_parser_spec.rb +123 -113
- data/spec/parser/source_parser_spec.rb +224 -224
- data/spec/parser/tag_parsing_spec.rb +6 -7
- data/spec/rake/yardoc_task_spec.rb +38 -48
- data/spec/registry_spec.rb +143 -143
- data/spec/registry_store_spec.rb +165 -165
- data/spec/rubygems/doc_manager_spec.rb +38 -38
- data/spec/serializers/file_system_serializer_spec.rb +53 -33
- data/spec/serializers/yardoc_serializer_spec.rb +15 -15
- data/spec/server/adapter_spec.rb +15 -15
- data/spec/server/commands/base_spec.rb +29 -29
- data/spec/server/commands/library_command_spec.rb +12 -12
- data/spec/server/commands/static_file_command_spec.rb +28 -28
- data/spec/server/doc_server_helper_spec.rb +8 -8
- data/spec/server/doc_server_serializer_spec.rb +23 -18
- data/spec/server/rack_adapter_spec.rb +6 -6
- data/spec/server/router_spec.rb +39 -39
- data/spec/server/static_caching_spec.rb +16 -16
- data/spec/server/webrick_servlet_spec.rb +6 -7
- data/spec/server_spec.rb +3 -3
- data/spec/spec_helper.rb +11 -2
- data/spec/tags/default_factory_spec.rb +64 -64
- data/spec/tags/default_tag_spec.rb +5 -5
- data/spec/tags/directives_spec.rb +121 -121
- data/spec/tags/library_spec.rb +14 -14
- data/spec/tags/overload_tag_spec.rb +24 -24
- data/spec/tags/ref_tag_list_spec.rb +12 -12
- data/spec/templates/class_spec.rb +3 -3
- data/spec/templates/constant_spec.rb +4 -4
- data/spec/templates/engine_spec.rb +47 -48
- data/spec/templates/examples/class001.html +129 -101
- data/spec/templates/examples/class002.html +31 -27
- data/spec/templates/examples/method001.html +54 -47
- data/spec/templates/examples/method002.html +33 -28
- data/spec/templates/examples/method003.html +70 -64
- data/spec/templates/examples/method004.html +13 -9
- data/spec/templates/examples/method005.html +38 -32
- data/spec/templates/examples/module001.html +343 -339
- data/spec/templates/examples/module002.html +147 -124
- data/spec/templates/examples/module003.html +94 -81
- data/spec/templates/examples/module004.html +40 -33
- data/spec/templates/helpers/base_helper_spec.rb +91 -95
- data/spec/templates/helpers/html_helper_spec.rb +276 -279
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +16 -15
- data/spec/templates/helpers/markup/rdoc_markup_spec.rb +27 -34
- data/spec/templates/helpers/markup_helper_spec.rb +57 -57
- data/spec/templates/helpers/method_helper_spec.rb +20 -20
- data/spec/templates/helpers/shared_signature_examples.rb +33 -31
- data/spec/templates/helpers/text_helper_spec.rb +6 -6
- data/spec/templates/method_spec.rb +7 -7
- data/spec/templates/module_spec.rb +7 -7
- data/spec/templates/onefile_spec.rb +7 -7
- data/spec/templates/section_spec.rb +66 -69
- data/spec/templates/spec_helper.rb +1 -1
- data/spec/templates/tag_spec.rb +5 -5
- data/spec/templates/template_spec.rb +158 -158
- data/spec/verifier_spec.rb +52 -52
- data/templates/default/fulldoc/html/css/full_list.css +32 -31
- data/templates/default/fulldoc/html/css/style.css +212 -77
- data/templates/default/fulldoc/html/frames.erb +6 -15
- data/templates/default/fulldoc/html/full_list.erb +14 -21
- data/templates/default/fulldoc/html/full_list_class.erb +1 -1
- data/templates/default/fulldoc/html/full_list_file.erb +6 -4
- data/templates/default/fulldoc/html/full_list_method.erb +8 -6
- data/templates/default/fulldoc/html/js/app.js +100 -76
- data/templates/default/fulldoc/html/js/full_list.js +170 -135
- data/templates/default/fulldoc/html/setup.rb +50 -7
- data/templates/default/layout/html/breadcrumb.erb +0 -2
- data/templates/default/layout/html/headers.erb +2 -1
- data/templates/default/layout/html/layout.erb +16 -10
- data/templates/default/layout/html/script_setup.erb +1 -2
- data/templates/default/layout/html/search.erb +7 -2
- data/templates/default/layout/html/setup.rb +16 -0
- data/templates/default/method/html/header.erb +7 -6
- data/templates/default/module/html/attribute_summary.erb +1 -1
- data/templates/default/module/html/box_info.erb +24 -18
- data/templates/default/module/html/constant_summary.erb +9 -11
- data/templates/default/module/html/item_summary.erb +1 -1
- data/templates/default/module/html/method_summary.erb +1 -1
- data/templates/guide/fulldoc/html/setup.rb +1 -1
- data/yard.gemspec +1 -2
- metadata +10 -7
- data/spec/handlers/examples/private_class_method_handler_001.rb.txt +0 -9
- data/spec/handlers/examples/private_class_method_handler_002.rb.txt +0 -18
- data/spec/handlers/examples/private_class_method_handler_003.rb.txt +0 -11
@@ -13,16 +13,16 @@ describe YARD::Parser::Ruby::RubyParser do
|
|
13
13
|
YARD::Parser::Ruby::RubyParser.new(stmt, nil).parse.tokens
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
17
|
-
it "
|
16
|
+
describe "#parse" do
|
17
|
+
it "gets comment line numbers" do
|
18
18
|
s = stmt <<-eof
|
19
19
|
# comment
|
20
20
|
# comment
|
21
21
|
# comment
|
22
22
|
def method; end
|
23
23
|
eof
|
24
|
-
s.comments.
|
25
|
-
s.comments_range.
|
24
|
+
expect(s.comments).to eq "comment\ncomment\ncomment"
|
25
|
+
expect(s.comments_range).to eq (1..3)
|
26
26
|
|
27
27
|
s = stmt <<-eof
|
28
28
|
|
@@ -30,8 +30,8 @@ describe YARD::Parser::Ruby::RubyParser do
|
|
30
30
|
# comment
|
31
31
|
def method; end
|
32
32
|
eof
|
33
|
-
s.comments.
|
34
|
-
s.comments_range.
|
33
|
+
expect(s.comments).to eq "comment\ncomment"
|
34
|
+
expect(s.comments_range).to eq (2..3)
|
35
35
|
|
36
36
|
s = stmt <<-eof
|
37
37
|
# comment
|
@@ -39,24 +39,24 @@ describe YARD::Parser::Ruby::RubyParser do
|
|
39
39
|
|
40
40
|
def method; end
|
41
41
|
eof
|
42
|
-
s.comments.
|
43
|
-
s.comments_range.
|
42
|
+
expect(s.comments).to eq "comment\ncomment"
|
43
|
+
expect(s.comments_range).to eq (1..2)
|
44
44
|
|
45
45
|
s = stmt <<-eof
|
46
46
|
# comment
|
47
47
|
def method; end
|
48
48
|
eof
|
49
|
-
s.comments.
|
50
|
-
s.comments_range.
|
49
|
+
expect(s.comments).to eq "comment"
|
50
|
+
expect(s.comments_range).to eq (1..1)
|
51
51
|
|
52
52
|
s = stmt <<-eof
|
53
53
|
def method; end # comment
|
54
54
|
eof
|
55
|
-
s.comments.
|
56
|
-
s.comments_range.
|
55
|
+
expect(s.comments).to eq "comment"
|
56
|
+
expect(s.comments_range).to eq (1..1)
|
57
57
|
end
|
58
58
|
|
59
|
-
it "
|
59
|
+
it "only looks up to two lines back for comments" do
|
60
60
|
s = stmts <<-eof
|
61
61
|
# comments
|
62
62
|
|
@@ -64,7 +64,7 @@ describe YARD::Parser::Ruby::RubyParser do
|
|
64
64
|
|
65
65
|
def method; end
|
66
66
|
eof
|
67
|
-
s[1].comments.
|
67
|
+
expect(s[1].comments).to eq "comments"
|
68
68
|
|
69
69
|
s = stmts <<-eof
|
70
70
|
# comments
|
@@ -72,7 +72,7 @@ describe YARD::Parser::Ruby::RubyParser do
|
|
72
72
|
|
73
73
|
def method; end
|
74
74
|
eof
|
75
|
-
s[1].comments.
|
75
|
+
expect(s[1].comments).to eq nil
|
76
76
|
|
77
77
|
ss = stmts <<-eof
|
78
78
|
# comments
|
@@ -83,11 +83,11 @@ describe YARD::Parser::Ruby::RubyParser do
|
|
83
83
|
# hello
|
84
84
|
def method2; end
|
85
85
|
eof
|
86
|
-
ss[1].comments.
|
87
|
-
ss[2].comments.
|
86
|
+
expect(ss[1].comments).to eq nil
|
87
|
+
expect(ss[2].comments).to eq 'hello'
|
88
88
|
end
|
89
89
|
|
90
|
-
it "
|
90
|
+
it "handles block comment followed by line comment" do
|
91
91
|
ss = stmts <<-eof
|
92
92
|
# comments1
|
93
93
|
|
@@ -97,10 +97,10 @@ comments2
|
|
97
97
|
# comments3
|
98
98
|
def hello; end
|
99
99
|
eof
|
100
|
-
ss.last.comments.
|
100
|
+
expect(ss.last.comments).to eq "comments3"
|
101
101
|
end
|
102
102
|
|
103
|
-
it "
|
103
|
+
it "handles block comment followed by block comment" do
|
104
104
|
ss = stmts <<-eof
|
105
105
|
=begin
|
106
106
|
comments1
|
@@ -110,222 +110,222 @@ comments2
|
|
110
110
|
=end
|
111
111
|
def hello; end
|
112
112
|
eof
|
113
|
-
ss.last.comments.strip.
|
113
|
+
expect(ss.last.comments.strip).to eq "comments2"
|
114
114
|
end
|
115
115
|
|
116
|
-
it "
|
116
|
+
it "handles 1.9 lambda syntax with args" do
|
117
117
|
src = "->(a,b,c=1,*args,&block) { hello_world }"
|
118
|
-
stmt(src).source.
|
118
|
+
expect(stmt(src).source).to eq src
|
119
119
|
end
|
120
120
|
|
121
|
-
it "
|
121
|
+
it "handles 1.9 lambda syntax" do
|
122
122
|
src = "-> { hello_world }"
|
123
|
-
stmt(src).source.
|
123
|
+
expect(stmt(src).source).to eq src
|
124
124
|
end
|
125
125
|
|
126
|
-
it "
|
126
|
+
it "handles standard lambda syntax" do
|
127
127
|
src = "lambda { hello_world }"
|
128
|
-
stmt(src).source.
|
128
|
+
expect(stmt(src).source).to eq src
|
129
129
|
end
|
130
130
|
|
131
|
-
it "
|
132
|
-
|
131
|
+
it "throws a ParserSyntaxError on invalid code" do
|
132
|
+
expect { stmt("Foo, bar.") }.to raise_error(YARD::Parser::ParserSyntaxError)
|
133
133
|
end
|
134
134
|
|
135
|
-
it "
|
135
|
+
it "handles bare hashes as method parameters" do
|
136
136
|
src = "command :a => 1, :b => 2, :c => 3"
|
137
|
-
stmt(src).jump(:command)[1].source.
|
137
|
+
expect(stmt(src).jump(:command)[1].source).to eq ":a => 1, :b => 2, :c => 3"
|
138
138
|
|
139
139
|
src = "command a: 1, b: 2, c: 3"
|
140
|
-
stmt(src).jump(:command)[1].source.
|
140
|
+
expect(stmt(src).jump(:command)[1].source).to eq "a: 1, b: 2, c: 3"
|
141
141
|
end
|
142
142
|
|
143
|
-
it "
|
143
|
+
it "handles source for hash syntax" do
|
144
144
|
src = "{ :a => 1, :b => 2, :c => 3 }"
|
145
|
-
stmt(src).jump(:hash).source.
|
145
|
+
expect(stmt(src).jump(:hash).source).to eq "{ :a => 1, :b => 2, :c => 3 }"
|
146
146
|
end
|
147
147
|
|
148
|
-
it "
|
149
|
-
stmt("{}").jump(:hash).source.
|
148
|
+
it "handles an empty hash" do
|
149
|
+
expect(stmt("{}").jump(:hash).source).to eq "{}"
|
150
150
|
end
|
151
151
|
|
152
152
|
it "new hash label syntax should show label without colon" do
|
153
153
|
ast = stmt("{ a: 1 }").jump(:label)
|
154
|
-
ast[0].
|
155
|
-
ast.source.
|
154
|
+
expect(ast[0]).to eq "a"
|
155
|
+
expect(ast.source).to eq "a:"
|
156
156
|
end
|
157
157
|
|
158
|
-
it "
|
158
|
+
it "handles begin/rescue blocks" do
|
159
159
|
ast = stmt("begin; X; rescue => e; Y end").jump(:rescue)
|
160
|
-
ast.source.
|
160
|
+
expect(ast.source).to eq "rescue => e; Y end"
|
161
161
|
|
162
162
|
ast = stmt("begin; X; rescue A => e; Y end").jump(:rescue)
|
163
|
-
ast.source.
|
163
|
+
expect(ast.source).to eq "rescue A => e; Y end"
|
164
164
|
|
165
165
|
ast = stmt("begin; X; rescue A, B => e; Y end").jump(:rescue)
|
166
|
-
ast.source.
|
166
|
+
expect(ast.source).to eq "rescue A, B => e; Y end"
|
167
167
|
end
|
168
168
|
|
169
|
-
it "
|
169
|
+
it "handles method rescue blocks" do
|
170
170
|
ast = stmt("def x; A; rescue Y; B end")
|
171
|
-
ast.source.
|
172
|
-
ast.jump(:rescue).source.
|
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
173
|
end
|
174
174
|
|
175
|
-
it "
|
175
|
+
it "handles defs with keywords as method name" do
|
176
176
|
ast = stmt("# docstring\nclass A;\ndef class; end\nend")
|
177
|
-
ast.jump(:class).docstring.
|
178
|
-
ast.jump(:class).line_range.
|
177
|
+
expect(ast.jump(:class).docstring).to eq "docstring"
|
178
|
+
expect(ast.jump(:class).line_range).to eq (2..4)
|
179
179
|
end
|
180
180
|
|
181
|
-
it
|
181
|
+
it "handles defs with unnamed argument with default values" do
|
182
182
|
ast = stmt('def hello(one, two = 2, three = 3) end').jump(:params)
|
183
|
-
ast.source.
|
183
|
+
expect(ast.source).to eq 'one, two = 2, three = 3'
|
184
184
|
end
|
185
185
|
|
186
|
-
it
|
186
|
+
it "handles defs with splats" do
|
187
187
|
ast = stmt('def hello(one, *two) end').jump(:params)
|
188
|
-
ast.source.
|
188
|
+
expect(ast.source).to eq 'one, *two'
|
189
189
|
end
|
190
190
|
|
191
191
|
if YARD.ruby2?
|
192
|
-
it
|
192
|
+
it "handles defs with named arguments with default values" do
|
193
193
|
ast = stmt('def hello(one, two: 2, three: 3) end').jump(:params)
|
194
|
-
ast.source.
|
194
|
+
expect(ast.source).to eq 'one, two: 2, three: 3'
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
198
|
if NAMED_OPTIONAL_ARGUMENTS
|
199
|
-
it
|
199
|
+
it "handles defs with named arguments without default values" do
|
200
200
|
ast = stmt('def hello(one, two:, three:) end').jump(:params)
|
201
|
-
ast.source.
|
201
|
+
expect(ast.source).to eq 'one, two:, three:'
|
202
202
|
end
|
203
203
|
|
204
|
-
it
|
204
|
+
it "handles defs with double splats" do
|
205
205
|
ast = stmt('def hello(one, **two) end').jump(:params)
|
206
|
-
ast.source.
|
206
|
+
expect(ast.source).to eq 'one, **two'
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
|
-
it "
|
210
|
+
it "ends source properly on array reference" do
|
211
211
|
ast = stmt("AS[0, 1 ] ")
|
212
|
-
ast.source.
|
212
|
+
expect(ast.source).to eq 'AS[0, 1 ]'
|
213
213
|
|
214
214
|
ast = stmt('def x(a = S[1]) end').jump(:params)
|
215
|
-
ast.source.
|
215
|
+
expect(ast.source).to eq 'a = S[1]'
|
216
216
|
end
|
217
217
|
|
218
|
-
it "
|
218
|
+
it "ends source properly on if/unless mod" do
|
219
219
|
%w(if unless while).each do |mod|
|
220
|
-
stmt("A=1 #{mod} true").source.
|
220
|
+
expect(stmt("A=1 #{mod} true").source).to eq "A=1 #{mod} true"
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
224
|
-
it "
|
225
|
-
stmt("A=1").jump(:assign).source.
|
224
|
+
it "shows proper source for assignment" do
|
225
|
+
expect(stmt("A=1").jump(:assign).source).to eq "A=1"
|
226
226
|
end
|
227
227
|
|
228
|
-
it "
|
228
|
+
it "shows proper source for a top_const_ref" do
|
229
229
|
s = stmt("::\nFoo::Bar")
|
230
|
-
s.jump(:top_const_ref).source.
|
231
|
-
s.
|
232
|
-
s.jump(:top_const_ref).
|
233
|
-
s.source.
|
234
|
-
s.line_range.to_a.
|
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
235
|
end
|
236
236
|
|
237
|
-
it "
|
237
|
+
it "shows proper source for inline heredoc" do
|
238
238
|
src = "def foo\n foo(<<-XML, 1, 2)\n bar\n\n XML\nend"
|
239
239
|
s = stmt(src)
|
240
240
|
t = tokenize(src)
|
241
|
-
s.source.
|
242
|
-
t.map {|x| x[1] }.join.
|
241
|
+
expect(s.source).to eq src
|
242
|
+
expect(t.map { |x| x[1] }.join).to eq src
|
243
243
|
end
|
244
244
|
|
245
|
-
it "
|
245
|
+
it "shows proper source for regular heredoc" do
|
246
246
|
src = "def foo\n x = <<-XML\n Hello \#{name}!\n Bye!\n XML\nend"
|
247
247
|
s = stmt(src)
|
248
248
|
t = tokenize(src)
|
249
|
-
s.source.
|
250
|
-
t.map {|x| x[1] }.join.
|
249
|
+
expect(s.source).to eq src
|
250
|
+
expect(t.map { |x| x[1] }.join).to eq src
|
251
251
|
end
|
252
252
|
|
253
|
-
it "
|
253
|
+
it "shows proper source for heredoc with comment" do
|
254
254
|
src = "def foo\n x = <<-XML # HI!\n Hello \#{name}!\n Bye!\n XML\nend"
|
255
255
|
s = stmt(src)
|
256
256
|
t = tokenize(src)
|
257
|
-
s.source.
|
258
|
-
t.map {|x| x[1] }.join.
|
257
|
+
expect(s.source).to eq src
|
258
|
+
expect(t.map {|x| x[1] }.join).to eq src
|
259
259
|
end
|
260
260
|
|
261
|
-
it "
|
261
|
+
it "shows proper source for string" do
|
262
262
|
["'", '"'].each do |q|
|
263
263
|
src = "#{q}hello\n\nworld#{q}"
|
264
264
|
s = stmt(src)
|
265
|
-
s.jump(:string_content).source.
|
266
|
-
s.source.
|
265
|
+
expect(s.jump(:string_content).source).to eq "hello\n\nworld"
|
266
|
+
expect(s.source).to eq src
|
267
267
|
end
|
268
268
|
|
269
269
|
src = '("this is a string")'
|
270
|
-
stmt(src).jump(:string_literal).source.
|
270
|
+
expect(stmt(src).jump(:string_literal).source).to eq '"this is a string"'
|
271
271
|
end
|
272
272
|
|
273
|
-
it "
|
273
|
+
it "shows proper source for %w() array" do
|
274
274
|
src = "%w(\na b c\n d e f\n)"
|
275
|
-
stmt(src).jump(:qwords_literal).source.
|
275
|
+
expect(stmt(src).jump(:qwords_literal).source).to eq src
|
276
276
|
end
|
277
277
|
|
278
|
-
it "
|
278
|
+
it "shows proper source for %w{} array" do
|
279
279
|
src = "%w{\na b c\n d e f\n}"
|
280
|
-
stmt(src).jump(:array).source.
|
280
|
+
expect(stmt(src).jump(:array).source).to eq src
|
281
281
|
end
|
282
282
|
|
283
|
-
it "
|
283
|
+
it "parses %w() array in constant declaration" do
|
284
284
|
s = stmt(<<-eof)
|
285
285
|
class Foo
|
286
286
|
FOO = %w( foo bar )
|
287
287
|
end
|
288
288
|
eof
|
289
|
-
s.jump(:qwords_literal).source.
|
289
|
+
expect(s.jump(:qwords_literal).source).to eq '%w( foo bar )'
|
290
290
|
if RUBY_VERSION >= '1.9.3' # ripper fix: array node encapsulates qwords
|
291
|
-
s.jump(:array).source.
|
291
|
+
expect(s.jump(:array).source).to eq '%w( foo bar )'
|
292
292
|
end
|
293
293
|
end
|
294
294
|
|
295
|
-
it "
|
295
|
+
it "parses %w() array source in object[] parsed context" do
|
296
296
|
s = stmts(<<-eof)
|
297
297
|
{}[:key]
|
298
298
|
FOO = %w( foo bar )
|
299
299
|
eof
|
300
|
-
s[1].jump(:array).source.
|
300
|
+
expect(s[1].jump(:array).source).to eq '%w( foo bar )'
|
301
301
|
end
|
302
302
|
|
303
|
-
it "
|
303
|
+
it "parses %w() array source in object[]= parsed context" do
|
304
304
|
s = stmts(<<-eof)
|
305
305
|
{}[:key] = :value
|
306
306
|
FOO = %w( foo bar )
|
307
307
|
eof
|
308
|
-
s[1].jump(:array).source.
|
308
|
+
expect(s[1].jump(:array).source).to eq '%w( foo bar )'
|
309
309
|
end
|
310
310
|
|
311
|
-
it "
|
311
|
+
it "parses [] as array" do
|
312
312
|
s = stmt(<<-eof)
|
313
313
|
class Foo
|
314
314
|
FOO = ['foo', 'bar']
|
315
315
|
end
|
316
316
|
eof
|
317
|
-
s.jump(:array).source.
|
317
|
+
expect(s.jump(:array).source).to eq "['foo', 'bar']"
|
318
318
|
end
|
319
319
|
|
320
|
-
it "
|
321
|
-
stmt("X = - 1").jump(:unary).source.
|
320
|
+
it "shows source for unary minus" do
|
321
|
+
expect(stmt("X = - 1").jump(:unary).source).to eq '- 1'
|
322
322
|
end
|
323
323
|
|
324
|
-
it "
|
325
|
-
stmt("X = !1").jump(:unary).source.
|
324
|
+
it "shows source for unary exclamation" do
|
325
|
+
expect(stmt("X = !1").jump(:unary).source).to eq '!1'
|
326
326
|
end
|
327
327
|
|
328
|
-
it "
|
328
|
+
it "has the correct line range for class/modules" do
|
329
329
|
s = stmt(<<-eof)
|
330
330
|
class Foo
|
331
331
|
def foo; end
|
@@ -335,10 +335,20 @@ eof
|
|
335
335
|
# Ending comment
|
336
336
|
end
|
337
337
|
eof
|
338
|
-
s.jump(:class).line_range.
|
338
|
+
expect(s.jump(:class).line_range).to eq (1..7)
|
339
339
|
end
|
340
340
|
|
341
|
-
it "
|
341
|
+
it "has the correct line range for blocks" do
|
342
|
+
Registry.clear
|
343
|
+
ast = YARD.parse_string(<<-eof).enumerator
|
344
|
+
module A
|
345
|
+
some_method
|
346
|
+
end
|
347
|
+
eof
|
348
|
+
expect(ast.first.block.source.strip).to eq "some_method"
|
349
|
+
end
|
350
|
+
|
351
|
+
it "finds lone comments" do
|
342
352
|
Registry.clear
|
343
353
|
ast = YARD.parse_string(<<-eof).enumerator
|
344
354
|
class Foo
|
@@ -351,16 +361,16 @@ eof
|
|
351
361
|
# end comment
|
352
362
|
end
|
353
363
|
eof
|
354
|
-
comment = ast.first.last.
|
355
|
-
comment.type.
|
356
|
-
comment.docstring_hash_flag.
|
357
|
-
comment.docstring.strip.
|
364
|
+
comment = ast.first.last.jump(:comment)
|
365
|
+
expect(comment.type).to eq :comment
|
366
|
+
expect(comment.docstring_hash_flag).to be true
|
367
|
+
expect(comment.docstring.strip).to eq "comment here"
|
358
368
|
|
359
|
-
ast.first.last.last.type.
|
360
|
-
ast.first.last.last.docstring.
|
369
|
+
expect(ast.first.last.last.type).to eq :comment
|
370
|
+
expect(ast.first.last.last.docstring).to eq "end comment"
|
361
371
|
end
|
362
372
|
|
363
|
-
it "
|
373
|
+
it "does not group comments if they don't begin the line" do
|
364
374
|
Registry.clear
|
365
375
|
ast = YARD.parse_string(<<-eof).enumerator
|
366
376
|
class Foo
|
@@ -368,8 +378,8 @@ eof
|
|
368
378
|
CONST2 = 2 # Another comment here
|
369
379
|
end
|
370
380
|
eof
|
371
|
-
Registry.at("Foo::CONST1").docstring.
|
372
|
-
Registry.at("Foo::CONST2").docstring.
|
381
|
+
expect(Registry.at("Foo::CONST1").docstring).to eq "Comment here"
|
382
|
+
expect(Registry.at("Foo::CONST2").docstring).to eq "Another comment here"
|
373
383
|
end
|
374
384
|
end
|
375
385
|
end if HAVE_RIPPER
|