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
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/spec_helper"
|
2
2
|
|
3
3
|
describe YARD::Handlers::C::AliasHandler do
|
4
|
-
it "
|
4
|
+
it "allows defining of aliases (rb_define_alias)" do
|
5
5
|
parse <<-eof
|
6
6
|
/* FOO */
|
7
7
|
VALUE foo(VALUE x) { int value = x; }
|
@@ -12,11 +12,11 @@ describe YARD::Handlers::C::AliasHandler do
|
|
12
12
|
}
|
13
13
|
eof
|
14
14
|
|
15
|
-
Registry.at('Foo#bar').
|
16
|
-
Registry.at('Foo#bar').docstring.
|
15
|
+
expect(Registry.at('Foo#bar')).to be_is_alias
|
16
|
+
expect(Registry.at('Foo#bar').docstring).to eq 'FOO'
|
17
17
|
end
|
18
18
|
|
19
|
-
it "
|
19
|
+
it "allows defining of aliases (rb_define_alias) of attributes" do
|
20
20
|
parse <<-eof
|
21
21
|
/* FOO */
|
22
22
|
VALUE foo(VALUE x) { int value = x; }
|
@@ -27,7 +27,7 @@ describe YARD::Handlers::C::AliasHandler do
|
|
27
27
|
}
|
28
28
|
eof
|
29
29
|
|
30
|
-
Registry.at('Foo#foo').
|
31
|
-
Registry.at('Foo#foo?').
|
30
|
+
expect(Registry.at('Foo#foo')).to be_reader
|
31
|
+
expect(Registry.at('Foo#foo?')).to be_is_alias
|
32
32
|
end
|
33
33
|
end
|
@@ -14,27 +14,27 @@ describe YARD::Handlers::C::AttributeHandler do
|
|
14
14
|
eof
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
17
|
+
it "handles readonly attribute (rb_define_attr)" do
|
18
18
|
run(1, 0)
|
19
|
-
Registry.at('Foo#foo').
|
20
|
-
Registry.at('Foo#foo=').
|
19
|
+
expect(Registry.at('Foo#foo')).to be_reader
|
20
|
+
expect(Registry.at('Foo#foo=')).to be nil
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
23
|
+
it "handles writeonly attribute (rb_define_attr)" do
|
24
24
|
run(0, 1)
|
25
|
-
Registry.at('Foo#foo').
|
26
|
-
Registry.at('Foo#foo=').
|
25
|
+
expect(Registry.at('Foo#foo')).to be nil
|
26
|
+
expect(Registry.at('Foo#foo=')).to be_writer
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
29
|
+
it "handles readwrite attribute (rb_define_attr)" do
|
30
30
|
run(1, 1)
|
31
|
-
Registry.at('Foo#foo').
|
32
|
-
Registry.at('Foo#foo=').
|
31
|
+
expect(Registry.at('Foo#foo')).to be_reader
|
32
|
+
expect(Registry.at('Foo#foo=')).to be_writer
|
33
33
|
end
|
34
34
|
|
35
|
-
it "
|
35
|
+
it "handles commented writeonly attribute (/* rb_define_attr */)" do
|
36
36
|
run(1, 1, true)
|
37
|
-
Registry.at('Foo#foo').
|
38
|
-
Registry.at('Foo#foo=').
|
37
|
+
expect(Registry.at('Foo#foo')).to be_reader
|
38
|
+
expect(Registry.at('Foo#foo=')).to be_writer
|
39
39
|
end
|
40
40
|
end
|
@@ -1,63 +1,76 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/spec_helper"
|
2
2
|
|
3
3
|
describe YARD::Handlers::C::ClassHandler do
|
4
|
-
it "
|
4
|
+
it "registers classes" do
|
5
5
|
parse_init 'cFoo = rb_define_class("Foo", rb_cObject);'
|
6
|
-
Registry.at('Foo').type.
|
6
|
+
expect(Registry.at('Foo').type).to eq :class
|
7
7
|
end
|
8
8
|
|
9
|
-
it "
|
10
|
-
parse_init
|
11
|
-
|
9
|
+
it "registers classes under namespaces" do
|
10
|
+
parse_init <<-EOF
|
11
|
+
cBar = rb_define_class("Bar", rb_cObject);
|
12
|
+
cFoo = rb_define_class_under(cBar, "Foo", rb_cObject);
|
13
|
+
EOF
|
14
|
+
expect(Registry.at('Bar::Foo').type).to eq :class
|
12
15
|
end
|
13
16
|
|
14
|
-
it "
|
17
|
+
it "remembers symbol defined with class" do
|
15
18
|
parse_init(<<-eof)
|
16
19
|
cXYZ = rb_define_class("Foo", rb_cObject);
|
17
20
|
rb_define_method(cXYZ, "bar", bar, 0);
|
18
21
|
eof
|
19
|
-
Registry.at('Foo').type.
|
20
|
-
Registry.at('Foo#bar').
|
22
|
+
expect(Registry.at('Foo').type).to eq :class
|
23
|
+
expect(Registry.at('Foo#bar')).not_to be nil
|
21
24
|
end
|
22
25
|
|
23
|
-
it "
|
26
|
+
it "looks up superclass symbol name" do
|
24
27
|
parse_init(<<-eof)
|
25
28
|
cXYZ = rb_define_class("Foo", rb_cObject);
|
26
29
|
cBar = rb_define_class("Bar", cXYZ);
|
27
30
|
eof
|
28
|
-
Registry.at('Bar').superclass.
|
31
|
+
expect(Registry.at('Bar').superclass).to eq Registry.at('Foo')
|
29
32
|
end
|
30
33
|
|
31
|
-
it "
|
34
|
+
it "uses superclass symbol name as proxy if not found" do
|
32
35
|
parse_init(<<-eof)
|
33
36
|
// cXYZ = rb_define_class("Foo", rb_cObject);
|
34
37
|
cBar = rb_define_class("Bar", cXYZ);
|
35
38
|
eof
|
36
|
-
Registry.at('Bar').superclass.
|
39
|
+
expect(Registry.at('Bar').superclass).to eq P('XYZ')
|
37
40
|
end
|
38
41
|
|
39
|
-
it "
|
42
|
+
it "does not associate declaration comments as class docstring" do
|
40
43
|
parse_init(<<-eof)
|
41
44
|
/* Docstring! */
|
42
45
|
cFoo = rb_define_class("Foo", cObject);
|
43
46
|
eof
|
44
|
-
Registry.at('Foo').docstring.
|
47
|
+
expect(Registry.at('Foo').docstring).to be_blank
|
45
48
|
end
|
46
49
|
|
47
|
-
it "
|
50
|
+
it "associates a file with the declaration" do
|
48
51
|
parse_init(<<-eof)
|
49
52
|
cFoo = rb_define_class("Foo", cObject);
|
50
53
|
eof
|
51
|
-
Registry.at('Foo').file.
|
52
|
-
Registry.at('Foo').line.
|
54
|
+
expect(Registry.at('Foo').file).to eq '(stdin)'
|
55
|
+
expect(Registry.at('Foo').line).to eq 2
|
53
56
|
end
|
54
57
|
|
55
|
-
it "
|
58
|
+
it "properly handles Proxy superclasses" do
|
56
59
|
parse_init <<-eof
|
57
|
-
|
60
|
+
mFoo = rb_define_module("Foo");
|
61
|
+
cBar = rb_define_class_under(mFoo, "Bar", rb_cBar);
|
58
62
|
eof
|
59
|
-
Registry.at('Foo::Bar').type.
|
60
|
-
Registry.at('Foo::Bar').superclass.
|
61
|
-
Registry.at('Foo::Bar').superclass.type.
|
63
|
+
expect(Registry.at('Foo::Bar').type).to eq :class
|
64
|
+
expect(Registry.at('Foo::Bar').superclass).to eq P('Bar')
|
65
|
+
expect(Registry.at('Foo::Bar').superclass.type).to eq :class
|
66
|
+
end
|
67
|
+
|
68
|
+
it "resolves namespace variable names across multiple files" do
|
69
|
+
parse_multi_file_init(
|
70
|
+
'cBar = rb_define_class_under(cFoo, "Bar", rb_cObject);',
|
71
|
+
'cFoo = rb_define_class("Foo", rb_cObject);'
|
72
|
+
)
|
73
|
+
|
74
|
+
expect(Registry.at('Foo::Bar').type).to eq :class
|
62
75
|
end
|
63
76
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/spec_helper"
|
2
2
|
|
3
3
|
describe YARD::Handlers::C::ConstantHandler do
|
4
|
-
it "
|
4
|
+
it "registers constants" do
|
5
5
|
parse_init <<-eof
|
6
6
|
mFoo = rb_define_module("Foo");
|
7
7
|
rb_define_const(mFoo, "FOO", ID2SYM(100));
|
8
|
+
rb_define_global_const("BAR", ID2SYM(100));
|
8
9
|
eof
|
9
|
-
|
10
|
+
expect( Registry.at('Foo::FOO').type).to eq :constant
|
11
|
+
expect( Registry.at('BAR').type).to eq :constant
|
10
12
|
end
|
11
13
|
|
12
|
-
it "
|
14
|
+
it "looks for override comments" do
|
13
15
|
parse <<-eof
|
14
16
|
/* Document-const: FOO
|
15
17
|
* Document-const: Foo::BAR
|
@@ -23,46 +25,46 @@ describe YARD::Handlers::C::ConstantHandler do
|
|
23
25
|
}
|
24
26
|
eof
|
25
27
|
foo = Registry.at('Foo::FOO')
|
26
|
-
foo.type.
|
27
|
-
foo.docstring.
|
28
|
-
foo.value.
|
29
|
-
foo.file.
|
30
|
-
foo.line.
|
28
|
+
expect(foo.type).to eq :constant
|
29
|
+
expect(foo.docstring).to eq 'Foo bar!'
|
30
|
+
expect(foo.value).to eq 'ID2SYM(100)'
|
31
|
+
expect(foo.file).to eq '(stdin)'
|
32
|
+
expect(foo.line).to eq 8
|
31
33
|
bar = Registry.at('Foo::BAR')
|
32
|
-
bar.type.
|
33
|
-
bar.docstring.
|
34
|
-
bar.file.
|
35
|
-
bar.line.
|
36
|
-
bar.value.
|
34
|
+
expect(bar.type).to eq :constant
|
35
|
+
expect(bar.docstring).to eq 'Foo bar!'
|
36
|
+
expect(bar.file).to eq '(stdin)'
|
37
|
+
expect(bar.line).to eq 9
|
38
|
+
expect(bar.value).to eq 'ID2SYM(101)'
|
37
39
|
end
|
38
40
|
|
39
|
-
it "
|
41
|
+
it "uses comment attached to declaration as fallback" do
|
40
42
|
parse_init <<-eof
|
41
43
|
mFoo = rb_define_module("Foo");
|
42
44
|
rb_define_const(mFoo, "FOO", ID2SYM(100)); // foobar!
|
43
45
|
eof
|
44
46
|
foo = Registry.at('Foo::FOO')
|
45
|
-
foo.value.
|
46
|
-
foo.docstring.
|
47
|
+
expect(foo.value).to eq 'ID2SYM(100)'
|
48
|
+
expect(foo.docstring).to eq 'foobar!'
|
47
49
|
end
|
48
50
|
|
49
|
-
it "
|
51
|
+
it "allows the form VALUE: DOCSTRING to document value" do
|
50
52
|
parse_init <<-eof
|
51
53
|
mFoo = rb_define_module("Foo");
|
52
54
|
rb_define_const(mFoo, "FOO", ID2SYM(100)); // 100: foobar!
|
53
55
|
eof
|
54
56
|
foo = Registry.at('Foo::FOO')
|
55
|
-
foo.value.
|
56
|
-
foo.docstring.
|
57
|
+
expect(foo.value).to eq '100'
|
58
|
+
expect(foo.docstring).to eq 'foobar!'
|
57
59
|
end
|
58
60
|
|
59
|
-
it "
|
61
|
+
it "allows escaping of backslashes in VALUE: DOCSTRING syntax" do
|
60
62
|
parse_init <<-eof
|
61
63
|
mFoo = rb_define_module("Foo");
|
62
64
|
rb_define_const(mFoo, "FOO", ID2SYM(100)); // 100\\:x\\:y: foobar:x!
|
63
65
|
eof
|
64
66
|
foo = Registry.at('Foo::FOO')
|
65
|
-
foo.value.
|
66
|
-
foo.docstring.
|
67
|
+
expect(foo.value).to eq '100:x:y'
|
68
|
+
expect(foo.docstring).to eq 'foobar:x!'
|
67
69
|
end
|
68
70
|
end
|
@@ -1,47 +1,47 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/spec_helper"
|
2
2
|
|
3
3
|
describe YARD::Handlers::C::InitHandler do
|
4
|
-
it "
|
4
|
+
it "adds documentation in Init_ClassName() to ClassName" do
|
5
5
|
parse(<<-eof)
|
6
6
|
// Bar!
|
7
7
|
void Init_A() {
|
8
8
|
rb_cA = rb_define_class("A", rb_cObject);
|
9
9
|
}
|
10
10
|
eof
|
11
|
-
Registry.at('A').docstring.
|
11
|
+
expect(Registry.at('A').docstring).to eq 'Bar!'
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "does not add documentation if ClassName is not created in Init" do
|
15
15
|
parse(<<-eof)
|
16
16
|
// Bar!
|
17
17
|
void Init_A() {
|
18
18
|
}
|
19
19
|
eof
|
20
|
-
Registry.at('A').
|
20
|
+
expect(Registry.at('A')).to be nil
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
23
|
+
it "does not overwrite override comment" do
|
24
24
|
parse(<<-eof)
|
25
25
|
/* Document-class: A
|
26
26
|
* Foo!
|
27
27
|
*/
|
28
28
|
|
29
29
|
// Bar!
|
30
|
-
void Init_A() {
|
30
|
+
static SWIGEXPORT void Init_A() {
|
31
31
|
rb_cA = rb_define_class("A", rb_cObject);
|
32
32
|
}
|
33
33
|
eof
|
34
|
-
Registry.at('A').docstring.
|
34
|
+
expect(Registry.at('A').docstring).to eq 'Foo!'
|
35
35
|
end
|
36
36
|
|
37
|
-
it "
|
37
|
+
it "checks non-Init methods for declarations too" do
|
38
38
|
parse(<<-eof)
|
39
39
|
void foo(int x, int y, char *name) {
|
40
40
|
rb_cB = rb_define_class("B", rb_cObject);
|
41
41
|
rb_define_method(rb_cB, "foo", foo_impl, 0);
|
42
42
|
}
|
43
43
|
eof
|
44
|
-
Registry.at('B').
|
45
|
-
Registry.at('B#foo').
|
44
|
+
expect(Registry.at('B')).to be_a(CodeObjects::ClassObject)
|
45
|
+
expect(Registry.at('B#foo')).to be_a(CodeObjects::MethodObject)
|
46
46
|
end
|
47
47
|
end
|
@@ -1,34 +1,34 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/spec_helper"
|
2
2
|
|
3
3
|
describe YARD::Handlers::C::MethodHandler do
|
4
|
-
it "
|
4
|
+
it "registers methods" do
|
5
5
|
parse_init <<-eof
|
6
6
|
mFoo = rb_define_module("Foo");
|
7
7
|
rb_define_method(mFoo, "bar", bar, 0);
|
8
8
|
eof
|
9
|
-
Registry.at('Foo#bar').
|
10
|
-
Registry.at('Foo#bar').visibility.
|
9
|
+
expect(Registry.at('Foo#bar')).not_to be nil
|
10
|
+
expect(Registry.at('Foo#bar').visibility).to eq :public
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
13
|
+
it "registers private methods" do
|
14
14
|
parse_init <<-eof
|
15
15
|
mFoo = rb_define_module("Foo");
|
16
16
|
rb_define_private_method(mFoo, "bar", bar, 0);
|
17
17
|
eof
|
18
|
-
Registry.at('Foo#bar').
|
19
|
-
Registry.at('Foo#bar').visibility.
|
18
|
+
expect(Registry.at('Foo#bar')).not_to be nil
|
19
|
+
expect(Registry.at('Foo#bar').visibility).to eq :private
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
22
|
+
it "registers singleton methods" do
|
23
23
|
parse_init <<-eof
|
24
24
|
mFoo = rb_define_module("Foo");
|
25
25
|
rb_define_singleton_method(mFoo, "bar", bar, 0);
|
26
26
|
eof
|
27
|
-
Registry.at('Foo.bar').
|
28
|
-
Registry.at('Foo.bar').visibility.
|
27
|
+
expect(Registry.at('Foo.bar')).not_to be nil
|
28
|
+
expect(Registry.at('Foo.bar').visibility).to eq :public
|
29
29
|
end
|
30
30
|
|
31
|
-
it "
|
31
|
+
it "registers module functions" do
|
32
32
|
parse <<-eof
|
33
33
|
/* DOCSTRING
|
34
34
|
* @return [String] foo!
|
@@ -42,24 +42,24 @@ describe YARD::Handlers::C::MethodHandler do
|
|
42
42
|
eof
|
43
43
|
bar_c = Registry.at('Foo.bar')
|
44
44
|
bar_i = Registry.at('Foo#bar')
|
45
|
-
bar_c.
|
46
|
-
bar_c.visibility.
|
47
|
-
bar_c.docstring.
|
48
|
-
bar_c.tag(:return).object.
|
49
|
-
bar_c.source.
|
50
|
-
bar_i.
|
51
|
-
bar_i.visibility.
|
52
|
-
bar_i.docstring.
|
53
|
-
bar_i.tag(:return).object.
|
54
|
-
bar_i.source.
|
55
|
-
end
|
56
|
-
|
57
|
-
it "
|
45
|
+
expect(bar_c).to be_module_function
|
46
|
+
expect(bar_c.visibility).to eq :public
|
47
|
+
expect(bar_c.docstring).to eq "DOCSTRING"
|
48
|
+
expect(bar_c.tag(:return).object).to eq bar_c
|
49
|
+
expect(bar_c.source).to eq "static VALUE bar(VALUE self) { x(); y(); z(); }"
|
50
|
+
expect(bar_i).not_to be_module_function
|
51
|
+
expect(bar_i.visibility).to eq :private
|
52
|
+
expect(bar_i.docstring).to eq "DOCSTRING"
|
53
|
+
expect(bar_i.tag(:return).object).to eq bar_i
|
54
|
+
expect(bar_i.source).to eq bar_c.source
|
55
|
+
end
|
56
|
+
|
57
|
+
it "registers global functions into Kernel" do
|
58
58
|
parse_init 'rb_define_global_function("bar", bar, 0);'
|
59
|
-
Registry.at('Kernel#bar').
|
59
|
+
expect(Registry.at('Kernel#bar')).not_to be nil
|
60
60
|
end
|
61
61
|
|
62
|
-
it "
|
62
|
+
it "looks for symbol containing method source" do
|
63
63
|
parse <<-eof
|
64
64
|
static VALUE foo(VALUE self) { x(); y(); z(); }
|
65
65
|
VALUE bar() { a(); b(); c(); }
|
@@ -71,15 +71,15 @@ describe YARD::Handlers::C::MethodHandler do
|
|
71
71
|
eof
|
72
72
|
foo = Registry.at('Foo#foo')
|
73
73
|
bar = Registry.at('Foo#bar')
|
74
|
-
foo.source.
|
75
|
-
foo.file.
|
76
|
-
foo.line.
|
77
|
-
bar.source.
|
78
|
-
bar.file.
|
79
|
-
bar.line.
|
74
|
+
expect(foo.source).to eq "static VALUE foo(VALUE self) { x(); y(); z(); }"
|
75
|
+
expect(foo.file).to eq '(stdin)'
|
76
|
+
expect(foo.line).to eq 1
|
77
|
+
expect(bar.source).to eq "VALUE bar() { a(); b(); c(); }"
|
78
|
+
expect(bar.file).to eq '(stdin)'
|
79
|
+
expect(bar.line).to eq 2
|
80
80
|
end
|
81
81
|
|
82
|
-
it "
|
82
|
+
it "finds docstrings attached to method symbols" do
|
83
83
|
parse <<-eof
|
84
84
|
/* DOCSTRING */
|
85
85
|
static VALUE foo(VALUE self) { x(); y(); z(); }
|
@@ -89,10 +89,10 @@ describe YARD::Handlers::C::MethodHandler do
|
|
89
89
|
}
|
90
90
|
eof
|
91
91
|
foo = Registry.at('Foo#foo')
|
92
|
-
foo.docstring.
|
92
|
+
expect(foo.docstring).to eq 'DOCSTRING'
|
93
93
|
end
|
94
94
|
|
95
|
-
it "
|
95
|
+
it "uses declaration comments as docstring if there are no others" do
|
96
96
|
parse <<-eof
|
97
97
|
static VALUE foo(VALUE self) { x(); y(); z(); }
|
98
98
|
void Init_Foo() {
|
@@ -104,17 +104,17 @@ describe YARD::Handlers::C::MethodHandler do
|
|
104
104
|
}
|
105
105
|
eof
|
106
106
|
foo = Registry.at('Foo#foo')
|
107
|
-
foo.docstring.
|
107
|
+
expect(foo.docstring).to eq 'DOCSTRING'
|
108
108
|
bar = Registry.at('Foo#bar')
|
109
|
-
bar.docstring.
|
109
|
+
expect(bar.docstring).to eq 'DOCSTRING!'
|
110
110
|
end
|
111
111
|
|
112
|
-
it "
|
112
|
+
it "looks for symbols in other file" do
|
113
113
|
other = <<-eof
|
114
114
|
/* DOCSTRING! */
|
115
115
|
static VALUE foo() { x(); }
|
116
116
|
eof
|
117
|
-
File.
|
117
|
+
expect(File).to receive(:read).with('other.c').and_return(other)
|
118
118
|
parse <<-eof
|
119
119
|
void Init_Foo() {
|
120
120
|
mFoo = rb_define_module("Foo");
|
@@ -122,14 +122,14 @@ describe YARD::Handlers::C::MethodHandler do
|
|
122
122
|
}
|
123
123
|
eof
|
124
124
|
foo = Registry.at('Foo#foo')
|
125
|
-
foo.docstring.
|
126
|
-
foo.file.
|
127
|
-
foo.line.
|
128
|
-
foo.source.
|
125
|
+
expect(foo.docstring).to eq 'DOCSTRING!'
|
126
|
+
expect(foo.file).to eq 'other.c'
|
127
|
+
expect(foo.line).to eq 2
|
128
|
+
expect(foo.source).to eq 'static VALUE foo() { x(); }'
|
129
129
|
end
|
130
130
|
|
131
|
-
it "
|
132
|
-
File.
|
131
|
+
it "allows extra file to include /'s and other filename characters" do
|
132
|
+
expect(File).to receive(:read).at_least(1).times.with('ext/a-file.c').and_return(<<-eof)
|
133
133
|
/* FOO */
|
134
134
|
VALUE foo(VALUE x) { int value = x; }
|
135
135
|
|
@@ -140,12 +140,12 @@ describe YARD::Handlers::C::MethodHandler do
|
|
140
140
|
rb_define_method(rb_cFoo, "foo", foo, 1); /* in ext/a-file.c */
|
141
141
|
rb_define_global_function("bar", bar, 1); /* in ext/a-file.c */
|
142
142
|
eof
|
143
|
-
Registry.at('Foo#foo').docstring.
|
144
|
-
Registry.at('Kernel#bar').docstring.
|
143
|
+
expect(Registry.at('Foo#foo').docstring).to eq 'FOO'
|
144
|
+
expect(Registry.at('Kernel#bar').docstring).to eq 'BAR'
|
145
145
|
end
|
146
146
|
|
147
|
-
it "
|
148
|
-
log.
|
147
|
+
it "warns if other file can't be found" do
|
148
|
+
expect(log).to receive(:warn).with(/Missing source file `other.c' when parsing Foo#foo/)
|
149
149
|
parse <<-eof
|
150
150
|
void Init_Foo() {
|
151
151
|
mFoo = rb_define_module("Foo");
|
@@ -154,7 +154,7 @@ describe YARD::Handlers::C::MethodHandler do
|
|
154
154
|
eof
|
155
155
|
end
|
156
156
|
|
157
|
-
it "
|
157
|
+
it "looks at override comments for docstring" do
|
158
158
|
parse <<-eof
|
159
159
|
/* Document-method: Foo::foo
|
160
160
|
* Document-method: new
|
@@ -171,12 +171,12 @@ describe YARD::Handlers::C::MethodHandler do
|
|
171
171
|
rb_define_method(mBar, "baz", foo, 0);
|
172
172
|
}
|
173
173
|
eof
|
174
|
-
Registry.at('Foo#foo').docstring.
|
175
|
-
Registry.at('Foo#initialize').docstring.
|
176
|
-
Registry.at('Foo::Bar#baz').docstring.
|
174
|
+
expect(Registry.at('Foo#foo').docstring).to eq 'Foo bar!'
|
175
|
+
expect(Registry.at('Foo#initialize').docstring).to eq 'Foo bar!'
|
176
|
+
expect(Registry.at('Foo::Bar#baz').docstring).to eq 'Foo bar!'
|
177
177
|
end
|
178
178
|
|
179
|
-
it "
|
179
|
+
it "looks at overrides in other files" do
|
180
180
|
other = <<-eof
|
181
181
|
/* Document-method: Foo::foo
|
182
182
|
* Document-method: new
|
@@ -184,7 +184,7 @@ describe YARD::Handlers::C::MethodHandler do
|
|
184
184
|
* Foo bar!
|
185
185
|
*/
|
186
186
|
eof
|
187
|
-
File.
|
187
|
+
expect(File).to receive(:read).with('foo/bar/other.c').and_return(other)
|
188
188
|
src = <<-eof
|
189
189
|
void Init_Foo() {
|
190
190
|
mFoo = rb_define_module("Foo");
|
@@ -195,12 +195,12 @@ describe YARD::Handlers::C::MethodHandler do
|
|
195
195
|
}
|
196
196
|
eof
|
197
197
|
parse(src, 'foo/bar/baz/init.c')
|
198
|
-
Registry.at('Foo#foo').docstring.
|
199
|
-
Registry.at('Foo#initialize').docstring.
|
200
|
-
Registry.at('Foo::Bar#baz').docstring.
|
198
|
+
expect(Registry.at('Foo#foo').docstring).to eq 'Foo bar!'
|
199
|
+
expect(Registry.at('Foo#initialize').docstring).to eq 'Foo bar!'
|
200
|
+
expect(Registry.at('Foo::Bar#baz').docstring).to eq 'Foo bar!'
|
201
201
|
end
|
202
202
|
|
203
|
-
it "
|
203
|
+
it "adds return tag on methods ending in '?'" do
|
204
204
|
parse <<-eof
|
205
205
|
/* DOCSTRING */
|
206
206
|
static VALUE foo(VALUE self) { x(); y(); z(); }
|
@@ -210,11 +210,11 @@ describe YARD::Handlers::C::MethodHandler do
|
|
210
210
|
}
|
211
211
|
eof
|
212
212
|
foo = Registry.at('Foo#foo?')
|
213
|
-
foo.docstring.
|
214
|
-
foo.tag(:return).types.
|
213
|
+
expect(foo.docstring).to eq 'DOCSTRING'
|
214
|
+
expect(foo.tag(:return).types).to eq ['Boolean']
|
215
215
|
end
|
216
216
|
|
217
|
-
it "
|
217
|
+
it "does not add return tag if return tags exist" do
|
218
218
|
parse <<-eof
|
219
219
|
// @return [String] foo
|
220
220
|
static VALUE foo(VALUE self) { x(); y(); z(); }
|
@@ -224,16 +224,101 @@ describe YARD::Handlers::C::MethodHandler do
|
|
224
224
|
}
|
225
225
|
eof
|
226
226
|
foo = Registry.at('Foo#foo?')
|
227
|
-
foo.tag(:return).types.
|
227
|
+
expect(foo.tag(:return).types).to eq ['String']
|
228
228
|
end
|
229
229
|
|
230
|
-
it "
|
230
|
+
it "handles casted method names" do
|
231
231
|
parse_init <<-eof
|
232
232
|
mFoo = rb_define_module("Foo");
|
233
233
|
rb_define_method(mFoo, "bar", (METHOD)bar, 0);
|
234
234
|
rb_define_global_function("baz", (METHOD)baz, 0);
|
235
235
|
eof
|
236
|
-
Registry.at('Foo#bar').
|
237
|
-
Registry.at('Kernel#baz').
|
236
|
+
expect(Registry.at('Foo#bar')).not_to be nil
|
237
|
+
expect(Registry.at('Kernel#baz')).not_to be nil
|
238
|
+
end
|
239
|
+
|
240
|
+
it "extracts at regular method parameters from C function signatures" do
|
241
|
+
parse <<-eof
|
242
|
+
static VALUE noargs_func(VALUE self) { return Qnil; }
|
243
|
+
static VALUE twoargs_func(VALUE self, VALUE a, VALUE b) { return a; }
|
244
|
+
void Init_Foo() {
|
245
|
+
mFoo = rb_define_module("Foo");
|
246
|
+
rb_define_method(mFoo, "noargs", noargs_func, 0);
|
247
|
+
rb_define_method(mFoo, "twoargs", twoargs_func, 2);
|
248
|
+
}
|
249
|
+
eof
|
250
|
+
expect(Registry.at('Foo#noargs').parameters).to be_empty
|
251
|
+
expect(Registry.at('Foo#twoargs').parameters).to eq [['a', nil], ['b', nil]]
|
252
|
+
end
|
253
|
+
|
254
|
+
it "extracts at varargs method parameters from C function signatures" do
|
255
|
+
parse <<-eof
|
256
|
+
static VALUE varargs_func(int argc, VALUE *argv, VALUE self) { return self; }
|
257
|
+
/* let's see if parser is robust in the face of strange spacing */
|
258
|
+
static VALUE varargs_func2( int argc , VALUE
|
259
|
+
* argv ,VALUE self )
|
260
|
+
|
261
|
+
{return self;}
|
262
|
+
void Init_Foo() {
|
263
|
+
mFoo = rb_define_module("Foo");
|
264
|
+
rb_define_method(mFoo, "varargs", varargs_func, -1);
|
265
|
+
rb_define_method( mFoo ,"varargs2",varargs_func2 ,-1);
|
266
|
+
}
|
267
|
+
eof
|
268
|
+
expect(Registry.at('Foo#varargs').parameters).to eq [['*args', nil]]
|
269
|
+
expect(Registry.at('Foo#varargs2').parameters).to eq [['*args', nil]]
|
270
|
+
end
|
271
|
+
|
272
|
+
it "is not too strict or too loose about matching override comments to methods" do
|
273
|
+
parse <<-eof
|
274
|
+
/* Document-method: Foo::foo
|
275
|
+
* Document-method: new
|
276
|
+
* Document-method: Foo::Bar#baz
|
277
|
+
* Foo bar!
|
278
|
+
*/
|
279
|
+
|
280
|
+
void Init_Foo() {
|
281
|
+
mFoo = rb_define_module("Foo");
|
282
|
+
mBar = rb_define_module_under(mFoo, "Bar");
|
283
|
+
|
284
|
+
rb_define_method(mFoo, "foo", foo, 0);
|
285
|
+
rb_define_singleton_method(mFoo, "foo", foo, 0);
|
286
|
+
rb_define_method(mBar, "foo", foo, 0);
|
287
|
+
rb_define_singleton_method(mBar, "foo", foo, 0);
|
288
|
+
|
289
|
+
rb_define_method(mFoo, "initialize", foo, 0);
|
290
|
+
rb_define_method(mBar, "initialize", foo, 0);
|
291
|
+
|
292
|
+
rb_define_method(mFoo, "baz", foo, 0);
|
293
|
+
rb_define_singleton_method(mFoo, "baz", foo, 0);
|
294
|
+
rb_define_method(mBar, "baz", foo, 0);
|
295
|
+
rb_define_singleton_method(mBar, "baz", foo, 0);
|
296
|
+
}
|
297
|
+
eof
|
298
|
+
expect(Registry.at('Foo#foo').docstring).to eq 'Foo bar!'
|
299
|
+
expect(Registry.at('Foo.foo').docstring).to eq 'Foo bar!'
|
300
|
+
expect(Registry.at('Foo::Bar#foo').docstring).to be_empty
|
301
|
+
expect(Registry.at('Foo::Bar.foo').docstring).to be_empty
|
302
|
+
expect(Registry.at('Foo#initialize').docstring).to eq 'Foo bar!'
|
303
|
+
expect(Registry.at('Foo::Bar#initialize').docstring).to eq 'Foo bar!'
|
304
|
+
expect(Registry.at('Foo#baz').docstring).to be_empty
|
305
|
+
expect(Registry.at('Foo.baz').docstring).to be_empty
|
306
|
+
expect(Registry.at('Foo::Bar#baz').docstring).to eq 'Foo bar!'
|
307
|
+
expect(Registry.at('Foo::Bar.baz').docstring).to be_empty
|
308
|
+
end
|
309
|
+
|
310
|
+
it "recognizes core Ruby classes and modules provided by ruby.h" do
|
311
|
+
parse_init <<-eof
|
312
|
+
rb_define_method(rb_cFixnum, "popcount", fix_popcount, 0);
|
313
|
+
rb_define_private_method(rb_mKernel, "pp", obj_pp, 0);
|
314
|
+
rb_define_method(rb_mEnumerable, "to_hash", enum_to_hash, 0);
|
315
|
+
eof
|
316
|
+
expect(Registry.at('Fixnum').type).to eq :class
|
317
|
+
expect(Registry.at('Fixnum#popcount').type).to eq :method
|
318
|
+
expect(Registry.at('Object').type).to eq :class
|
319
|
+
# Methods defined on Kernel are treated as if they were defined on Object
|
320
|
+
expect(Registry.at('Object#pp').type).to eq :method
|
321
|
+
expect(Registry.at('Enumerable').type).to eq :module
|
322
|
+
expect(Registry.at('Enumerable#to_hash').type).to eq :method
|
238
323
|
end
|
239
324
|
end
|