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