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,299 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe YARD::Parser::Ruby::Legacy::StatementList do
|
4
|
-
def stmts(code) YARD::Parser::Ruby::Legacy::StatementList.new(code) end
|
5
|
-
def stmt(code) stmts(code).first end
|
6
|
-
|
7
|
-
it "parses dangling block expressions" do
|
8
|
-
s = stmt <<-eof
|
9
|
-
if
|
10
|
-
foo
|
11
|
-
puts 'hi'
|
12
|
-
end
|
13
|
-
eof
|
14
|
-
|
15
|
-
expect(s.tokens.to_s(true)).to eq "if\n foo\n ...\n end"
|
16
|
-
expect(s.tokens.to_s).to eq "if\n foo"
|
17
|
-
expect(s.block.to_s).to eq "puts 'hi'"
|
18
|
-
|
19
|
-
s = stmt <<-eof
|
20
|
-
if foo ||
|
21
|
-
bar
|
22
|
-
puts 'hi'
|
23
|
-
end
|
24
|
-
eof
|
25
|
-
|
26
|
-
expect(s.tokens.to_s(true)).to eq "if foo ||\n bar\n ...\n end"
|
27
|
-
expect(s.tokens.to_s).to eq "if foo ||\n bar"
|
28
|
-
expect(s.block.to_s).to eq "puts 'hi'"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "allows semicolons within parentheses" do
|
32
|
-
s = stmt "(foo; bar)"
|
33
|
-
|
34
|
-
expect(s.tokens.to_s(true)).to eq "(foo; bar)"
|
35
|
-
expect(s.block).to be nil
|
36
|
-
end
|
37
|
-
|
38
|
-
it "allows for non-block statements" do
|
39
|
-
s = stmt "hello_world(1, 2, 3)"
|
40
|
-
expect(s.tokens.to_s).to eq "hello_world(1, 2, 3)"
|
41
|
-
expect(s.block).to be nil
|
42
|
-
end
|
43
|
-
|
44
|
-
it "allows block statements to be used as part of other block statements" do
|
45
|
-
s = stmt "while (foo; bar); foo = 12; end; while"
|
46
|
-
|
47
|
-
expect(s.tokens.to_s(true)).to eq "while (foo; bar); ... end"
|
48
|
-
expect(s.tokens.to_s).to eq "while (foo; bar)"
|
49
|
-
expect(s.block.to_s).to eq "foo = 12"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "allows continued processing after a block" do
|
53
|
-
s = stmt "if foo; end.stuff"
|
54
|
-
expect(s.tokens.to_s(true)).to eq "if foo; end.stuff"
|
55
|
-
expect(s.block.to_s).to eq ""
|
56
|
-
|
57
|
-
s = stmt "if foo; end[stuff]"
|
58
|
-
expect(s.tokens.to_s(true)).to eq "if foo; end[stuff]"
|
59
|
-
expect(s.block.to_s).to eq ""
|
60
|
-
|
61
|
-
s = stmt "if foo; hi end.map do; 123; end"
|
62
|
-
expect(s.tokens.to_s(true)).to eq "if foo; ... end.map do; 123; end"
|
63
|
-
expect(s.block.to_s).to eq "hi"
|
64
|
-
end
|
65
|
-
|
66
|
-
it "parses default arguments" do
|
67
|
-
s = stmt "def foo(bar, baz = 1, bang = 2); bar; end"
|
68
|
-
expect(s.tokens.to_s(true)).to eq "def foo(bar, baz = 1, bang = 2) ... end"
|
69
|
-
expect(s.block.to_s).to eq "bar"
|
70
|
-
|
71
|
-
s = stmt "def foo bar, baz = 1, bang = 2; bar; end"
|
72
|
-
expect(s.tokens.to_s(true)).to eq "def foo bar, baz = 1, bang = 2; ... end"
|
73
|
-
expect(s.block.to_s).to eq "bar"
|
74
|
-
|
75
|
-
s = stmt "def foo bar , baz = 1 , bang = 2; bar; end"
|
76
|
-
expect(s.tokens.to_s(true)).to eq "def foo bar , baz = 1 , bang = 2; ... end"
|
77
|
-
expect(s.block.to_s).to eq "bar"
|
78
|
-
end
|
79
|
-
|
80
|
-
it "parses complex default arguments" do
|
81
|
-
s = stmt "def foo(bar, baz = File.new(1, 2), bang = 3); bar; end"
|
82
|
-
expect(s.tokens.to_s(true)).to eq "def foo(bar, baz = File.new(1, 2), bang = 3) ... end"
|
83
|
-
expect(s.block.to_s).to eq "bar"
|
84
|
-
|
85
|
-
s = stmt "def foo bar, baz = File.new(1, 2), bang = 3; bar; end"
|
86
|
-
expect(s.tokens.to_s(true)).to eq "def foo bar, baz = File.new(1, 2), bang = 3; ... end"
|
87
|
-
expect(s.block.to_s).to eq "bar"
|
88
|
-
|
89
|
-
s = stmt "def foo bar , baz = File.new(1, 2) , bang = 3; bar; end"
|
90
|
-
expect(s.tokens.to_s(true)).to eq "def foo bar , baz = File.new(1, 2) , bang = 3; ... end"
|
91
|
-
expect(s.block.to_s).to eq "bar"
|
92
|
-
end
|
93
|
-
|
94
|
-
it "parses blocks with do/end" do
|
95
|
-
s = stmt <<-eof
|
96
|
-
foo do
|
97
|
-
puts 'hi'
|
98
|
-
end
|
99
|
-
eof
|
100
|
-
|
101
|
-
expect(s.tokens.to_s(true)).to eq "foo do\n ...\n end"
|
102
|
-
expect(s.block.to_s).to eq "puts 'hi'"
|
103
|
-
end
|
104
|
-
|
105
|
-
it "parses blocks with {}" do
|
106
|
-
s = stmt "x { y }"
|
107
|
-
expect(s.tokens.to_s(true)).to eq "x { ... }"
|
108
|
-
expect(s.block.to_s).to eq "y"
|
109
|
-
|
110
|
-
s = stmt "x() { y }"
|
111
|
-
expect(s.tokens.to_s(true)).to eq "x() { ... }"
|
112
|
-
expect(s.block.to_s).to eq "y"
|
113
|
-
end
|
114
|
-
|
115
|
-
it "parses blocks with begin/end" do
|
116
|
-
s = stmt "begin xyz end"
|
117
|
-
expect(s.tokens.to_s(true)).to eq "begin ... end"
|
118
|
-
expect(s.block.to_s).to eq "xyz"
|
119
|
-
end
|
120
|
-
|
121
|
-
it "parses nested blocks" do
|
122
|
-
s = stmt "foo(:x) { baz(:y) { skippy } }"
|
123
|
-
|
124
|
-
expect(s.tokens.to_s(true)).to eq "foo(:x) { ... }"
|
125
|
-
expect(s.block.to_s).to eq "baz(:y) { skippy }"
|
126
|
-
end
|
127
|
-
|
128
|
-
it "does not parse hashes as blocks" do
|
129
|
-
s = stmt "x({})"
|
130
|
-
expect(s.tokens.to_s(true)).to eq "x({})"
|
131
|
-
expect(s.block.to_s).to eq ""
|
132
|
-
|
133
|
-
s = stmt "x = {}"
|
134
|
-
expect(s.tokens.to_s(true)).to eq "x = {}"
|
135
|
-
expect(s.block.to_s).to eq ""
|
136
|
-
|
137
|
-
s = stmt "x(y, {})"
|
138
|
-
expect(s.tokens.to_s(true)).to eq "x(y, {})"
|
139
|
-
expect(s.block.to_s).to eq ""
|
140
|
-
end
|
141
|
-
|
142
|
-
it "parses hashes in blocks with {}" do
|
143
|
-
s = stmt "x {x = {}}"
|
144
|
-
|
145
|
-
expect(s.tokens.to_s(true)).to eq "x {...}"
|
146
|
-
expect(s.block.to_s).to eq "x = {}"
|
147
|
-
end
|
148
|
-
|
149
|
-
it "parses blocks with {} in hashes" do
|
150
|
-
s = stmt "[:foo, x {}]"
|
151
|
-
|
152
|
-
expect(s.tokens.to_s(true)).to eq "[:foo, x {}]"
|
153
|
-
expect(s.block.to_s).to eq ""
|
154
|
-
end
|
155
|
-
|
156
|
-
it "handles multiple methods" do
|
157
|
-
s = stmt <<-eof
|
158
|
-
def %; end
|
159
|
-
def b; end
|
160
|
-
eof
|
161
|
-
expect(s.to_s).to eq "def %; end"
|
162
|
-
end
|
163
|
-
|
164
|
-
it "handles nested methods" do
|
165
|
-
s = stmt <<-eof
|
166
|
-
def *(o) def +@; end
|
167
|
-
def ~@
|
168
|
-
end end
|
169
|
-
eof
|
170
|
-
expect(s.tokens.to_s(true)).to eq "def *(o) ... end"
|
171
|
-
expect(s.block.to_s).to eq "def +@; end\n def ~@\n end"
|
172
|
-
|
173
|
-
s = stmts(<<-eof)
|
174
|
-
def /(other) 'hi' end
|
175
|
-
def method1
|
176
|
-
def dynamic; end
|
177
|
-
end
|
178
|
-
eof
|
179
|
-
expect(s[1].to_s).to eq "def method1\n def dynamic; end\n end"
|
180
|
-
end
|
181
|
-
|
182
|
-
it "gets comment line numbers" do
|
183
|
-
s = stmt <<-eof
|
184
|
-
# comment
|
185
|
-
# comment
|
186
|
-
# comment
|
187
|
-
def method; end
|
188
|
-
eof
|
189
|
-
expect(s.comments).to eq ["comment", "comment", "comment"]
|
190
|
-
expect(s.comments_range).to eq(1..3)
|
191
|
-
|
192
|
-
s = stmt <<-eof
|
193
|
-
|
194
|
-
# comment
|
195
|
-
# comment
|
196
|
-
def method; end
|
197
|
-
eof
|
198
|
-
expect(s.comments).to eq ["comment", "comment"]
|
199
|
-
expect(s.comments_range).to eq(2..3)
|
200
|
-
|
201
|
-
s = stmt <<-eof
|
202
|
-
# comment
|
203
|
-
# comment
|
204
|
-
|
205
|
-
def method; end
|
206
|
-
eof
|
207
|
-
expect(s.comments).to eq ["comment", "comment"]
|
208
|
-
expect(s.comments_range).to eq(1..2)
|
209
|
-
|
210
|
-
s = stmt <<-eof
|
211
|
-
# comment
|
212
|
-
def method; end
|
213
|
-
eof
|
214
|
-
expect(s.comments).to eq ["comment"]
|
215
|
-
expect(s.comments_range).to eq(1..1)
|
216
|
-
|
217
|
-
s = stmt <<-eof
|
218
|
-
def method; end # comment
|
219
|
-
eof
|
220
|
-
expect(s.comments).to eq ["comment"]
|
221
|
-
expect(s.comments_range).to eq(1..1)
|
222
|
-
end
|
223
|
-
|
224
|
-
it "only looks up to two lines back for comments" do
|
225
|
-
s = stmt <<-eof
|
226
|
-
# comments
|
227
|
-
|
228
|
-
# comments
|
229
|
-
|
230
|
-
def method; end
|
231
|
-
eof
|
232
|
-
expect(s.comments).to eq ["comments"]
|
233
|
-
|
234
|
-
s = stmt <<-eof
|
235
|
-
# comments
|
236
|
-
|
237
|
-
|
238
|
-
def method; end
|
239
|
-
eof
|
240
|
-
expect(s.comments).to eq nil
|
241
|
-
|
242
|
-
ss = stmts <<-eof
|
243
|
-
# comments
|
244
|
-
|
245
|
-
|
246
|
-
def method; end
|
247
|
-
|
248
|
-
# hello
|
249
|
-
def method2; end
|
250
|
-
eof
|
251
|
-
expect(ss[0].comments).to eq nil
|
252
|
-
expect(ss[1].comments).to eq ['hello']
|
253
|
-
end
|
254
|
-
|
255
|
-
it "handles CRLF (Windows) newlines" do
|
256
|
-
s = stmts("require 'foo'\r\n\r\n# Test Test\r\n# \r\n# Example:\r\n# example code\r\ndef test\r\nend\r\n")
|
257
|
-
expect(s[1].comments).to eq ['Test Test', '', 'Example:', ' example code']
|
258
|
-
end
|
259
|
-
|
260
|
-
it "handles elsif blocks" do
|
261
|
-
s = stmts(stmt("if 0\n foo\nelsif 2\n bar\nend\nbaz").block)
|
262
|
-
expect(s.size).to eq 2
|
263
|
-
expect(s[1].tokens.to_s).to eq "elsif 2"
|
264
|
-
expect(s[1].block.to_s).to eq "bar"
|
265
|
-
end
|
266
|
-
|
267
|
-
it "handles else blocks" do
|
268
|
-
s = stmts(stmt("if 0\n foo\nelse\n bar\nend\nbaz").block)
|
269
|
-
expect(s.size).to eq 2
|
270
|
-
expect(s[1].tokens.to_s).to eq "else"
|
271
|
-
expect(s[1].block.to_s).to eq "bar"
|
272
|
-
end
|
273
|
-
|
274
|
-
it "allows aliasing keywords" do
|
275
|
-
['do x', 'x do', 'end begin', 'begin end'].each do |a|
|
276
|
-
s = stmt("alias #{a}\ndef foo; end")
|
277
|
-
expect(s.tokens.to_s).to eq "alias #{a}"
|
278
|
-
expect(s.block).to be nil
|
279
|
-
end
|
280
|
-
|
281
|
-
s = stmt("alias do x if 2 ==\n 2")
|
282
|
-
expect(s.tokens.to_s).to eq "alias do x if 2 ==\n 2"
|
283
|
-
end
|
284
|
-
|
285
|
-
it "does not open a block on an aliased keyword block opener" do
|
286
|
-
s = stmts(<<-eof)
|
287
|
-
class A; alias x do end
|
288
|
-
class B; end
|
289
|
-
eof
|
290
|
-
expect(s[0].block.to_s).to eq 'alias x do'
|
291
|
-
expect(s.size).to be > 1
|
292
|
-
end
|
293
|
-
|
294
|
-
it "converts heredoc to string" do
|
295
|
-
src = "<<-XML\n foo\n\nXML"
|
296
|
-
s = stmt(src)
|
297
|
-
expect(s.source).to eq '"foo\n\n"'
|
298
|
-
end
|
299
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe YARD::Parser::Ruby::Legacy::TokenList do
|
4
|
-
Legacy = YARD::Parser::Ruby::Legacy
|
5
|
-
TokenList = Legacy::TokenList
|
6
|
-
LT = Legacy::RubyToken
|
7
|
-
|
8
|
-
describe "#initialize / #push" do
|
9
|
-
it "accepts a tokenlist (via constructor or push)" do
|
10
|
-
expect { TokenList.new(TokenList.new) }.not_to raise_error
|
11
|
-
expect(TokenList.new.push(TokenList.new("x = 2")).size).to eq 6
|
12
|
-
end
|
13
|
-
|
14
|
-
it "accept a token (via constructor or push)" do
|
15
|
-
expect { TokenList.new(LT::Token.new(0, 0)) }.not_to raise_error
|
16
|
-
expect(TokenList.new.push(LT::Token.new(0, 0),
|
17
|
-
LT::Token.new(1, 1)).size).to eq 2
|
18
|
-
end
|
19
|
-
|
20
|
-
it "accepts a string and parse it as code (via constructor or push)" do
|
21
|
-
expect { TokenList.new("x = 2") }.not_to raise_error
|
22
|
-
x = TokenList.new
|
23
|
-
x.push("x", "=", "2")
|
24
|
-
expect(x.size).to eq 6
|
25
|
-
expect(x.to_s).to eq "x\n=\n2\n"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "does not accept any other input" do
|
29
|
-
expect { TokenList.new(:notcode) }.to raise_error(ArgumentError)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "does not interpolate string data" do
|
33
|
-
x = TokenList.new('x = "hello #{world}"')
|
34
|
-
expect(x.size).to eq 6
|
35
|
-
expect(x[4].class).to eq LT::TkDSTRING
|
36
|
-
expect(x.to_s).to eq 'x = "hello #{world}"' + "\n"
|
37
|
-
end
|
38
|
-
|
39
|
-
it "handles label syntax" do
|
40
|
-
x = TokenList.new('a:1,b:2')
|
41
|
-
expect(x[0].class).to eq LT::TkLABEL
|
42
|
-
expect(x[0].text).to eq 'a:'
|
43
|
-
expect(x[3].class).to eq LT::TkLABEL
|
44
|
-
expect(x[3].text).to eq 'b:'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#to_s" do
|
49
|
-
before do
|
50
|
-
@t = TokenList.new
|
51
|
-
@t << LT::TkDEF.new(1, 1, "def")
|
52
|
-
@t << LT::TkSPACE.new(1, 1)
|
53
|
-
@t << LT::TkIDENTIFIER.new(1, 1, "x")
|
54
|
-
@t << LT::TkStatementEnd.new(1, 1)
|
55
|
-
@t << LT::TkSEMICOLON.new(1, 1) << LT::TkSPACE.new(1, 1)
|
56
|
-
@t << LT::TkBlockContents.new(1, 1)
|
57
|
-
@t << LT::TkSPACE.new(1, 1) << LT::TkEND.new(1, 1, "end")
|
58
|
-
@t[0].set_text "def"
|
59
|
-
@t[1].set_text " "
|
60
|
-
@t[2].set_text "x"
|
61
|
-
@t[4].set_text ";"
|
62
|
-
@t[5].set_text " "
|
63
|
-
@t[7].set_text " "
|
64
|
-
@t[8].set_text "end"
|
65
|
-
end
|
66
|
-
|
67
|
-
it "only shows the statement portion of the tokens by default" do
|
68
|
-
expect(@t.to_s).to eq "def x"
|
69
|
-
end
|
70
|
-
|
71
|
-
it "shows ... for the block token if all of the tokens are shown" do
|
72
|
-
expect(@t.to_s(true)).to eq "def x; ... end"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "ignores ... if show_block = false" do
|
76
|
-
expect(@t.to_s(true, false)).to eq "def x; end"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|