yard 0.2.1 → 0.2.2
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/{LICENSE.txt → LICENSE} +1 -1
- data/README +211 -0
- data/Rakefile +31 -0
- data/benchmarks/builtins_vs_eval.rb +23 -0
- data/benchmarks/erb_vs_erubis.rb +53 -0
- data/benchmarks/generation.rb +37 -0
- data/benchmarks/parsing.rb +33 -0
- data/bin/view_generator +17 -0
- data/bin/yard-graph +4 -0
- data/bin/yardoc +1 -93
- data/bin/yri +12 -3
- data/lib/yard.rb +10 -5
- data/lib/yard/autoload.rb +116 -0
- data/lib/yard/cli/yard_graph.rb +86 -0
- data/lib/yard/cli/yardoc.rb +131 -0
- data/lib/yard/code_objects/base.rb +321 -0
- data/lib/yard/code_objects/class_object.rb +89 -0
- data/lib/yard/code_objects/class_variable_object.rb +4 -0
- data/lib/yard/code_objects/constant_object.rb +4 -0
- data/lib/yard/code_objects/method_object.rb +51 -0
- data/lib/yard/code_objects/module_object.rb +4 -0
- data/lib/yard/code_objects/namespace_object.rb +88 -0
- data/lib/yard/code_objects/proxy.rb +183 -0
- data/lib/yard/code_objects/root_object.rb +8 -0
- data/lib/yard/core_ext/file.rb +26 -0
- data/lib/yard/core_ext/logger.rb +5 -0
- data/lib/yard/core_ext/module.rb +9 -0
- data/lib/yard/core_ext/string.rb +13 -0
- data/lib/yard/core_ext/symbol_hash.rb +24 -0
- data/lib/yard/generators/attributes_generator.rb +22 -0
- data/lib/yard/generators/base.rb +285 -0
- data/lib/yard/generators/class_generator.rb +25 -0
- data/lib/yard/generators/constants_generator.rb +73 -0
- data/lib/yard/generators/constructor_generator.rb +25 -0
- data/lib/yard/generators/deprecated_generator.rb +15 -0
- data/lib/yard/generators/docstring_generator.rb +15 -0
- data/lib/yard/generators/full_doc_generator.rb +59 -0
- data/lib/yard/generators/helpers/base_helper.rb +52 -0
- data/lib/yard/generators/helpers/filter_helper.rb +21 -0
- data/lib/yard/generators/helpers/html_helper.rb +137 -0
- data/lib/yard/generators/helpers/method_helper.rb +27 -0
- data/lib/yard/generators/helpers/uml_helper.rb +16 -0
- data/lib/yard/generators/inheritance_generator.rb +16 -0
- data/lib/yard/generators/method_details_generator.rb +18 -0
- data/lib/yard/generators/method_generator.rb +31 -0
- data/lib/yard/generators/method_listing_generator.rb +105 -0
- data/lib/yard/generators/method_missing_generator.rb +25 -0
- data/lib/yard/generators/method_signature_generator.rb +19 -0
- data/lib/yard/generators/method_summary_generator.rb +21 -0
- data/lib/yard/generators/mixins_generator.rb +15 -0
- data/lib/yard/generators/module_generator.rb +22 -0
- data/lib/yard/generators/quick_doc_generator.rb +31 -0
- data/lib/yard/generators/source_generator.rb +26 -0
- data/lib/yard/generators/tags_generator.rb +50 -0
- data/lib/yard/generators/uml_generator.rb +92 -0
- data/lib/yard/generators/visibility_group_generator.rb +26 -0
- data/lib/yard/handlers/alias_handler.rb +32 -0
- data/lib/yard/handlers/attribute_handler.rb +54 -0
- data/lib/yard/handlers/base.rb +509 -0
- data/lib/yard/handlers/class_handler.rb +44 -0
- data/lib/yard/handlers/class_variable_handler.rb +13 -0
- data/lib/yard/handlers/constant_handler.rb +13 -0
- data/lib/yard/handlers/exception_handler.rb +12 -0
- data/lib/yard/handlers/method_handler.rb +27 -0
- data/lib/yard/handlers/mixin_handler.rb +16 -0
- data/lib/yard/handlers/module_handler.rb +9 -0
- data/lib/yard/handlers/visibility_handler.rb +14 -0
- data/lib/yard/handlers/yield_handler.rb +26 -0
- data/lib/yard/logging.rb +27 -0
- data/lib/yard/parser/ruby_lex.rb +1344 -0
- data/lib/yard/parser/source_parser.rb +109 -0
- data/lib/yard/parser/statement.rb +36 -0
- data/lib/yard/parser/statement_list.rb +167 -0
- data/lib/yard/parser/token_list.rb +58 -0
- data/lib/yard/rake/yardoc_task.rb +30 -0
- data/lib/yard/registry.rb +136 -0
- data/lib/yard/serializers/base.rb +16 -0
- data/lib/yard/serializers/file_system_serializer.rb +48 -0
- data/lib/yard/serializers/process_serializer.rb +14 -0
- data/lib/yard/serializers/stdout_serializer.rb +21 -0
- data/lib/yard/tags/default_factory.rb +98 -0
- data/lib/yard/tags/library.rb +109 -0
- data/lib/yard/tags/merbdoc_factory.rb +47 -0
- data/lib/yard/tags/tag.rb +35 -0
- data/spec/code_objects/base_spec.rb +219 -0
- data/spec/code_objects/class_object_spec.rb +176 -0
- data/spec/code_objects/code_object_list_spec.rb +33 -0
- data/spec/code_objects/constants_spec.rb +79 -0
- data/spec/code_objects/method_object_spec.rb +30 -0
- data/spec/code_objects/module_object_spec.rb +73 -0
- data/spec/code_objects/namespace_object_spec.rb +129 -0
- data/spec/code_objects/proxy_spec.rb +80 -0
- data/spec/code_objects/spec_helper.rb +3 -0
- data/spec/core_ext/file_spec.rb +20 -0
- data/spec/core_ext/string_spec.rb +4 -0
- data/spec/core_ext/symbol_hash_spec.rb +80 -0
- data/spec/generators/base_spec.rb +64 -0
- data/spec/generators/helpers/base_helper_spec.rb +15 -0
- data/spec/generators/helpers/html_helper_spec.rb +56 -0
- data/spec/generators/quick_doc_generator_spec.rb +13 -0
- data/spec/handlers/alias_handler_spec.rb +50 -0
- data/spec/handlers/attribute_handler_spec.rb +78 -0
- data/spec/handlers/base_spec.rb +165 -0
- data/spec/handlers/class_handler_spec.rb +68 -0
- data/spec/handlers/class_variable_handler_spec.rb +9 -0
- data/spec/handlers/constant_handler_spec.rb +13 -0
- data/spec/handlers/examples/alias_handler_001.rb.txt +24 -0
- data/spec/handlers/examples/attribute_handler_001.rb.txt +19 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +39 -0
- data/spec/handlers/examples/class_variable_handler_001.rb.txt +9 -0
- data/spec/handlers/examples/constant_handler_001.rb.txt +10 -0
- data/spec/handlers/examples/exception_handler_001.rb.txt +42 -0
- data/spec/handlers/examples/method_handler_001.rb.txt +35 -0
- data/spec/handlers/examples/mixin_handler_001.rb.txt +12 -0
- data/spec/handlers/examples/module_handler_001.rb.txt +16 -0
- data/spec/handlers/examples/visibility_handler_001.rb.txt +20 -0
- data/spec/handlers/examples/yield_handler_001.rb.txt +55 -0
- data/spec/handlers/exception_handler_spec.rb +35 -0
- data/spec/handlers/method_handler_spec.rb +35 -0
- data/spec/handlers/mixin_handler_spec.rb +30 -0
- data/spec/handlers/module_handler_spec.rb +25 -0
- data/spec/handlers/spec_helper.rb +21 -0
- data/spec/handlers/visibility_handler_spec.rb +24 -0
- data/spec/handlers/yield_handler_spec.rb +51 -0
- data/spec/parser/examples/example1.rb.txt +8 -0
- data/spec/parser/examples/tag_handler_001.rb.txt +8 -0
- data/spec/parser/source_parser_spec.rb +43 -0
- data/spec/parser/tag_parsing_spec.rb +18 -0
- data/spec/parser/token_list_spec.rb +35 -0
- data/spec/registry_spec.rb +70 -0
- data/spec/serializers/file_system_serializer_spec.rb +91 -0
- data/spec/serializers/spec_helper.rb +2 -0
- data/spec/spec_helper.rb +77 -0
- data/templates/default/attributes/html/header.erb +35 -0
- data/templates/default/attributes/text/header.erb +10 -0
- data/templates/default/class/html/header.erb +4 -0
- data/templates/default/constants/html/constants.erb +9 -0
- data/templates/default/constants/html/header.erb +3 -0
- data/templates/default/constants/html/included.erb +9 -0
- data/templates/default/constants/html/inherited.erb +9 -0
- data/templates/default/constructor/html/header.erb +10 -0
- data/templates/default/deprecated/html/main.erb +4 -0
- data/templates/default/deprecated/text/main.erb +3 -0
- data/templates/default/docstring/html/main.erb +3 -0
- data/templates/default/docstring/text/main.erb +3 -0
- data/templates/default/fulldoc/html/all_methods.erb +25 -0
- data/templates/default/fulldoc/html/all_namespaces.erb +19 -0
- data/templates/default/fulldoc/html/app.js +18 -0
- data/templates/default/fulldoc/html/header.erb +15 -0
- data/templates/default/fulldoc/html/html_head.erb +3 -0
- data/templates/default/fulldoc/html/index.erb +18 -0
- data/templates/default/fulldoc/html/jquery.js +11 -0
- data/templates/default/fulldoc/html/readme.erb +15 -0
- data/templates/default/fulldoc/html/style.css +65 -0
- data/templates/default/fulldoc/html/syntax_highlight.css +21 -0
- data/templates/default/inheritance/html/header.erb +8 -0
- data/templates/default/inheritance/text/header.erb +3 -0
- data/templates/default/method/html/aliases.erb +6 -0
- data/templates/default/method/html/header.erb +3 -0
- data/templates/default/method/html/title.erb +3 -0
- data/templates/default/methoddetails/html/header.erb +8 -0
- data/templates/default/methoddetails/html/method_header.erb +3 -0
- data/templates/default/methodmissing/html/header.erb +12 -0
- data/templates/default/methodsignature/html/main.erb +8 -0
- data/templates/default/methodsignature/text/main.erb +5 -0
- data/templates/default/methodsummary/html/header.erb +5 -0
- data/templates/default/methodsummary/html/included.erb +9 -0
- data/templates/default/methodsummary/html/inherited.erb +9 -0
- data/templates/default/methodsummary/html/summary.erb +25 -0
- data/templates/default/methodsummary/text/header.erb +5 -0
- data/templates/default/methodsummary/text/included.erb +0 -0
- data/templates/default/methodsummary/text/inherited.erb +0 -0
- data/templates/default/methodsummary/text/summary.erb +3 -0
- data/templates/default/mixins/html/header.erb +4 -0
- data/templates/default/module/html/header.erb +4 -0
- data/templates/default/quickdoc/html/header.erb +15 -0
- data/templates/default/quickdoc/text/header.erb +12 -0
- data/templates/default/source/html/main.erb +15 -0
- data/templates/default/source/text/main.erb +4 -0
- data/templates/default/tags/html/header.erb +4 -0
- data/templates/default/tags/html/see.erb +13 -0
- data/templates/default/tags/html/tags.erb +20 -0
- data/templates/default/tags/text/header.erb +3 -0
- data/templates/default/tags/text/see.erb +5 -0
- data/templates/default/tags/text/tags.erb +7 -0
- data/templates/default/uml/dot/child.erb +1 -0
- data/templates/default/uml/dot/dependencies.erb +10 -0
- data/templates/default/uml/dot/header.erb +6 -0
- data/templates/default/uml/dot/info.erb +14 -0
- data/templates/default/uml/dot/subgraph.erb +6 -0
- data/templates/default/uml/dot/superclasses.erb +9 -0
- data/templates/default/uml/dot/unknown.erb +3 -0
- data/templates/default/uml/dot/unknown_child.erb +1 -0
- data/templates/default/visibilitygroup/html/header.erb +6 -0
- data/templates/javadoc/attributes/html/header.erb +16 -0
- data/templates/javadoc/class/html/header.erb +4 -0
- data/templates/javadoc/constants/html/constants.erb +9 -0
- data/templates/javadoc/constants/html/header.erb +3 -0
- data/templates/javadoc/constants/html/included.erb +12 -0
- data/templates/javadoc/constants/html/inherited.erb +12 -0
- data/templates/javadoc/constructor/html/header.erb +10 -0
- data/templates/javadoc/deprecated/html/main.erb +0 -0
- data/templates/javadoc/docstring/html/main.erb +6 -0
- data/templates/javadoc/fulldoc/html/all_methods.erb +25 -0
- data/templates/javadoc/fulldoc/html/all_namespaces.erb +19 -0
- data/templates/javadoc/fulldoc/html/app.js +18 -0
- data/templates/javadoc/fulldoc/html/header.erb +15 -0
- data/templates/javadoc/fulldoc/html/html_head.erb +3 -0
- data/templates/javadoc/fulldoc/html/index.erb +18 -0
- data/templates/javadoc/fulldoc/html/jquery.js +11 -0
- data/templates/javadoc/fulldoc/html/readme.erb +15 -0
- data/templates/javadoc/fulldoc/html/style.css +22 -0
- data/templates/javadoc/fulldoc/html/syntax_highlight.css +21 -0
- data/templates/javadoc/inheritance/html/header.erb +6 -0
- data/templates/javadoc/method/html/aliases.erb +6 -0
- data/templates/javadoc/method/html/header.erb +4 -0
- data/templates/javadoc/method/html/title.erb +4 -0
- data/templates/javadoc/methoddetails/html/header.erb +8 -0
- data/templates/javadoc/methoddetails/html/method_header.erb +0 -0
- data/templates/javadoc/methodmissing/html/header.erb +12 -0
- data/templates/javadoc/methodsignature/html/main.erb +8 -0
- data/templates/javadoc/methodsummary/html/header.erb +5 -0
- data/templates/javadoc/methodsummary/html/included.erb +12 -0
- data/templates/javadoc/methodsummary/html/inherited.erb +12 -0
- data/templates/javadoc/methodsummary/html/summary.erb +25 -0
- data/templates/javadoc/mixins/html/header.erb +5 -0
- data/templates/javadoc/module/html/header.erb +4 -0
- data/templates/javadoc/source/html/main.erb +15 -0
- data/templates/javadoc/tags/html/header.erb +5 -0
- data/templates/javadoc/tags/html/see.erb +8 -0
- data/templates/javadoc/tags/html/tags.erb +19 -0
- data/templates/javadoc/visibilitygroup/html/header.erb +5 -0
- metadata +352 -50
- data/README.pdf +0 -0
- data/lib/code_object.rb +0 -337
- data/lib/extra.rb +0 -8
- data/lib/formatter.rb +0 -90
- data/lib/handlers/all_handlers.rb +0 -2
- data/lib/handlers/attribute_handler.rb +0 -51
- data/lib/handlers/class_handler.rb +0 -30
- data/lib/handlers/class_variable_handler.rb +0 -9
- data/lib/handlers/code_object_handler.rb +0 -104
- data/lib/handlers/constant_handler.rb +0 -11
- data/lib/handlers/exception_handler.rb +0 -20
- data/lib/handlers/method_handler.rb +0 -28
- data/lib/handlers/mixin_handler.rb +0 -15
- data/lib/handlers/module_handler.rb +0 -9
- data/lib/handlers/visibility_handler.rb +0 -7
- data/lib/handlers/yield_handler.rb +0 -33
- data/lib/logger.rb +0 -19
- data/lib/namespace.rb +0 -98
- data/lib/quick_doc.rb +0 -104
- data/lib/ruby_lex.rb +0 -1321
- data/lib/source_parser.rb +0 -253
- data/lib/tag_library.rb +0 -175
- data/lib/tag_type.rb +0 -155
- data/templates/default/html/_fulldoc.erb +0 -64
- data/templates/default/html/class.erb +0 -226
- data/templates/default/html/method.erb +0 -20
- data/templates/default/html/module.erb +0 -126
- data/test/fixtures/docstring.txt +0 -23
- data/test/fixtures/docstring2.txt +0 -4
- data/test/test_code_object.rb +0 -66
- data/test/test_namespace.rb +0 -10
@@ -0,0 +1,165 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
include Parser
|
4
|
+
|
5
|
+
describe YARD::Handlers::Base, "#handles and inheritance" do
|
6
|
+
before do
|
7
|
+
Handlers::Base.stub!(:inherited)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should keep track of subclasses" do
|
11
|
+
Handlers::Base.should_receive(:inherited).once
|
12
|
+
class TestHandler < Handlers::Base; end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should handle a string input" do
|
16
|
+
class TestStringHandler < Handlers::Base
|
17
|
+
handles "hello"
|
18
|
+
end
|
19
|
+
|
20
|
+
TestStringHandler.handles?(TokenList.new("hello world")).should == true
|
21
|
+
TestStringHandler.handles?(TokenList.new("nothello world")).should == false
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should handle regex input" do
|
25
|
+
class TestRegexHandler < Handlers::Base
|
26
|
+
handles /^nothello$/
|
27
|
+
end
|
28
|
+
|
29
|
+
TestRegexHandler.handles?(TokenList.new("nothello")).should == true
|
30
|
+
TestRegexHandler.handles?(TokenList.new("not hello hello")).should == false
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should handle token input" do
|
34
|
+
class TestTokenHandler < Handlers::Base
|
35
|
+
handles TkMODULE
|
36
|
+
end
|
37
|
+
|
38
|
+
TestTokenHandler.handles?(TokenList.new("module")).should == true
|
39
|
+
TestTokenHandler.handles?(TokenList.new("if")).should == false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should raise NotImplementedError if process is called on a class with no #process" do
|
43
|
+
class TestNotImplementedHandler < Handlers::Base
|
44
|
+
handles TkMODULE
|
45
|
+
end
|
46
|
+
|
47
|
+
lambda { TestNotImplementedHandler.new(0, 0).process }.should raise_error(NotImplementedError)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe YARD::Handlers::Base, "#tokval" do
|
52
|
+
include RubyToken
|
53
|
+
|
54
|
+
before { @handler = Handlers::Base.new(nil, nil) }
|
55
|
+
|
56
|
+
def tokval(code, *types)
|
57
|
+
@handler.send(:tokval, TokenList.new(code).first, *types)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return the String's value without quotes" do
|
61
|
+
tokval('"hello"').should == "hello"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not allow interpolated strings with TkSTRING" do
|
65
|
+
tokval('"#{c}"', RubyToken::TkSTRING).should be_nil
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should return a Symbol's value as a String (as if it was done via :name.to_sym)" do
|
69
|
+
tokval(':sym').should == :sym
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return nil for any non accepted type" do
|
73
|
+
tokval('identifier').should be_nil
|
74
|
+
tokval(':sym', RubyToken::TkId).should be_nil
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should accept TkVal tokens by default" do
|
78
|
+
tokval('2.5').should == 2.5
|
79
|
+
tokval(':sym').should == :sym
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should accept any ID type if TkId is set" do
|
83
|
+
tokval('variable', RubyToken::TkId).should == "variable"
|
84
|
+
tokval('CONSTANT', RubyToken::TkId).should == "CONSTANT"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should allow extra token types to be accepted" do
|
88
|
+
tokval('2.5', RubyToken::TkFLOAT).should == 2.5
|
89
|
+
tokval('2', RubyToken::TkFLOAT).should be_nil
|
90
|
+
tokval(':symbol', RubyToken::TkFLOAT).should be_nil
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should allow :string for any string type" do
|
94
|
+
tokval('"hello"', :string).should == "hello"
|
95
|
+
tokval('"#{c}"', :string).should == '#{c}'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should not include interpolated strings when using :attr" do
|
99
|
+
tokval('"#{c}"', :attr).should be_nil
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should allow any number type with :number" do
|
103
|
+
tokval('2.5', :number).should == 2.5
|
104
|
+
tokval('2', :number).should == 2
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should should allow method names with :identifier" do
|
108
|
+
tokval('methodname?', :identifier).should == "methodname?"
|
109
|
+
end
|
110
|
+
|
111
|
+
#it "should obey documentation expectations" do docspec end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe YARD::Handlers::Base, "#tokval_list" do
|
115
|
+
before { @handler = Handlers::Base.new(nil, nil) }
|
116
|
+
|
117
|
+
def tokval_list(code, *types)
|
118
|
+
@handler.send(:tokval_list, TokenList.new(code), *types)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should return the list of tokvalues" do
|
122
|
+
tokval_list(":a, :b, \"\#{c}\", 'd'", :attr).should == [:a, :b, 'd']
|
123
|
+
tokval_list(":a, :b, File.read(\"\#{c}\", ['w']), :d", RubyToken::Token).should == [:a, :b, 'File.read("#{c}", [\'w\'])', :d]
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should try to skip any invalid tokens" do
|
127
|
+
tokval_list(":a, :b, \"\#{c}\", :d", :attr).should == [:a, :b, :d]
|
128
|
+
tokval_list(":a, :b, File.read(\"\#{c}\", 'w', File.open { }), :d", :attr).should == [:a, :b, :d]
|
129
|
+
tokval_list("CONST1, identifier, File.read(\"\#{c}\", 'w', File.open { }), CONST2", RubyToken::TkId).should == ['CONST1', 'identifier', 'CONST2']
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should ignore a token if another invalid token is read before a comma" do
|
133
|
+
tokval_list(":a, :b XYZ, :c", RubyToken::TkSYMBOL).should == [:a, :c]
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should stop on most keywords" do
|
137
|
+
tokval_list(':a rescue :x == 5', RubyToken::Token).should == [:a]
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should handle ignore parentheses that begin the token list" do
|
141
|
+
tokval_list('(:a, :b, :c)', :attr).should == [:a, :b, :c]
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should end when a closing parenthesis was found" do
|
145
|
+
tokval_list(':a, :b, :c), :d', :attr).should == [:a, :b, :c]
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should ignore parentheses around items in a list" do
|
149
|
+
tokval_list(':a, (:b), :c, (:d TEST), :e, [:f], :g', :attr).should == [:a, :b, :c, :e, :g]
|
150
|
+
tokval_list(':a, (((:f)))', :attr).should == [:a, :f]
|
151
|
+
tokval_list(':a, ([:f]), :c)', RubyToken::Token).should == [:a, '[:f]', :c]
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should not stop on a true/false/self keyword (cannot handle nil)" do
|
155
|
+
tokval_list(':a, true, :b, self, false, :c, nil, File, super, if, XYZ', RubyToken::Token).should == [:a, true, :b, 'self', false, :c, 'File', 'super']
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should ignore invalid commas" do
|
159
|
+
tokval_list(":a, :b, , :d").should == [:a, :b, :d]
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should return an empty list if no matches were found" do
|
163
|
+
tokval_list('attr_accessor :x').should == []
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::Handlers::ClassHandler do
|
4
|
+
before { parse_file :class_handler_001, __FILE__ }
|
5
|
+
|
6
|
+
it "should parse a class block with docstring" do
|
7
|
+
P("A").docstring.should == "Docstring"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should handle complex class names" do
|
11
|
+
P("A::B::C").should_not == nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should handle the subclassing syntax" do
|
15
|
+
P("A::B::C").superclass.should == P(:String)
|
16
|
+
P("A::X").superclass.should == Registry.at("A::B::C")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should interpret class << self as a class level block" do
|
20
|
+
P("A::classmethod1").should_not == nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should interpret class << ClassName as a class level block in ClassName's namespace" do
|
24
|
+
P("A::B::C::Hello").should be_instance_of(CodeObjects::MethodObject)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should make visibility public when parsing a block" do
|
28
|
+
P("A::B::C#method1").visibility.should == :public
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set superclass type to :class if it is a Proxy" do
|
32
|
+
P("A::B::C").superclass.type.should == :class
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should look for a superclass before creating the class if it shares the same name" do
|
36
|
+
P('B::A').superclass.should == P('A')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should raise an UndocumentableError if the class is invalid" do
|
40
|
+
["CallMethod('test')", "VSD^#}}", 'not.aclass', 'self'].each do |klass|
|
41
|
+
undoc_error "class #{klass}; end"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should handle superclass as a constant-style method (camping style < R /path/)" do
|
46
|
+
P('Test1').superclass.should == P(:R)
|
47
|
+
P('Test2').superclass.should == P(:R)
|
48
|
+
P('Test6').superclass.should == P(:NotDelegateClass)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should handle superclass with OStruct.new or Struct.new syntax (superclass should be OStruct/Struct)" do
|
52
|
+
P('Test3').superclass.should == P(:Struct)
|
53
|
+
P('Test4').superclass.should == P(:OStruct)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should handle DelegateClass(CLASSNAME) superclass syntax" do
|
57
|
+
P('Test5').superclass.should == P(:Array)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should raise an UndocumentableError if the superclass is invalid but it should create the class." do
|
61
|
+
["VSD^#}}", 'not.aclass', 'self', 'AnotherClass.new'].each do |klass|
|
62
|
+
Registry.clear
|
63
|
+
undoc_error "class A < #{klass}; end"
|
64
|
+
Registry.at('A').should_not be_nil
|
65
|
+
Registry.at('A').superclass.should == P(:Object)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::Handlers::ClassVariableHandler do
|
4
|
+
before { parse_file :class_variable_handler_001, __FILE__ }
|
5
|
+
|
6
|
+
it "should not parse class variables inside methods" do
|
7
|
+
Registry.at("A::B::@@somevar").source.should == "@@somevar = \"hello\""
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::Handlers::ConstantHandler do
|
4
|
+
before { parse_file :constant_handler_001, __FILE__ }
|
5
|
+
|
6
|
+
it "should not parse constants inside methods" do
|
7
|
+
Registry.at("A::B::SOMECONSTANT").source.should == "SOMECONSTANT= \"hello\""
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should only parse valid constants" do
|
11
|
+
Registry.at("A::B::notaconstant").should be_nil
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module A
|
2
|
+
def a; end
|
3
|
+
alias_method :b, :a
|
4
|
+
|
5
|
+
# Handle keyword syntax too
|
6
|
+
alias :c :a
|
7
|
+
alias d? a
|
8
|
+
alias [] a
|
9
|
+
alias []= a
|
10
|
+
alias @- a
|
11
|
+
alias % a
|
12
|
+
alias * a
|
13
|
+
end
|
14
|
+
|
15
|
+
class C
|
16
|
+
def x; end
|
17
|
+
end
|
18
|
+
|
19
|
+
class B < C
|
20
|
+
alias_method(:q, :x)
|
21
|
+
alias_method :r?, :x
|
22
|
+
alias_method :s, :to_s
|
23
|
+
alias_method :t, :inspect if 500 = 3 * CONSTANT
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module A
|
2
|
+
attr_writer :x
|
3
|
+
end
|
4
|
+
|
5
|
+
class B
|
6
|
+
class << self
|
7
|
+
attr_accessor :z
|
8
|
+
end
|
9
|
+
|
10
|
+
attr :a, true
|
11
|
+
attr :a2, false
|
12
|
+
attr :a3
|
13
|
+
# Docstring
|
14
|
+
attr_reader :b, :c, :d
|
15
|
+
attr_writer :e
|
16
|
+
attr_accessor 'f'
|
17
|
+
|
18
|
+
attr_accessor :z
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Docstring
|
2
|
+
class A
|
3
|
+
module B; end
|
4
|
+
private
|
5
|
+
class B::C < String;
|
6
|
+
def method1; end
|
7
|
+
def method2; end
|
8
|
+
end
|
9
|
+
class X<B::C
|
10
|
+
end
|
11
|
+
class<<self
|
12
|
+
def classmethod1; end
|
13
|
+
end
|
14
|
+
|
15
|
+
class << A::B::C; def Hello; end end
|
16
|
+
end
|
17
|
+
|
18
|
+
module B
|
19
|
+
class A < A
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Test1 < R "something"
|
24
|
+
end
|
25
|
+
|
26
|
+
class Test2 < R(/something/)
|
27
|
+
end
|
28
|
+
|
29
|
+
class Test3 < Struct.new(:foo, :bar)
|
30
|
+
end
|
31
|
+
|
32
|
+
class Test4 < OStruct.new
|
33
|
+
end
|
34
|
+
|
35
|
+
class Test5 < DelegateClass(Array)
|
36
|
+
end
|
37
|
+
|
38
|
+
class Test6 < NotDelegateClass(Array)
|
39
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Testing
|
2
|
+
# Ignore yields outside methods
|
3
|
+
raise NoMethodError, "reason"
|
4
|
+
|
5
|
+
# Should document this
|
6
|
+
def mymethod
|
7
|
+
raise ArgumentError, "Argument is missing"
|
8
|
+
end
|
9
|
+
|
10
|
+
# Don't document this
|
11
|
+
def mymethod2
|
12
|
+
raise(a)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Don't document this (docstring takes precedence)
|
16
|
+
# @raise [A]
|
17
|
+
def mymethod3
|
18
|
+
raise SomethingElse
|
19
|
+
end
|
20
|
+
|
21
|
+
# Only document the first one (limitation of exc handler)
|
22
|
+
def mymethod4
|
23
|
+
raise(A)
|
24
|
+
raise B, "Argument", somethingelse
|
25
|
+
end
|
26
|
+
|
27
|
+
def mymethod5
|
28
|
+
raise YARD::Handlers::UndocumentableError
|
29
|
+
end
|
30
|
+
|
31
|
+
def mymethod6
|
32
|
+
raise YARD::Handlers.constants("test")
|
33
|
+
end
|
34
|
+
|
35
|
+
def mymethod7
|
36
|
+
raise MethodCall('argument')
|
37
|
+
end
|
38
|
+
|
39
|
+
def mymethod8
|
40
|
+
raise ExceptionClass.new('blah')
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Foo
|
2
|
+
def ==(other)
|
3
|
+
'hello'
|
4
|
+
end
|
5
|
+
def /(other) 'hi' end
|
6
|
+
|
7
|
+
attr_reader :method1
|
8
|
+
|
9
|
+
def method1
|
10
|
+
def dynamic; end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.method2; end
|
14
|
+
|
15
|
+
# Docstring
|
16
|
+
def String :: hello; "" end
|
17
|
+
|
18
|
+
def [](key) puts key end
|
19
|
+
def []=(key, value) end
|
20
|
+
def
|
21
|
+
allowed?
|
22
|
+
end
|
23
|
+
|
24
|
+
def ` param; end
|
25
|
+
def /(x) end
|
26
|
+
def |; end; def =~ ()
|
27
|
+
def -@; end;
|
28
|
+
end
|
29
|
+
def *(o) def +@; end
|
30
|
+
def ~@
|
31
|
+
end end
|
32
|
+
def &(o) end
|
33
|
+
def %(o) end
|
34
|
+
def ^(o) end
|
35
|
+
end
|