yard 0.7.5 → 0.8.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.
- data/.yardopts +10 -2
- data/ChangeLog +1263 -38
- data/LEGAL +5 -5
- data/LICENSE +1 -1
- data/README.md +91 -82
- data/Rakefile +6 -6
- data/benchmarks/builtins_vs_eval.rb +1 -1
- data/benchmarks/erb_vs_erubis.rb +4 -4
- data/benchmarks/generation.rb +5 -5
- data/benchmarks/parsing.rb +2 -2
- data/benchmarks/registry_store_types.rb +48 -0
- data/bin/yard +9 -1
- data/bin/yardoc +9 -1
- data/bin/yri +10 -2
- data/docs/CodeObjects.md +10 -10
- data/docs/GettingStarted.md +85 -83
- data/docs/Handlers.md +21 -21
- data/docs/Overview.md +7 -7
- data/docs/Parser.md +30 -30
- data/docs/Tags.md +250 -554
- data/docs/TagsArch.md +123 -0
- data/docs/Templates.md +58 -80
- data/docs/WhatsNew.md +378 -133
- data/docs/templates/default/fulldoc/html/full_list_tag.erb +7 -0
- data/docs/templates/default/fulldoc/html/setup.rb +6 -0
- data/docs/templates/default/layout/html/setup.rb +8 -0
- data/docs/templates/default/layout/html/tag_list.erb +11 -0
- data/docs/templates/default/yard_tags/html/list.erb +18 -0
- data/docs/templates/default/yard_tags/html/setup.rb +27 -0
- data/docs/templates/plugin.rb +65 -0
- data/lib/yard.rb +1 -10
- data/lib/yard/autoload.rb +75 -27
- data/lib/yard/cli/command.rb +5 -2
- data/lib/yard/cli/command_parser.rb +3 -2
- data/lib/yard/cli/diff.rb +1 -1
- data/lib/yard/cli/i18n.rb +69 -0
- data/lib/yard/cli/list.rb +1 -1
- data/lib/yard/cli/server.rb +30 -7
- data/lib/yard/cli/stats.rb +5 -6
- data/lib/yard/cli/yardoc.rb +95 -45
- data/lib/yard/cli/yri.rb +24 -3
- data/lib/yard/code_objects/base.rb +35 -4
- data/lib/yard/code_objects/extra_file_object.rb +1 -1
- data/lib/yard/code_objects/macro_object.rb +56 -99
- data/lib/yard/code_objects/method_object.rb +44 -6
- data/lib/yard/config.rb +18 -8
- data/lib/yard/core_ext/symbol_hash.rb +1 -1
- data/lib/yard/docstring.rb +45 -85
- data/lib/yard/docstring_parser.rb +269 -0
- data/lib/yard/handlers/base.rb +129 -118
- data/lib/yard/handlers/c/alias_handler.rb +15 -0
- data/lib/yard/handlers/c/attribute_handler.rb +13 -0
- data/lib/yard/handlers/c/base.rb +110 -0
- data/lib/yard/handlers/c/class_handler.rb +26 -0
- data/lib/yard/handlers/c/constant_handler.rb +12 -0
- data/lib/yard/handlers/c/handler_methods.rb +165 -0
- data/lib/yard/handlers/c/init_handler.rb +16 -0
- data/lib/yard/handlers/c/method_handler.rb +35 -0
- data/lib/yard/handlers/c/mixin_handler.rb +13 -0
- data/lib/yard/handlers/c/module_handler.rb +16 -0
- data/lib/yard/handlers/c/override_comment_handler.rb +22 -0
- data/lib/yard/handlers/c/path_handler.rb +10 -0
- data/lib/yard/handlers/c/struct_handler.rb +12 -0
- data/lib/yard/handlers/c/symbol_handler.rb +7 -0
- data/lib/yard/handlers/processor.rb +41 -30
- data/lib/yard/handlers/ruby/alias_handler.rb +0 -2
- data/lib/yard/handlers/ruby/attribute_handler.rb +16 -17
- data/lib/yard/handlers/ruby/base.rb +10 -6
- data/lib/yard/handlers/ruby/comment_handler.rb +9 -0
- data/lib/yard/handlers/ruby/dsl_handler.rb +14 -0
- data/lib/yard/handlers/ruby/dsl_handler_methods.rb +71 -0
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +0 -3
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +16 -17
- data/lib/yard/handlers/ruby/legacy/base.rb +28 -6
- data/lib/yard/handlers/ruby/legacy/comment_handler.rb +9 -0
- data/lib/yard/handlers/ruby/legacy/dsl_handler.rb +16 -0
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +0 -2
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +1 -1
- data/lib/yard/handlers/ruby/legacy/module_function_handler.rb +18 -0
- data/lib/yard/handlers/ruby/method_handler.rb +10 -15
- data/lib/yard/handlers/ruby/mixin_handler.rb +1 -1
- data/lib/yard/handlers/ruby/module_function_handler.rb +26 -0
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -2
- data/lib/yard/i18n/pot_generator.rb +281 -0
- data/lib/yard/i18n/text.rb +72 -0
- data/lib/yard/logging.rb +3 -7
- data/lib/yard/options.rb +216 -0
- data/lib/yard/parser/c/c_parser.rb +225 -0
- data/lib/yard/parser/c/comment_parser.rb +131 -0
- data/lib/yard/parser/c/statement.rb +63 -0
- data/lib/yard/parser/ruby/ast_node.rb +91 -1
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
- data/lib/yard/parser/ruby/legacy/statement.rb +7 -2
- data/lib/yard/parser/ruby/legacy/statement_list.rb +13 -22
- data/lib/yard/parser/ruby/ruby_parser.rb +87 -26
- data/lib/yard/parser/source_parser.rb +89 -88
- data/lib/yard/rake/yardoc_task.rb +1 -1
- data/lib/yard/registry.rb +21 -10
- data/lib/yard/registry_store.rb +48 -0
- data/lib/yard/serializers/file_system_serializer.rb +18 -20
- data/lib/yard/serializers/yardoc_serializer.rb +1 -0
- data/lib/yard/server/adapter.rb +2 -2
- data/lib/yard/server/commands/base.rb +1 -1
- data/lib/yard/server/commands/display_object_command.rb +13 -6
- data/lib/yard/server/commands/frames_command.rb +4 -21
- data/lib/yard/server/commands/library_command.rb +57 -11
- data/lib/yard/server/commands/list_command.rb +10 -34
- data/lib/yard/server/commands/search_command.rb +8 -2
- data/lib/yard/server/doc_server_helper.rb +34 -0
- data/lib/yard/server/rack_adapter.rb +5 -1
- data/lib/yard/server/router.rb +4 -10
- data/lib/yard/server/static_caching.rb +2 -2
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +2 -2
- data/lib/yard/server/templates/default/fulldoc/html/js/live.js +0 -15
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +3 -3
- data/lib/yard/server/templates/default/layout/html/script_setup.erb +8 -0
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
- data/lib/yard/server/templates/doc_server/search/html/setup.rb +1 -1
- data/lib/yard/tags/default_factory.rb +31 -4
- data/lib/yard/tags/directives.rb +593 -0
- data/lib/yard/tags/library.rb +437 -35
- data/lib/yard/templates/engine.rb +17 -12
- data/lib/yard/templates/helpers/base_helper.rb +8 -2
- data/lib/yard/templates/helpers/html_helper.rb +57 -14
- data/lib/yard/templates/helpers/markup/rdoc_markup.rb +1 -1
- data/lib/yard/templates/helpers/markup_helper.rb +9 -9
- data/lib/yard/templates/helpers/text_helper.rb +2 -2
- data/lib/yard/templates/template.rb +42 -13
- data/lib/yard/templates/template_options.rb +81 -0
- data/spec/cli/command_parser_spec.rb +4 -4
- data/spec/cli/command_spec.rb +3 -3
- data/spec/cli/config_spec.rb +13 -13
- data/spec/cli/diff_spec.rb +13 -10
- data/spec/cli/gems_spec.rb +12 -12
- data/spec/cli/help_spec.rb +2 -2
- data/spec/cli/i18n_spec.rb +111 -0
- data/spec/cli/server_spec.rb +66 -18
- data/spec/cli/stats_spec.rb +15 -15
- data/spec/cli/yardoc_spec.rb +124 -97
- data/spec/cli/yri_spec.rb +14 -12
- data/spec/code_objects/base_spec.rb +104 -46
- data/spec/code_objects/class_object_spec.rb +33 -33
- data/spec/code_objects/code_object_list_spec.rb +5 -5
- data/spec/code_objects/constants_spec.rb +4 -3
- data/spec/code_objects/extra_file_object_spec.rb +19 -19
- data/spec/code_objects/macro_object_spec.rb +31 -37
- data/spec/code_objects/method_object_spec.rb +46 -23
- data/spec/code_objects/module_object_spec.rb +16 -16
- data/spec/code_objects/namespace_object_spec.rb +6 -6
- data/spec/code_objects/proxy_spec.rb +19 -19
- data/spec/config_spec.rb +33 -24
- data/spec/core_ext/array_spec.rb +1 -1
- data/spec/core_ext/file_spec.rb +8 -8
- data/spec/core_ext/hash_spec.rb +1 -1
- data/spec/core_ext/insertion_spec.rb +3 -3
- data/spec/core_ext/module_spec.rb +1 -1
- data/spec/core_ext/string_spec.rb +6 -6
- data/spec/core_ext/symbol_hash_spec.rb +11 -11
- data/spec/docstring_parser_spec.rb +207 -0
- data/spec/docstring_spec.rb +33 -146
- data/spec/handlers/alias_handler_spec.rb +14 -14
- data/spec/handlers/attribute_handler_spec.rb +20 -20
- data/spec/handlers/base_spec.rb +16 -16
- data/spec/handlers/c/alias_handler_spec.rb +33 -0
- data/spec/handlers/c/attribute_handler_spec.rb +40 -0
- data/spec/handlers/c/class_handler_spec.rb +64 -0
- data/spec/handlers/c/constant_handler_spec.rb +68 -0
- data/spec/handlers/c/init_handler_spec.rb +36 -0
- data/spec/handlers/c/method_handler_spec.rb +228 -0
- data/spec/handlers/c/mixin_handler_spec.rb +27 -0
- data/spec/handlers/c/module_handler_spec.rb +38 -0
- data/spec/handlers/c/override_comment_handler_spec.rb +43 -0
- data/spec/handlers/c/path_handler_spec.rb +35 -0
- data/spec/handlers/c/spec_helper.rb +11 -0
- data/spec/handlers/c/struct_handler_spec.rb +15 -0
- data/spec/handlers/class_condition_handler_spec.rb +10 -10
- data/spec/handlers/class_handler_spec.rb +38 -38
- data/spec/handlers/class_variable_handler_spec.rb +1 -1
- data/spec/handlers/constant_handler_spec.rb +7 -7
- data/spec/handlers/{macro_handler_spec.rb → dsl_handler_spec.rb} +72 -53
- data/spec/handlers/examples/alias_handler_001.rb.txt +5 -5
- data/spec/handlers/examples/class_condition_handler_001.rb.txt +9 -9
- data/spec/handlers/examples/class_handler_001.rb.txt +1 -1
- data/spec/handlers/examples/dsl_handler_001.rb.txt +110 -0
- data/spec/handlers/examples/exception_handler_001.rb.txt +14 -14
- data/spec/handlers/examples/method_condition_handler_001.rb.txt +2 -2
- data/spec/handlers/examples/method_handler_001.rb.txt +16 -16
- data/spec/handlers/examples/mixin_handler_001.rb.txt +8 -4
- data/spec/handlers/examples/private_constant_handler_001.rb.txt +1 -1
- data/spec/handlers/examples/visibility_handler_001.rb.txt +3 -3
- data/spec/handlers/examples/yield_handler_001.rb.txt +13 -14
- data/spec/handlers/exception_handler_spec.rb +9 -9
- data/spec/handlers/extend_handler_spec.rb +2 -2
- data/spec/handlers/legacy_base_spec.rb +34 -34
- data/spec/handlers/method_condition_handler_spec.rb +2 -2
- data/spec/handlers/method_handler_spec.rb +33 -33
- data/spec/handlers/mixin_handler_spec.rb +13 -9
- data/spec/handlers/module_function_handler_spec.rb +82 -0
- data/spec/handlers/module_handler_spec.rb +6 -6
- data/spec/handlers/private_constant_handler_spec.rb +3 -3
- data/spec/handlers/processor_spec.rb +5 -5
- data/spec/handlers/ruby/base_spec.rb +10 -6
- data/spec/handlers/ruby/legacy/base_spec.rb +11 -7
- data/spec/handlers/spec_helper.rb +2 -3
- data/spec/handlers/visibility_handler_spec.rb +6 -6
- data/spec/handlers/yield_handler_spec.rb +8 -8
- data/spec/i18n/pot_generator_spec.rb +244 -0
- data/spec/i18n/text_spec.rb +69 -0
- data/spec/options_spec.rb +160 -0
- data/spec/parser/base_spec.rb +3 -3
- data/spec/parser/c_parser_spec.rb +31 -257
- data/spec/parser/examples/array.c.txt +187 -187
- data/spec/parser/examples/extrafile.c.txt +1 -1
- data/spec/parser/examples/override.c.txt +1 -1
- data/spec/parser/ruby/ast_node_spec.rb +1 -1
- data/spec/parser/ruby/legacy/statement_list_spec.rb +24 -24
- data/spec/parser/ruby/legacy/token_list_spec.rb +7 -7
- data/spec/parser/ruby/ruby_parser_spec.rb +56 -34
- data/spec/parser/source_parser_spec.rb +125 -65
- data/spec/parser/tag_parsing_spec.rb +4 -4
- data/spec/rake/yardoc_task_spec.rb +10 -8
- data/spec/registry_spec.rb +65 -36
- data/spec/registry_store_spec.rb +90 -40
- data/spec/serializers/file_system_serializer_spec.rb +12 -12
- data/spec/serializers/yardoc_serializer_spec.rb +2 -2
- data/spec/server/adapter_spec.rb +3 -3
- data/spec/server/commands/base_spec.rb +8 -8
- data/spec/server/commands/library_command_spec.rb +3 -3
- data/spec/server/commands/static_file_command_spec.rb +7 -7
- data/spec/server/doc_server_helper_spec.rb +1 -1
- data/spec/server/doc_server_serializer_spec.rb +6 -6
- data/spec/server/rack_adapter_spec.rb +3 -3
- data/spec/server/router_spec.rb +19 -19
- data/spec/server/static_caching_spec.rb +4 -4
- data/spec/spec_helper.rb +7 -7
- data/spec/tags/default_factory_spec.rb +24 -16
- data/spec/tags/directives_spec.rb +422 -0
- data/spec/tags/library_spec.rb +15 -4
- data/spec/tags/overload_tag_spec.rb +6 -6
- data/spec/tags/ref_tag_list_spec.rb +8 -8
- data/spec/templates/class_spec.rb +7 -7
- data/spec/templates/constant_spec.rb +7 -7
- data/spec/templates/engine_spec.rb +28 -36
- data/spec/templates/examples/class001.html +108 -108
- data/spec/templates/examples/class002.html +17 -17
- data/spec/templates/examples/constant001.txt +1 -1
- data/spec/templates/examples/method001.html +45 -45
- data/spec/templates/examples/method002.html +25 -25
- data/spec/templates/examples/method003.html +60 -60
- data/spec/templates/examples/method004.html +7 -7
- data/spec/templates/examples/method005.html +28 -28
- data/spec/templates/examples/module001.html +321 -321
- data/spec/templates/examples/module001.txt +1 -1
- data/spec/templates/examples/module002.html +130 -130
- data/spec/templates/examples/module003.html +74 -74
- data/spec/templates/examples/module004.html +388 -0
- data/spec/templates/helpers/base_helper_spec.rb +32 -32
- data/spec/templates/helpers/html_helper_spec.rb +87 -68
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +9 -9
- data/spec/templates/helpers/markup/rdoc_markup_spec.rb +16 -16
- data/spec/templates/helpers/markup_helper_spec.rb +31 -28
- data/spec/templates/helpers/method_helper_spec.rb +7 -7
- data/spec/templates/helpers/shared_signature_examples.rb +9 -7
- data/spec/templates/helpers/text_helper_spec.rb +3 -3
- data/spec/templates/method_spec.rb +13 -13
- data/spec/templates/module_spec.rb +70 -24
- data/spec/templates/onefile_spec.rb +32 -15
- data/spec/templates/section_spec.rb +23 -23
- data/spec/templates/spec_helper.rb +31 -1
- data/spec/templates/tag_spec.rb +5 -5
- data/spec/templates/template_spec.rb +54 -46
- data/spec/verifier_spec.rb +5 -5
- data/templates/default/class/setup.rb +2 -2
- data/templates/default/docstring/html/abstract.erb +1 -1
- data/templates/default/docstring/html/note.erb +1 -1
- data/templates/default/docstring/html/private.erb +1 -1
- data/templates/default/docstring/html/todo.erb +1 -1
- data/templates/default/docstring/setup.rb +2 -2
- data/templates/default/fulldoc/html/css/full_list.css +4 -2
- data/templates/default/fulldoc/html/css/style.css +50 -44
- data/templates/default/fulldoc/html/frames.erb +21 -6
- data/templates/default/fulldoc/html/full_list.erb +5 -3
- data/templates/default/fulldoc/html/{full_list_files.erb → full_list_file.erb} +0 -0
- data/templates/default/fulldoc/html/js/app.js +29 -26
- data/templates/default/fulldoc/html/js/full_list.js +9 -9
- data/templates/default/fulldoc/html/js/jquery.js +4 -16
- data/templates/default/fulldoc/html/setup.rb +42 -38
- data/templates/default/layout/dot/header.erb +1 -1
- data/templates/default/layout/html/breadcrumb.erb +6 -6
- data/templates/default/layout/html/files.erb +1 -1
- data/templates/default/layout/html/footer.erb +1 -1
- data/templates/default/layout/html/headers.erb +3 -6
- data/templates/default/layout/html/index.erb +1 -1
- data/templates/default/layout/html/layout.erb +3 -7
- data/templates/default/layout/html/objects.erb +1 -1
- data/templates/default/layout/html/script_setup.erb +5 -0
- data/templates/default/layout/html/search.erb +4 -1
- data/templates/default/layout/html/setup.rb +8 -8
- data/templates/default/method_details/html/method_signature.erb +10 -3
- data/templates/default/method_details/setup.rb +1 -0
- data/templates/default/module/dot/info.erb +1 -1
- data/templates/default/module/dot/setup.rb +2 -2
- data/templates/default/module/html/attribute_details.erb +1 -1
- data/templates/default/module/html/children.erb +1 -1
- data/templates/default/module/html/defines.erb +1 -1
- data/templates/default/module/html/inherited_methods.erb +5 -4
- data/templates/default/module/html/item_summary.erb +15 -5
- data/templates/default/module/html/method_details_list.erb +2 -2
- data/templates/default/module/setup.rb +25 -12
- data/templates/default/module/text/setup.rb +1 -1
- data/templates/default/onefile/html/layout.erb +1 -1
- data/templates/default/onefile/html/setup.rb +2 -2
- data/templates/default/tags/html/example.erb +4 -2
- data/templates/default/tags/html/option.erb +1 -1
- data/templates/default/tags/html/overload.erb +1 -1
- data/templates/default/tags/html/see.erb +1 -1
- data/templates/default/tags/html/tag.erb +1 -1
- data/templates/default/tags/setup.rb +4 -3
- data/templates/guide/fulldoc/html/css/style.css +8 -8
- data/templates/guide/fulldoc/html/js/app.js +6 -6
- data/templates/guide/fulldoc/html/setup.rb +12 -12
- data/templates/guide/layout/html/layout.erb +11 -11
- data/templates/guide/layout/html/setup.rb +9 -9
- data/templates/guide/method/html/header.erb +2 -2
- data/templates/guide/method/html/setup.rb +1 -1
- metadata +68 -18
- data/bin/yard-graph +0 -4
- data/bin/yard-server +0 -4
- data/docs/Glossary.md +0 -12
- data/lib/yard/handlers/ruby/legacy/macro_handler.rb +0 -39
- data/lib/yard/handlers/ruby/macro_handler.rb +0 -40
- data/lib/yard/handlers/ruby/macro_handler_methods.rb +0 -131
- data/lib/yard/parser/c_parser.rb +0 -497
- data/lib/yard/server/templates/default/layout/html/headers.erb +0 -16
- data/lib/yard/server/templates/doc_server/frames/html/frames.erb +0 -13
- data/lib/yard/server/templates/doc_server/frames/html/setup.rb +0 -3
- data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +0 -34
- data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +0 -20
- data/spec/handlers/examples/macro_handler_001.rb.txt +0 -83
@@ -0,0 +1,160 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::Options do
|
4
|
+
class FooOptions < YARD::Options
|
5
|
+
attr_accessor :foo
|
6
|
+
def initialize; self.foo = "abc" end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '.default_attr' do
|
10
|
+
it "should allow default attributes to be defined with symbols" do
|
11
|
+
class DefaultOptions1 < YARD::Options
|
12
|
+
default_attr :foo, 'HELLO'
|
13
|
+
end
|
14
|
+
o = DefaultOptions1.new
|
15
|
+
o.reset_defaults
|
16
|
+
o.foo.should == 'HELLO'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should call lambda if value is a Proc" do
|
20
|
+
class DefaultOptions2 < YARD::Options
|
21
|
+
default_attr :foo, lambda { 100 }
|
22
|
+
end
|
23
|
+
o = DefaultOptions2.new
|
24
|
+
o.reset_defaults
|
25
|
+
o.foo.should == 100
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#reset_defaults' do
|
30
|
+
it "should not define defaults until reset is called" do
|
31
|
+
class ResetDefaultOptions1 < YARD::Options
|
32
|
+
default_attr :foo, 'FOO'
|
33
|
+
end
|
34
|
+
ResetDefaultOptions1.new.foo.should be_nil
|
35
|
+
o = ResetDefaultOptions1.new
|
36
|
+
o.reset_defaults
|
37
|
+
o.foo.should == 'FOO'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#delete' do
|
42
|
+
it "should delete an option" do
|
43
|
+
o = FooOptions.new
|
44
|
+
o.delete(:foo)
|
45
|
+
o.to_hash.should == {}
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not error if an option is deleted that does not exist" do
|
49
|
+
o = FooOptions.new
|
50
|
+
o.delete(:foo)
|
51
|
+
o.delete(:foo)
|
52
|
+
o.to_hash.should == {}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#[]' do
|
57
|
+
it "should handle getting option values using hash syntax" do
|
58
|
+
FooOptions.new[:foo].should == "abc"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#[]=' do
|
63
|
+
it "should handle setting options using hash syntax" do
|
64
|
+
o = FooOptions.new
|
65
|
+
o[:foo] = "xyz"
|
66
|
+
o[:foo].should == "xyz"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should allow setting of unregistered keys" do
|
70
|
+
o = FooOptions.new
|
71
|
+
o[:bar] = "foo"
|
72
|
+
o[:bar].should == "foo"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#method_missing' do
|
77
|
+
it "should allow setting of unregistered keys" do
|
78
|
+
o = FooOptions.new
|
79
|
+
o.bar = 'foo'
|
80
|
+
o.bar.should == 'foo'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should allow getting values of unregistered keys (return nil)" do
|
84
|
+
FooOptions.new.bar.should be_nil
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should print debugging messages about unregistered keys" do
|
88
|
+
log.should_receive(:debug).with("Attempting to access unregistered key bar on FooOptions")
|
89
|
+
FooOptions.new.bar
|
90
|
+
log.should_receive(:debug).with("Attempting to set unregistered key bar on FooOptions")
|
91
|
+
FooOptions.new.bar = 1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#update' do
|
96
|
+
it "should allow updating of options" do
|
97
|
+
FooOptions.new.update(:foo => "xyz").foo.should == "xyz"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not ignore keys with no setter (OpenStruct behaviour)" do
|
101
|
+
o = FooOptions.new
|
102
|
+
o.update(:bar => "xyz")
|
103
|
+
o.to_hash.should == {:foo => "abc", :bar => "xyz"}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#merge' do
|
108
|
+
it "should update a new object" do
|
109
|
+
o = FooOptions.new
|
110
|
+
o.merge(:foo => "xyz").object_id.should_not == o.object_id
|
111
|
+
o.merge(:foo => "xyz").to_hash.should == {:foo => "xyz"}
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should add in values from original object" do
|
115
|
+
o = FooOptions.new
|
116
|
+
o.update(:bar => "foo")
|
117
|
+
o.merge(:baz => 1).to_hash.should == {:foo => "abc", :bar => "foo", :baz => 1}
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#to_hash' do
|
122
|
+
it "should convert all instance variables and symbolized keys" do
|
123
|
+
class ToHashOptions1 < YARD::Options
|
124
|
+
attr_accessor :foo, :bar, :baz
|
125
|
+
def initialize; @foo = 1; @bar = 2; @baz = "hello" end
|
126
|
+
end
|
127
|
+
o = ToHashOptions1.new
|
128
|
+
hash = o.to_hash
|
129
|
+
hash.keys.should include(:foo, :bar, :baz)
|
130
|
+
hash[:foo].should == 1
|
131
|
+
hash[:bar].should == 2
|
132
|
+
hash[:baz].should == "hello"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should use accessor when converting values to hash" do
|
136
|
+
class ToHashOptions2 < YARD::Options
|
137
|
+
def initialize; @foo = 1 end
|
138
|
+
def foo; "HELLO#{@foo}" end
|
139
|
+
end
|
140
|
+
o = ToHashOptions2.new
|
141
|
+
o.to_hash.should == {:foo => "HELLO1"}
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should ignore ivars with no accessor" do
|
145
|
+
class ToHashOptions3 < YARD::Options
|
146
|
+
attr_accessor :foo
|
147
|
+
def initialize; @foo = 1; @bar = "NOIGNORE" end
|
148
|
+
end
|
149
|
+
o = ToHashOptions3.new
|
150
|
+
o.to_hash.should == {:foo => 1, :bar => "NOIGNORE"}
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#tap' do
|
155
|
+
it "should support #tap(&block) (even in 1.8.6)" do
|
156
|
+
o = FooOptions.new.tap {|o| o.foo = :BAR }
|
157
|
+
o.to_hash.should == {:foo => :BAR}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
data/spec/parser/base_spec.rb
CHANGED
@@ -3,12 +3,12 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
|
3
3
|
describe YARD::Parser::Base do
|
4
4
|
describe '#initialize' do
|
5
5
|
class MyParser < Parser::Base; def initialize(a, b) end end
|
6
|
-
|
6
|
+
|
7
7
|
it "should take 2 arguments" do
|
8
|
-
lambda { YARD::Parser::Base.new }.should raise_error(ArgumentError,
|
8
|
+
lambda { YARD::Parser::Base.new }.should raise_error(ArgumentError,
|
9
9
|
/wrong (number|#) of arguments|given 0, expected 2/)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it "should raise NotImplementedError on #initialize" do
|
13
13
|
lambda { YARD::Parser::Base.new('a', 'b') }.should raise_error(NotImplementedError)
|
14
14
|
end
|
@@ -1,25 +1,16 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
-
begin require 'continuation'; rescue LoadError; end unless RUBY18
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
describe YARD::Parser::CParser do
|
3
|
+
describe YARD::Parser::C::CParser do
|
7
4
|
describe '#parse' do
|
8
|
-
def parse(
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def parse_init(src = @contents)
|
14
|
-
YARD::Registry.clear
|
15
|
-
Parser::CParser.new("void Init_Foo() {\n#{src}\n}").parse
|
5
|
+
def parse(contents)
|
6
|
+
Registry.clear
|
7
|
+
YARD.parse_string(contents, :c)
|
16
8
|
end
|
17
9
|
|
18
10
|
describe 'Array class' do
|
19
11
|
before(:all) do
|
20
12
|
file = File.join(File.dirname(__FILE__), 'examples', 'array.c.txt')
|
21
|
-
|
22
|
-
@parser.parse
|
13
|
+
parse(File.read(file))
|
23
14
|
end
|
24
15
|
|
25
16
|
it "should parse Array class" do
|
@@ -34,292 +25,75 @@ describe YARD::Parser::CParser do
|
|
34
25
|
obj.tags(:overload).size.should > 1
|
35
26
|
end
|
36
27
|
end
|
37
|
-
|
28
|
+
|
38
29
|
describe 'Source located in extra files' do
|
39
30
|
before(:all) do
|
40
31
|
@multifile = File.join(File.dirname(__FILE__), 'examples', 'multifile.c.txt')
|
41
32
|
@extrafile = File.join(File.dirname(__FILE__), 'examples', 'extrafile.c.txt')
|
42
33
|
@contents = File.read(@multifile)
|
43
34
|
end
|
44
|
-
|
35
|
+
|
45
36
|
it "should look for methods in extra files (if 'in' comment is found)" do
|
46
37
|
extra_contents = File.read(@extrafile)
|
47
38
|
File.should_receive(:read).with('extra.c').and_return(extra_contents)
|
48
|
-
parse
|
39
|
+
parse(@contents)
|
49
40
|
Registry.at('Multifile#extra').docstring.should == 'foo'
|
50
41
|
end
|
51
42
|
|
52
43
|
it "should stop searching for extra source file gracefully if file is not found" do
|
53
44
|
File.should_receive(:read).with('extra.c').and_raise(Errno::ENOENT)
|
54
45
|
log.should_receive(:warn).with("Missing source file `extra.c' when parsing Multifile#extra")
|
55
|
-
parse
|
46
|
+
parse(@contents)
|
56
47
|
Registry.at('Multifile#extra').docstring.should == ''
|
57
48
|
end
|
58
49
|
end
|
59
|
-
|
50
|
+
|
60
51
|
describe 'Foo class' do
|
61
52
|
it 'should not include comments in docstring source' do
|
62
|
-
|
63
|
-
/*
|
53
|
+
parse <<-eof
|
54
|
+
/*
|
64
55
|
* Hello world
|
65
56
|
*/
|
66
57
|
VALUE foo(VALUE x) {
|
67
58
|
int value = x;
|
68
59
|
}
|
69
|
-
|
60
|
+
|
70
61
|
void Init_Foo() {
|
71
62
|
rb_define_method(rb_cFoo, "foo", foo, 1);
|
72
63
|
}
|
73
64
|
eof
|
74
|
-
|
75
|
-
Registry.at('Foo#foo').source.gsub(/\s\s+/, ' ').should ==
|
65
|
+
Registry.at('Foo#foo').source.gsub(/\s\s+/, ' ').should ==
|
76
66
|
"VALUE foo(VALUE x) { int value = x;\n}"
|
77
67
|
end
|
78
68
|
end
|
79
|
-
|
80
|
-
describe 'Handling namespace parsing' do
|
81
|
-
it 'should track variable names defined under namespaces' do
|
82
|
-
@contents = <<-eof
|
83
|
-
void Init_Foo(void) {
|
84
|
-
mFoo = rb_define_module("Foo");
|
85
|
-
cBar = rb_define_class_under(mFoo, "Bar", rb_cObject);
|
86
|
-
rb_define_method(cBar, "foo", foo, 1);
|
87
|
-
}
|
88
|
-
eof
|
89
|
-
parse
|
90
|
-
Registry.at('Foo::Bar').should_not be_nil
|
91
|
-
Registry.at('Foo::Bar#foo').should_not be_nil
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should track variable names defined under namespaces' do
|
95
|
-
@contents = <<-eof
|
96
|
-
void Init_Foo(void) {
|
97
|
-
mFoo = rb_define_module("Foo");
|
98
|
-
cBar = rb_define_class_under(mFoo, "Bar", rb_cObject);
|
99
|
-
mBaz = rb_define_module_under(cBar, "Baz");
|
100
|
-
rb_define_method(mBaz, "foo", foo, 1);
|
101
|
-
}
|
102
|
-
eof
|
103
|
-
parse
|
104
|
-
Registry.at('Foo::Bar::Baz').should_not be_nil
|
105
|
-
Registry.at('Foo::Bar::Baz#foo').should_not be_nil
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should handle rb_path2class() calls" do
|
109
|
-
@contents = <<-eof
|
110
|
-
void Init_Foo(void) {
|
111
|
-
somePath = rb_path2class("Foo::Bar::Baz")
|
112
|
-
mFoo = rb_define_module("Foo");
|
113
|
-
cBar = rb_define_class_under(mFoo, "Bar", rb_cObject);
|
114
|
-
mBaz = rb_define_module_under(cBar, "Baz");
|
115
|
-
rb_define_method(somePath, "foo", foo, 1);
|
116
|
-
}
|
117
|
-
eof
|
118
|
-
parse
|
119
|
-
Registry.at('Foo::Bar::Baz#foo').should_not be_nil
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe 'Defining methods with source in other files' do
|
124
|
-
it "should look in another file for method" do
|
125
|
-
File.should_receive(:read).at_least(1).times.with('file.c').and_return(<<-eof)
|
126
|
-
/* FOO
|
127
|
-
*/
|
128
|
-
VALUE foo(VALUE x)
|
129
|
-
{ }
|
130
|
-
|
131
|
-
/* BAR
|
132
|
-
*/
|
133
|
-
VALUE bar(VALUE x)
|
134
|
-
{ }
|
135
|
-
eof
|
136
|
-
@contents = <<-eof
|
137
|
-
void Init_Foo() {
|
138
|
-
rb_define_method(rb_cFoo, "foo", foo, 1); /* in file.c */
|
139
|
-
rb_define_global_function("bar", bar, 1); /* in file.c */
|
140
|
-
}
|
141
|
-
eof
|
142
|
-
parse
|
143
|
-
Registry.at('Foo#foo').docstring.should == 'FOO'
|
144
|
-
Registry.at('Kernel#bar').docstring.should == 'BAR'
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should allow extra file to include /'s and other filename characters" do
|
148
|
-
File.should_receive(:read).at_least(1).times.with('ext/a-file.c').and_return(<<-eof)
|
149
|
-
/* FOO
|
150
|
-
*/
|
151
|
-
VALUE foo(VALUE x) {
|
152
|
-
int value = x;
|
153
|
-
}
|
154
|
-
|
155
|
-
/* BAR
|
156
|
-
*/
|
157
|
-
VALUE bar(VALUE x) {
|
158
|
-
int value = x;
|
159
|
-
}
|
160
|
-
eof
|
161
|
-
@contents = <<-eof
|
162
|
-
void Init_Foo() {
|
163
|
-
rb_define_method(rb_cFoo, "foo", foo, 1); /* in ext/a-file.c */
|
164
|
-
rb_define_global_function("bar", bar, 1); /* in ext/a-file.c */
|
165
|
-
}
|
166
|
-
eof
|
167
|
-
parse
|
168
|
-
Registry.at('Foo#foo').docstring.should == 'FOO'
|
169
|
-
Registry.at('Kernel#bar').docstring.should == 'BAR'
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
describe 'Defining attributes' do
|
174
|
-
before do
|
175
|
-
Registry.clear
|
176
|
-
end
|
177
|
-
|
178
|
-
def run(read, write, commented = nil)
|
179
|
-
@contents = <<-eof
|
180
|
-
/* FOO */
|
181
|
-
VALUE foo(VALUE x) { int value = x; }
|
182
|
-
void Init_Foo() {
|
183
|
-
rb_cFoo = rb_define_class("Foo", rb_cObject);
|
184
|
-
#{commented ? '/*' : ''}
|
185
|
-
rb_define_attr(rb_cFoo, "foo", #{read}, #{write});
|
186
|
-
#{commented ? '*/' : ''}
|
187
|
-
}
|
188
|
-
eof
|
189
|
-
parse
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should handle readonly attribute (rb_define_attr)" do
|
193
|
-
run(1, 0)
|
194
|
-
Registry.at('Foo#foo').should be_reader
|
195
|
-
Registry.at('Foo#foo=').should be_nil
|
196
|
-
end
|
197
69
|
|
198
|
-
|
199
|
-
|
200
|
-
Registry.at('Foo#foo').should be_nil
|
201
|
-
Registry.at('Foo#foo=').should be_writer
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should handle readwrite attribute (rb_define_attr)" do
|
205
|
-
run(1, 1)
|
206
|
-
Registry.at('Foo#foo').should be_reader
|
207
|
-
Registry.at('Foo#foo=').should be_writer
|
208
|
-
end
|
209
|
-
|
210
|
-
it "should handle commented writeonly attribute (/* rb_define_attr */)" do
|
211
|
-
run(1, 1, true)
|
212
|
-
Registry.at('Foo#foo').should be_reader
|
213
|
-
Registry.at('Foo#foo=').should be_writer
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
describe 'Defining constants' do
|
218
|
-
it "should register constants" do
|
219
|
-
parse_init <<-eof
|
220
|
-
mFoo = rb_define_module("Foo");
|
221
|
-
rb_define_const(mFoo, "FOO", ID2SYM(100));
|
222
|
-
eof
|
223
|
-
Registry.at('Foo::FOO').type.should == :constant
|
224
|
-
end
|
225
|
-
|
226
|
-
it "should look for override comments" do
|
70
|
+
describe 'Constant' do
|
71
|
+
it 'should not truncate docstring' do
|
227
72
|
parse <<-eof
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
73
|
+
#define MSK_DEADBEEF 0xdeadbeef
|
74
|
+
void
|
75
|
+
Init_Mask(void)
|
76
|
+
{
|
77
|
+
rb_cMask = rb_define_class("Mask", rb_cObject);
|
78
|
+
/* 0xdeadbeef: This constant is frequently used to indicate a
|
79
|
+
* software crash or deadlock in embedded systems. */
|
80
|
+
rb_define_const(rb_cMask, "DEADBEEF", INT2FIX(MSK_DEADBEEF));
|
235
81
|
}
|
236
82
|
eof
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
foo.value.should == 'ID2SYM(100)'
|
241
|
-
foo.file.should == '(stdin)'
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should use comment attached to declaration as fallback" do
|
245
|
-
parse_init <<-eof
|
246
|
-
mFoo = rb_define_module("Foo");
|
247
|
-
/* foobar! */
|
248
|
-
rb_define_const(mFoo, "FOO", ID2SYM(100));
|
249
|
-
eof
|
250
|
-
foo = Registry.at('Foo::FOO')
|
251
|
-
foo.value.should == 'ID2SYM(100)'
|
252
|
-
foo.docstring.should == 'foobar!'
|
253
|
-
end
|
254
|
-
|
255
|
-
it "should allow the form VALUE: DOCSTRING to document value" do
|
256
|
-
parse_init <<-eof
|
257
|
-
mFoo = rb_define_module("Foo");
|
258
|
-
/* 100: foobar! */
|
259
|
-
rb_define_const(mFoo, "FOO", ID2SYM(100));
|
260
|
-
eof
|
261
|
-
foo = Registry.at('Foo::FOO')
|
262
|
-
foo.value.should == '100'
|
263
|
-
foo.docstring.should == 'foobar!'
|
264
|
-
end
|
265
|
-
|
266
|
-
it "should allow escaping of backslashes in VALUE: DOCSTRING syntax" do
|
267
|
-
parse_init <<-eof
|
268
|
-
mFoo = rb_define_module("Foo");
|
269
|
-
/* 100\\:x\\:y: foobar:x! */
|
270
|
-
rb_define_const(mFoo, "FOO", ID2SYM(100));
|
271
|
-
eof
|
272
|
-
foo = Registry.at('Foo::FOO')
|
273
|
-
foo.value.should == '100:x:y'
|
274
|
-
foo.docstring.should == 'foobar:x!'
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
describe 'Defining aliases' do
|
279
|
-
before do
|
280
|
-
Registry.clear
|
281
|
-
end
|
282
|
-
|
283
|
-
it "should allow defining of aliases (rb_define_alias)" do
|
284
|
-
@contents = <<-eof
|
285
|
-
/* FOO */
|
286
|
-
VALUE foo(VALUE x) { int value = x; }
|
287
|
-
void Init_Foo() {
|
288
|
-
rb_cFoo = rb_define_class("Foo", rb_cObject);
|
289
|
-
rb_define_method(rb_cFoo, "foo", foo, 1);
|
290
|
-
rb_define_alias(rb_cFoo, "bar", "foo");
|
291
|
-
}
|
292
|
-
eof
|
293
|
-
parse
|
294
|
-
|
295
|
-
Registry.at('Foo#bar').should be_is_alias
|
296
|
-
Registry.at('Foo#bar').docstring.should == 'FOO'
|
297
|
-
end
|
298
|
-
|
299
|
-
it "should allow defining of aliases (rb_define_alias) of attributes" do
|
300
|
-
@contents = <<-eof
|
301
|
-
/* FOO */
|
302
|
-
VALUE foo(VALUE x) { int value = x; }
|
303
|
-
void Init_Foo() {
|
304
|
-
rb_cFoo = rb_define_class("Foo", rb_cObject);
|
305
|
-
rb_define_attr(rb_cFoo, "foo", 1, 0);
|
306
|
-
rb_define_alias(rb_cFoo, "foo?", "foo");
|
307
|
-
}
|
308
|
-
eof
|
309
|
-
parse
|
310
|
-
|
311
|
-
Registry.at('Foo#foo').should be_reader
|
312
|
-
Registry.at('Foo#foo?').should be_is_alias
|
83
|
+
constant = Registry.at('Mask::DEADBEEF')
|
84
|
+
constant.value.should == '0xdeadbeef'
|
85
|
+
constant.docstring.should == "This constant is frequently used to indicate a\nsoftware crash or deadlock in embedded systems."
|
313
86
|
end
|
314
87
|
end
|
315
88
|
end
|
316
89
|
|
317
|
-
describe '
|
90
|
+
describe 'Override comments' do
|
318
91
|
before(:all) do
|
92
|
+
Registry.clear
|
319
93
|
override_file = File.join(File.dirname(__FILE__), 'examples', 'override.c.txt')
|
320
|
-
@override_parser =
|
94
|
+
@override_parser = YARD.parse_string(File.read(override_file), :c)
|
321
95
|
end
|
322
|
-
|
96
|
+
|
323
97
|
it "should parse GMP::Z class" do
|
324
98
|
z = YARD::Registry.at('GMP::Z')
|
325
99
|
z.should_not be_nil
|