yard 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- data/LICENSE +1 -1
- data/README.markdown +200 -0
- data/Rakefile +6 -1
- data/benchmarks/format_args.rb +46 -0
- data/benchmarks/parsing.rb +13 -1
- data/benchmarks/rdoc_vs_yardoc.rb +10 -0
- data/benchmarks/ripper_parser.rb +12 -0
- data/docs/CODE_OBJECTS.markdown +121 -0
- data/docs/FAQ.markdown +34 -0
- data/docs/GENERATORS.markdown +211 -0
- data/docs/GETTING_STARTED.markdown +263 -0
- data/docs/GLOSSARY.markdown +13 -0
- data/docs/HANDLERS.markdown +158 -0
- data/docs/OVERVIEW.markdown +64 -0
- data/docs/PARSER.markdown +180 -0
- data/docs/TAGS.markdown +181 -0
- data/docs/WHATSNEW.markdown +96 -0
- data/docs/images/code-objects-class-diagram.png +0 -0
- 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/images/tags-class-diagram.png +0 -0
- data/lib/yard.rb +4 -1
- data/lib/yard/autoload.rb +79 -31
- data/lib/yard/cli/yard_graph.rb +8 -2
- data/lib/yard/cli/yardoc.rb +61 -8
- data/lib/yard/code_objects/base.rb +78 -135
- data/lib/yard/code_objects/class_object.rb +9 -8
- data/lib/yard/code_objects/constant_object.rb +1 -0
- data/lib/yard/code_objects/extended_method_object.rb +9 -0
- data/lib/yard/code_objects/method_object.rb +18 -5
- data/lib/yard/code_objects/module_object.rb +8 -1
- data/lib/yard/code_objects/namespace_object.rb +25 -16
- data/lib/yard/code_objects/proxy.rb +22 -22
- data/lib/yard/core_ext/file.rb +1 -1
- data/lib/yard/core_ext/string.rb +0 -4
- data/lib/yard/core_ext/symbol_hash.rb +3 -2
- data/lib/yard/docstring.rb +180 -0
- data/lib/yard/generators/base.rb +33 -13
- data/lib/yard/generators/class_generator.rb +4 -2
- data/lib/yard/generators/constants_generator.rb +3 -2
- data/lib/yard/generators/full_doc_generator.rb +76 -9
- data/lib/yard/generators/helpers/base_helper.rb +18 -1
- data/lib/yard/generators/helpers/filter_helper.rb +2 -2
- data/lib/yard/generators/helpers/html_helper.rb +94 -39
- data/lib/yard/generators/helpers/html_syntax_highlight_helper.rb +49 -0
- data/lib/yard/generators/helpers/markup_helper.rb +86 -0
- data/lib/yard/generators/helpers/method_helper.rb +23 -7
- data/lib/yard/generators/method_generator.rb +15 -3
- data/lib/yard/generators/method_listing_generator.rb +3 -3
- data/lib/yard/generators/mixins_generator.rb +8 -2
- data/lib/yard/generators/module_generator.rb +3 -2
- data/lib/yard/generators/overloads_generator.rb +20 -0
- data/lib/yard/generators/quick_doc_generator.rb +3 -9
- data/lib/yard/generators/root_generator.rb +32 -0
- data/lib/yard/generators/source_generator.rb +2 -17
- data/lib/yard/generators/tags_generator.rb +34 -6
- data/lib/yard/generators/uml_generator.rb +16 -6
- data/lib/yard/handlers/base.rb +88 -253
- data/lib/yard/handlers/processor.rb +72 -0
- data/lib/yard/handlers/ruby/alias_handler.rb +38 -0
- data/lib/yard/handlers/ruby/attribute_handler.rb +69 -0
- data/lib/yard/handlers/ruby/base.rb +72 -0
- data/lib/yard/handlers/ruby/class_condition_handler.rb +70 -0
- data/lib/yard/handlers/ruby/class_handler.rb +74 -0
- data/lib/yard/handlers/ruby/class_variable_handler.rb +11 -0
- data/lib/yard/handlers/ruby/constant_handler.rb +12 -0
- data/lib/yard/handlers/ruby/exception_handler.rb +22 -0
- data/lib/yard/handlers/ruby/extend_handler.rb +19 -0
- data/lib/yard/handlers/{alias_handler.rb → ruby/legacy/alias_handler.rb} +3 -4
- data/lib/yard/handlers/{attribute_handler.rb → ruby/legacy/attribute_handler.rb} +2 -2
- data/lib/yard/handlers/ruby/legacy/base.rb +198 -0
- data/lib/yard/handlers/{class_handler.rb → ruby/legacy/class_handler.rb} +18 -6
- data/lib/yard/handlers/{class_variable_handler.rb → ruby/legacy/class_variable_handler.rb} +1 -1
- data/lib/yard/handlers/{constant_handler.rb → ruby/legacy/constant_handler.rb} +2 -2
- data/lib/yard/handlers/{exception_handler.rb → ruby/legacy/exception_handler.rb} +3 -3
- data/lib/yard/handlers/ruby/legacy/extend_handler.rb +18 -0
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +31 -0
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +28 -0
- data/lib/yard/handlers/{module_handler.rb → ruby/legacy/module_handler.rb} +1 -1
- data/lib/yard/handlers/{visibility_handler.rb → ruby/legacy/visibility_handler.rb} +1 -1
- data/lib/yard/handlers/{yield_handler.rb → ruby/legacy/yield_handler.rb} +4 -4
- data/lib/yard/handlers/ruby/method_condition_handler.rb +7 -0
- data/lib/yard/handlers/ruby/method_handler.rb +48 -0
- data/lib/yard/handlers/ruby/mixin_handler.rb +25 -0
- data/lib/yard/handlers/ruby/module_handler.rb +9 -0
- data/lib/yard/handlers/ruby/visibility_handler.rb +18 -0
- data/lib/yard/handlers/ruby/yield_handler.rb +28 -0
- data/lib/yard/parser/ruby/ast_node.rb +263 -0
- data/lib/yard/parser/{ruby_lex.rb → ruby/legacy/ruby_lex.rb} +258 -259
- data/lib/yard/parser/{statement.rb → ruby/legacy/statement.rb} +8 -4
- data/lib/yard/parser/ruby/legacy/statement_list.rb +262 -0
- data/lib/yard/parser/{token_list.rb → ruby/legacy/token_list.rb} +1 -1
- data/lib/yard/parser/ruby/ruby_parser.rb +307 -0
- data/lib/yard/parser/source_parser.rb +76 -45
- data/lib/yard/rake/yardoc_task.rb +6 -1
- data/lib/yard/registry.rb +45 -19
- data/lib/yard/serializers/file_system_serializer.rb +8 -3
- data/lib/yard/tags/default_factory.rb +70 -10
- data/lib/yard/tags/default_tag.rb +12 -0
- data/lib/yard/tags/library.rb +65 -26
- data/lib/yard/tags/option_tag.rb +12 -0
- data/lib/yard/tags/overload_tag.rb +62 -0
- data/lib/yard/tags/ref_tag.rb +7 -0
- data/lib/yard/tags/ref_tag_list.rb +27 -0
- data/lib/yard/tags/tag.rb +1 -0
- data/lib/yard/tags/tag_format_error.rb +6 -0
- data/spec/cli/yardoc_spec.rb +43 -0
- data/spec/code_objects/base_spec.rb +56 -68
- data/spec/code_objects/class_object_spec.rb +18 -6
- data/spec/code_objects/constants_spec.rb +2 -0
- data/spec/code_objects/method_object_spec.rb +33 -5
- data/spec/code_objects/module_object_spec.rb +66 -8
- data/spec/code_objects/namespace_object_spec.rb +37 -17
- data/spec/code_objects/proxy_spec.rb +13 -2
- data/spec/core_ext/string_spec.rb +14 -2
- data/spec/core_ext/symbol_hash_spec.rb +9 -3
- data/spec/docstring_spec.rb +139 -0
- data/spec/generators/full_doc_generator_spec.rb +29 -0
- data/spec/generators/helpers/html_helper_spec.rb +74 -0
- data/spec/generators/helpers/markup_helper_spec.rb +95 -0
- data/spec/handlers/alias_handler_spec.rb +16 -3
- data/spec/handlers/attribute_handler_spec.rb +1 -1
- data/spec/handlers/base_spec.rb +15 -141
- data/spec/handlers/class_condition_handler_spec.rb +49 -0
- data/spec/handlers/class_handler_spec.rb +44 -3
- data/spec/handlers/class_variable_handler_spec.rb +1 -1
- data/spec/handlers/constant_handler_spec.rb +1 -1
- data/spec/handlers/examples/alias_handler_001.rb.txt +7 -3
- data/spec/handlers/examples/class_condition_handler_001.rb.txt +61 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +33 -0
- data/spec/handlers/examples/exception_handler_001.rb.txt +1 -1
- data/spec/handlers/examples/extend_handler_001.rb.txt +8 -0
- data/spec/handlers/examples/method_condition_handler_001.rb.txt +10 -0
- data/spec/handlers/examples/method_handler_001.rb.txt +16 -4
- data/spec/handlers/examples/mixin_handler_001.rb.txt +10 -2
- data/spec/handlers/examples/module_handler_001.rb.txt +4 -0
- data/spec/handlers/examples/visibility_handler_001.rb.txt +1 -1
- data/spec/handlers/exception_handler_spec.rb +2 -2
- data/spec/handlers/extend_handler_spec.rb +15 -0
- data/spec/handlers/legacy_base_spec.rb +128 -0
- data/spec/handlers/method_condition_handler_spec.rb +14 -0
- data/spec/handlers/method_handler_spec.rb +38 -5
- data/spec/handlers/mixin_handler_spec.rb +15 -7
- data/spec/handlers/module_handler_spec.rb +5 -1
- data/spec/handlers/processor_spec.rb +19 -0
- data/spec/handlers/ruby/base_spec.rb +90 -0
- data/spec/handlers/ruby/legacy/base_spec.rb +53 -0
- data/spec/handlers/spec_helper.rb +22 -16
- data/spec/handlers/visibility_handler_spec.rb +4 -4
- data/spec/handlers/yield_handler_spec.rb +1 -1
- data/spec/parser/ruby/ast_node_spec.rb +15 -0
- data/spec/parser/ruby/legacy/statement_list_spec.rb +145 -0
- data/spec/parser/{token_list_spec.rb → ruby/legacy/token_list_spec.rb} +4 -4
- data/spec/parser/source_parser_spec.rb +0 -15
- data/spec/rake/yardoc_task_spec.rb +48 -0
- data/spec/registry_spec.rb +28 -2
- data/spec/serializers/file_system_serializer_spec.rb +7 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/tags/default_factory_spec.rb +135 -0
- data/spec/tags/default_tag_spec.rb +11 -0
- data/spec/tags/overload_tag_spec.rb +35 -0
- data/spec/tags/ref_tag_list_spec.rb +53 -0
- data/templates/default/attributes/html/header.erb +17 -5
- data/templates/default/attributes/text/header.erb +1 -1
- data/templates/default/fulldoc/html/all_files.erb +19 -0
- data/templates/default/fulldoc/html/all_methods.erb +8 -7
- data/templates/default/fulldoc/html/all_namespaces.erb +4 -1
- data/templates/default/fulldoc/html/app.js +1 -1
- data/templates/default/fulldoc/html/{readme.erb → file.erb} +2 -2
- data/templates/default/fulldoc/html/header.erb +1 -1
- data/templates/default/fulldoc/html/index.erb +4 -3
- data/templates/default/fulldoc/html/style.css +13 -3
- data/templates/default/fulldoc/html/syntax_highlight.css +8 -5
- data/templates/default/method/text/header.erb +1 -0
- data/templates/default/method/text/title.erb +1 -0
- data/templates/default/methodsignature/html/main.erb +10 -8
- data/templates/default/methodsignature/text/main.erb +4 -1
- data/templates/default/methodsummary/html/summary.erb +8 -4
- data/templates/default/methodsummary/text/summary.erb +4 -1
- data/templates/default/mixins/html/header.erb +3 -3
- data/templates/default/overloads/html/header.erb +8 -0
- data/templates/default/overloads/text/header.erb +8 -0
- data/templates/default/root/html/header.erb +4 -0
- data/templates/default/tags/html/example.erb +20 -0
- data/templates/default/tags/html/option.erb +27 -0
- data/templates/default/tags/html/param.erb +21 -0
- data/templates/default/tags/html/tags.erb +4 -1
- data/templates/default/tags/html/todo.erb +8 -0
- data/templates/default/tags/text/example.erb +14 -0
- data/templates/default/tags/text/header.erb +3 -3
- data/templates/default/tags/text/option.erb +5 -0
- data/templates/default/tags/text/param.erb +9 -0
- data/templates/default/uml/dot/dependencies.erb +1 -1
- data/templates/default/uml/dot/info.erb +1 -1
- data/templates/default/uml/dot/superclasses.erb +2 -2
- data/templates/javadoc/methodsummary/html/summary.erb +2 -2
- data/templates/javadoc/mixins/html/header.erb +3 -3
- metadata +108 -139
- data/README +0 -211
- data/lib/yard/handlers/method_handler.rb +0 -27
- data/lib/yard/handlers/mixin_handler.rb +0 -16
- data/lib/yard/parser/statement_list.rb +0 -167
- data/lib/yard/tags/merbdoc_factory.rb +0 -47
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w|.. spec_helper|)
|
2
|
+
|
3
|
+
class YARD::Generators::FullDocGenerator
|
4
|
+
public :generate_files, :readme_file_exists? # public for test
|
5
|
+
end
|
6
|
+
|
7
|
+
describe YARD::Generators::FullDocGenerator do
|
8
|
+
it "should know about absence of 'readme' file" do
|
9
|
+
generator = Generators::FullDocGenerator.new(:readme => nil)
|
10
|
+
generator.readme_file_exists?.should == false
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should know about existence of 'readme' file" do
|
14
|
+
generator = Generators::FullDocGenerator.new(:readme => __FILE__)
|
15
|
+
generator.readme_file_exists?.should == true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should allow absence of 'readme' file" do
|
19
|
+
serializer = mock('serializer')
|
20
|
+
generator_options = {
|
21
|
+
:format => :html,
|
22
|
+
:serializer => serializer,
|
23
|
+
:readme => nil
|
24
|
+
}
|
25
|
+
generator = Generators::FullDocGenerator.new(generator_options)
|
26
|
+
serializer.should_not_receive(:serialize)
|
27
|
+
lambda { generator.generate_files }.should_not raise_error(Errno::ENOENT)
|
28
|
+
end
|
29
|
+
end
|
@@ -1,9 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
1
3
|
describe YARD::Generators::Helpers::HtmlHelper, "basic HTML methods" do
|
2
4
|
include YARD::Generators::Helpers::HtmlHelper
|
3
5
|
|
4
6
|
it "should use #h to escape HTML" do
|
5
7
|
h('Usage: foo "bar" <baz>').should == "Usage: foo "bar" <baz>"
|
6
8
|
end
|
9
|
+
|
10
|
+
it "should use #fix_typewriter to convert +text+ to <tt>text</tt>" do
|
11
|
+
fix_typewriter("Some +typewriter text+.").should == "Some <tt>typewriter text</tt>."
|
12
|
+
fix_typewriter("Not +typewriter text.").should == "Not +typewriter text."
|
13
|
+
fix_typewriter("Alternating +type writer+ text +here+.").should == "Alternating <tt>type writer</tt> text <tt>here</tt>."
|
14
|
+
fix_typewriter("No ++problem.").should == "No ++problem."
|
15
|
+
fix_typewriter("Math + stuff +is ok+").should == "Math + stuff <tt>is ok</tt>"
|
16
|
+
end
|
7
17
|
end
|
8
18
|
|
9
19
|
describe YARD::Generators::Helpers::HtmlHelper, "#link_object" do
|
@@ -53,4 +63,68 @@ describe YARD::Generators::Helpers::HtmlHelper, '#url_for' do
|
|
53
63
|
meth = CodeObjects::MethodObject.new(yard, :meth)
|
54
64
|
url_for(meth).should == 'YARD.html#meth-instance_method'
|
55
65
|
end
|
66
|
+
|
67
|
+
it "should properly urlencode methods with punctuation in links" do
|
68
|
+
obj = CodeObjects::MethodObject.new(nil, :/)
|
69
|
+
serializer = mock(:serializer)
|
70
|
+
serializer.stub!(:serialized_path).and_return("file.html")
|
71
|
+
stub!(:serializer).and_return(serializer)
|
72
|
+
stub!(:current_object).and_return(obj)
|
73
|
+
url_for(obj).should == "#%2F-instance_method"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe YARD::Generators::Helpers::HtmlHelper, '#anchor_for' do
|
78
|
+
include YARD::Generators::Helpers::HtmlHelper
|
79
|
+
|
80
|
+
it "should not urlencode data when called directly" do
|
81
|
+
obj = CodeObjects::MethodObject.new(nil, :/)
|
82
|
+
anchor_for(obj).should == "/-instance_method"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe YARD::Generators::Helpers::HtmlHelper, '#resolve_links' do
|
87
|
+
include YARD::Generators::Helpers::HtmlHelper
|
88
|
+
|
89
|
+
def parse_link(link)
|
90
|
+
results = {}
|
91
|
+
link =~ /<a (.+?)>(.+?)<\/a>/
|
92
|
+
params, results[:inner_text] = $1, $2
|
93
|
+
params.split(/\s+/).each do |match|
|
94
|
+
key, value = *match.split('=')
|
95
|
+
results[key.to_sym] = value.gsub(/^["'](.+)["']$/, '\1')
|
96
|
+
end
|
97
|
+
results
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should link static files with file: prefix" do
|
101
|
+
stub!(:serializer).and_return Serializers::FileSystemSerializer.new
|
102
|
+
stub!(:current_object).and_return Registry.root
|
103
|
+
|
104
|
+
parse_link(resolve_links("{file:TEST.txt#abc}")).should == {
|
105
|
+
:inner_text => "TEST.txt",
|
106
|
+
:title => "TEST.txt",
|
107
|
+
:href => "TEST.txt.html#abc"
|
108
|
+
}
|
109
|
+
parse_link(resolve_links("{file:TEST.txt title}")).should == {
|
110
|
+
:inner_text => "title",
|
111
|
+
:title => "title",
|
112
|
+
:href => "TEST.txt.html"
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should create regular links with http:// or https:// prefixes" do
|
117
|
+
parse_link(resolve_links("{http://example.com}")).should == {
|
118
|
+
:inner_text => "http://example.com",
|
119
|
+
:target => "_parent",
|
120
|
+
:href => "http://example.com",
|
121
|
+
:title => "http://example.com"
|
122
|
+
}
|
123
|
+
parse_link(resolve_links("{http://example.com title}")).should == {
|
124
|
+
:inner_text => "title",
|
125
|
+
:target => "_parent",
|
126
|
+
:href => "http://example.com",
|
127
|
+
:title => "title"
|
128
|
+
}
|
129
|
+
end
|
56
130
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
module YARD::Generators::Helpers::MarkupHelper
|
4
|
+
public :load_markup_provider, :markup_class, :markup_provider
|
5
|
+
end
|
6
|
+
|
7
|
+
class MyMock
|
8
|
+
attr_accessor :options
|
9
|
+
include YARD::Generators::Helpers::MarkupHelper
|
10
|
+
end
|
11
|
+
|
12
|
+
describe YARD::Generators::Helpers::MarkupHelper do
|
13
|
+
before do
|
14
|
+
@gen = mock('Generator')
|
15
|
+
@gen.extend(YARD::Generators::Helpers::MarkupHelper)
|
16
|
+
end
|
17
|
+
|
18
|
+
def generator_should_exit
|
19
|
+
STDERR.should_receive(:puts)
|
20
|
+
@gen.should_receive(:exit)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should exit on an invalid markup type" do
|
24
|
+
generator_should_exit
|
25
|
+
@gen.stub!(:options).and_return({:markup => :invalid})
|
26
|
+
|
27
|
+
# it will raise since providers == nil
|
28
|
+
# but in reality it would have already `exit`ed.
|
29
|
+
@gen.load_markup_provider rescue nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should exit on when an invalid markup provider is specified" do
|
33
|
+
generator_should_exit
|
34
|
+
@gen.stub!(:options).and_return({:markup => :markdown, :markup_provider => :invalid})
|
35
|
+
|
36
|
+
# it will raise since providers == nil
|
37
|
+
# but in reality it would have already `exit`ed.
|
38
|
+
@gen.load_markup_provider rescue nil
|
39
|
+
@gen.markup_class.should == nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should load nothing if rdoc is specified" do
|
43
|
+
@gen.stub!(:options).and_return({:markup => :rdoc})
|
44
|
+
@gen.load_markup_provider
|
45
|
+
@gen.markup_class.should == YARD::Generators::Helpers::MarkupHelper::SimpleMarkup
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should search through available markup providers for the markup type if none is set" do
|
49
|
+
@gen.should_receive(:require).with('bluecloth').and_return(true)
|
50
|
+
@gen.stub!(:options).and_return({:markup => :markdown})
|
51
|
+
# this only raises an exception because we mock out require to avoid
|
52
|
+
# loading any libraries but our implementation tries to return the library
|
53
|
+
# name as a constant
|
54
|
+
@gen.load_markup_provider rescue nil
|
55
|
+
@gen.markup_provider.should == :bluecloth
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should continue searching if some of the providers are unavailable" do
|
59
|
+
@gen.should_receive(:require).with('bluecloth').and_raise(LoadError)
|
60
|
+
@gen.should_receive(:require).with('maruku').and_raise(LoadError)
|
61
|
+
@gen.should_receive(:require).with('rpeg-markdown').and_return(true)
|
62
|
+
@gen.stub!(:options).and_return({:markup => :markdown})
|
63
|
+
# this only raises an exception because we mock out require to avoid
|
64
|
+
# loading any libraries but our implementation tries to return the library
|
65
|
+
# name as a constant
|
66
|
+
@gen.load_markup_provider rescue nil
|
67
|
+
@gen.markup_provider.should == :"rpeg-markdown"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should override the search if `:markup_provider` is set in options" do
|
71
|
+
@gen.should_receive(:require).with('rdiscount').and_return(true)
|
72
|
+
@gen.stub!(:options).and_return({:markup => :markdown, :markup_provider => :rdiscount})
|
73
|
+
@gen.load_markup_provider rescue nil
|
74
|
+
@gen.markup_provider.should == :rdiscount
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should fail if no provider is found" do
|
78
|
+
generator_should_exit
|
79
|
+
YARD::Generators::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown].each do |p|
|
80
|
+
@gen.should_receive(:require).with(p[:lib].to_s).and_raise(LoadError)
|
81
|
+
end
|
82
|
+
@gen.stub!(:options).and_return({:markup => :markdown})
|
83
|
+
@gen.load_markup_provider rescue nil
|
84
|
+
@gen.markup_provider.should == nil
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should fail if overridden provider is not found" do
|
88
|
+
generator_should_exit
|
89
|
+
@gen.should_receive(:require).with('rdiscount').and_raise(LoadError)
|
90
|
+
@gen.stub!(:options).and_return({:markup => :markdown, :markup_provider => :rdiscount})
|
91
|
+
@gen.load_markup_provider rescue nil
|
92
|
+
@gen.markup_provider.should == nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
describe YARD::Handlers::AliasHandler do
|
3
|
+
describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}AliasHandler" do
|
4
4
|
before do
|
5
5
|
Registry.clear
|
6
6
|
parse_file :alias_handler_001, __FILE__
|
@@ -11,11 +11,19 @@ describe YARD::Handlers::AliasHandler do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should handle the Ruby 'alias' keyword syntax" do
|
14
|
-
['A#c', 'A#d?', 'A#[]', 'A#[]=', 'A
|
14
|
+
['A#c', 'A#d?', 'A#[]', 'A#[]=', 'A#-@', 'A#%', 'A#*'].each do |a|
|
15
15
|
P(a).should be_instance_of(CodeObjects::MethodObject)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
it "should handle keywords as the alias name" do
|
20
|
+
P('A#for').should be_instance_of(CodeObjects::MethodObject)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should allow ConstantNames to be specified as aliases" do
|
24
|
+
P('A#ConstantName').should be_instance_of(CodeObjects::MethodObject)
|
25
|
+
end
|
26
|
+
|
19
27
|
it "should create a new method object for the alias" do
|
20
28
|
P("A#b").should be_instance_of(CodeObjects::MethodObject)
|
21
29
|
end
|
@@ -37,6 +45,11 @@ describe YARD::Handlers::AliasHandler do
|
|
37
45
|
P("B#t").is_alias?.should == true
|
38
46
|
P('B#r?').is_alias?.should == true
|
39
47
|
end
|
48
|
+
|
49
|
+
it "should allow operators and keywords to be specified as symbols" do
|
50
|
+
P('B#<<').should be_instance_of(CodeObjects::MethodObject)
|
51
|
+
P('B#for').should be_instance_of(CodeObjects::MethodObject)
|
52
|
+
end
|
40
53
|
|
41
54
|
it "should raise an UndocumentableError if only one parameter is passed" do
|
42
55
|
undoc_error "alias_method :q"
|
@@ -47,4 +60,4 @@ describe YARD::Handlers::AliasHandler do
|
|
47
60
|
undoc_error "alias_method variable, ClassName"
|
48
61
|
undoc_error "alias_method variable, other_variable"
|
49
62
|
end
|
50
|
-
end
|
63
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
describe YARD::Handlers::AttributeHandler do
|
3
|
+
describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}AttributeHandler" do
|
4
4
|
before { parse_file :attribute_handler_001, __FILE__ }
|
5
5
|
|
6
6
|
def read_write(namespace, name, read, write, scope = :instance)
|
data/spec/handlers/base_spec.rb
CHANGED
@@ -12,154 +12,28 @@ describe YARD::Handlers::Base, "#handles and inheritance" do
|
|
12
12
|
class TestHandler < Handlers::Base; end
|
13
13
|
end
|
14
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
15
|
it "should raise NotImplementedError if process is called on a class with no #process" do
|
43
16
|
class TestNotImplementedHandler < Handlers::Base
|
44
|
-
handles TkMODULE
|
45
17
|
end
|
46
18
|
|
47
19
|
lambda { TestNotImplementedHandler.new(0, 0).process }.should raise_error(NotImplementedError)
|
48
20
|
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
21
|
|
98
|
-
it "should
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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?"
|
22
|
+
it "should allow multiple handles arguments" do
|
23
|
+
Handlers::Base.should_receive(:inherited).once
|
24
|
+
class TestHandler1 < Handlers::Base
|
25
|
+
handles :a, :b, :c
|
26
|
+
end
|
27
|
+
TestHandler1.handlers.should == [:a, :b, :c]
|
109
28
|
end
|
110
|
-
|
111
|
-
#it "should obey documentation expectations" do docspec end
|
112
|
-
end
|
113
29
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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 == []
|
30
|
+
it "should allow multiple handles calls" do
|
31
|
+
Handlers::Base.should_receive(:inherited).once
|
32
|
+
class TestHandler2 < Handlers::Base
|
33
|
+
handles :a
|
34
|
+
handles :b
|
35
|
+
handles :c
|
36
|
+
end
|
37
|
+
TestHandler2.handlers.should == [:a, :b, :c]
|
164
38
|
end
|
165
|
-
end
|
39
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ClassConditionHandler" do
|
4
|
+
before do
|
5
|
+
Registry.clear
|
6
|
+
parse_file :class_condition_handler_001, __FILE__
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify_method(*names)
|
10
|
+
names.each {|name| Registry.at("A##{name}").should_not be_nil }
|
11
|
+
names.each {|name| Registry.at("A##{name}not").should be_nil }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should parse all if/elsif blocks for complex conditions" do
|
15
|
+
verify_method :a, :b, :c, :d
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should parse all unless blocks for complex conditions" do
|
19
|
+
verify_method :g
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not parse conditionals inside methods" do
|
23
|
+
verify_method :h
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should only parse then block if condition is literal value `true`" do
|
27
|
+
verify_method :p
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should only parse else block if condition is literal value `false`" do
|
31
|
+
verify_method :q
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should only parse then block if condition is literal integer != 0" do
|
35
|
+
verify_method :o
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should only parse else block if condition is literal integer == 0" do
|
39
|
+
verify_method :n
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should invert block to parse for literal condition if it's an unless block" do
|
43
|
+
verify_method :e
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should handle conditions such as 'defined? VALUE'" do
|
47
|
+
verify_method :j, :k
|
48
|
+
end
|
49
|
+
end if RUBY19
|