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,80 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::CodeObjects::Proxy do
|
4
|
+
before { Registry.clear }
|
5
|
+
|
6
|
+
it "should return the object if it's in the Registry" do
|
7
|
+
pathobj = ModuleObject.new(:root, :YARD)
|
8
|
+
proxyobj = P(:root, :YARD)
|
9
|
+
proxyobj.type.should == :module
|
10
|
+
Proxy.should_not === proxyobj
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should handle complex string namespaces" do
|
14
|
+
ModuleObject.new(:root, :A)
|
15
|
+
pathobj = ModuleObject.new(P(nil, :A), :B)
|
16
|
+
P(:root, "A::B").should be_instance_of(ModuleObject)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not return true to Proxy === obj if obj is a Proxy class holding a resolved object" do
|
20
|
+
Proxy.should === P(:root, 'a')
|
21
|
+
Proxy.should_not === P(:root)
|
22
|
+
MethodObject.new(:root, 'a')
|
23
|
+
Proxy.should_not === P(:root, 'a')
|
24
|
+
x = Proxy.new(:root, 'a')
|
25
|
+
Proxy.should_not === x
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return the object if it's an included Module" do
|
29
|
+
yardobj = ModuleObject.new(:root, :YARD)
|
30
|
+
pathobj = ClassObject.new(:root, :TestClass)
|
31
|
+
pathobj.mixins << yardobj
|
32
|
+
P(P(nil, :TestClass), :YARD).should be_instance_of(ModuleObject)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should respond_to respond_to?" do
|
36
|
+
obj = ClassObject.new(:root, :Object)
|
37
|
+
yardobj = ModuleObject.new(:root, :YARD)
|
38
|
+
P(:YARD).respond_to?(:children).should == true
|
39
|
+
P(:NOTYARD).respond_to?(:children).should == false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should make itself obvious that it's a proxy" do
|
43
|
+
pathobj = P(:root, :YARD)
|
44
|
+
pathobj.class.should == Proxy
|
45
|
+
(Proxy === pathobj).should == true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should pretend it's the object's type if it can resolve" do
|
49
|
+
pathobj = ModuleObject.new(:root, :YARD)
|
50
|
+
proxyobj = P(:root, :YARD)
|
51
|
+
proxyobj.should be_instance_of(ModuleObject)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should handle instance method names" do
|
55
|
+
obj = P(nil, '#test')
|
56
|
+
obj.name.should == :test
|
57
|
+
obj.path.should == "#test"
|
58
|
+
obj.namespace.should == Registry.root
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should handle instance method names under a namespace" do
|
62
|
+
pathobj = ModuleObject.new(:root, :YARD)
|
63
|
+
obj = P(pathobj, "A::B#test")
|
64
|
+
obj.name.should == :test
|
65
|
+
obj.path.should == "A::B#test"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should allow type to be changed" do
|
69
|
+
obj = P("InvalidClass")
|
70
|
+
obj.type.should == :proxy
|
71
|
+
Proxy.should === obj
|
72
|
+
obj.type = :class
|
73
|
+
obj.type.should == :class
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should retain a type change between Proxy objects" do
|
77
|
+
P("InvalidClass").type = :class
|
78
|
+
P("InvalidClass").type.should == :class
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe File, ".relative_path" do
|
4
|
+
it "should return the relative path between two files" do
|
5
|
+
File.relative_path('a/b/c/d.html', 'a/b/d/q.html').should == '../d/q.html'
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return the relative path between two directories" do
|
9
|
+
File.relative_path('a/b/c/d/', 'a/b/d/').should == '../d'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return only the to file if from file is in the same directory as the to file" do
|
13
|
+
File.relative_path('a/b/c/d', 'a/b/c/e').should == 'e'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should handle non-normalized paths" do
|
17
|
+
File.relative_path('Hello/./I/Am/Fred', 'Hello/Fred').should == '../../Fred'
|
18
|
+
File.relative_path('A//B/C', 'Q/X').should == '../../Q/X'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe SymbolHash do
|
4
|
+
|
5
|
+
it "should allow access to keys as String or Symbol" do
|
6
|
+
h = SymbolHash.new(false)
|
7
|
+
h['test'] = true
|
8
|
+
h[:test].should == true
|
9
|
+
h['test'].should == true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should #delete by key as String or Symbol" do
|
13
|
+
h = SymbolHash.new
|
14
|
+
h.keys.length.should == 0
|
15
|
+
|
16
|
+
h['test'] = true
|
17
|
+
h.keys.length.should == 1
|
18
|
+
|
19
|
+
h.delete(:test)
|
20
|
+
h.keys.length.should == 0
|
21
|
+
|
22
|
+
h[:test] = true
|
23
|
+
h.keys.length.should == 1
|
24
|
+
|
25
|
+
h.delete('test')
|
26
|
+
h.keys.length.should == 0
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return same #has_key? for key as String or Symbol" do
|
30
|
+
h = SymbolHash.new
|
31
|
+
h[:test] = 1
|
32
|
+
h.has_key?(:test).should == true
|
33
|
+
h.has_key?('test').should == true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should symbolize value if it is a String (and only a string)" do
|
37
|
+
class Substring < String; end
|
38
|
+
|
39
|
+
h = SymbolHash.new
|
40
|
+
h['test1'] = "hello"
|
41
|
+
h['test2'] = Substring.new("hello")
|
42
|
+
h['test1'].should == :hello
|
43
|
+
h['test2'].should == "hello"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not symbolize value if SymbolHash.new(false) is created" do
|
47
|
+
h = SymbolHash.new(false)
|
48
|
+
h['test'] = "hello"
|
49
|
+
h[:test].should == "hello"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not symbolize value if it is not a String" do
|
53
|
+
h = SymbolHash.new
|
54
|
+
h['test'] = [1,2,3]
|
55
|
+
h['test'].should == [1,2,3]
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should support symbolization using #update or #merge" do
|
59
|
+
h = SymbolHash.new
|
60
|
+
h.update('test' => 'value')
|
61
|
+
h[:test].should == :value
|
62
|
+
h.merge('test' => 'value2')
|
63
|
+
h[:test].should == :value2
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should support #initializing of a hash" do
|
67
|
+
h = SymbolHash[:test => 1]
|
68
|
+
h[:test].should == 1
|
69
|
+
h[:somethingelse].should be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should support reverse merge syntax" do
|
73
|
+
opts = {}
|
74
|
+
opts = SymbolHash[
|
75
|
+
'default' => 1
|
76
|
+
].update(opts)
|
77
|
+
opts.keys.should == [:default]
|
78
|
+
opts[:default].should == 1
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
include YARD::Generators
|
5
|
+
|
6
|
+
describe YARD::Generators::Base, 'Section handling' do
|
7
|
+
before { Registry.clear }
|
8
|
+
|
9
|
+
it "should allow a list of sections to be returned by sections_for" do
|
10
|
+
base = Generators::Base.new
|
11
|
+
base.stub!(:sections_for).and_return [:meth1, :meth2, :meth3]
|
12
|
+
base.should_receive(:meth1).and_return('a')
|
13
|
+
base.should_receive(:meth2).and_return('b')
|
14
|
+
base.should_receive(:meth3).and_return('c')
|
15
|
+
base.generate(Registry.root).should == 'abc'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should allow a heirarchical list of sections to be returned by sections_for" do
|
19
|
+
base = Generators::Base.new
|
20
|
+
base.stub!(:sections_for).and_return [:meth1, [:meth2, :meth3]]
|
21
|
+
base.should_receive(:meth1).and_return('a')
|
22
|
+
base.should_not_receive(:meth2)
|
23
|
+
base.should_not_receive(:meth3)
|
24
|
+
base.generate(Registry.root).should == 'a'
|
25
|
+
base.current_object.should == Registry.root
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should yield sub section lists to the parent section" do
|
29
|
+
class XYZ < Generators::Base
|
30
|
+
def sections_for(object) [:meth1, [:submeth1, :submeth2, [:submeth1]]] end
|
31
|
+
def meth1(object) object.name.to_s + yield(object) end
|
32
|
+
def submeth1(object) object.name.to_s end
|
33
|
+
def submeth2(object) object.name.to_s + yield(P(:YARD)) end
|
34
|
+
end
|
35
|
+
|
36
|
+
CodeObjects::Base.new(:root, :YARD)
|
37
|
+
XYZ.new.generate(Registry.root).should == "rootrootrootYARD"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe YARD::Generators::Base, 'Rendering' do
|
42
|
+
it "should have a default template path" do
|
43
|
+
Generators::Base.template_paths.should == [YARD::TEMPLATE_ROOT]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should find the right erb file to render given a template, format and name" do
|
47
|
+
base = Generators::Base.new
|
48
|
+
file = File.join(YARD::TEMPLATE_ROOT, 'default', 'base', 'html', 'name.erb')
|
49
|
+
File.should_receive(:file?).with(file).and_return(true)
|
50
|
+
File.should_receive(:read).with(file).and_return("output")
|
51
|
+
base.stub!(:sections_for).and_return([:name])
|
52
|
+
base.generate(Registry.root).should == "output"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should allow the user to add extra search paths to find a custom template" do
|
56
|
+
Generators::Base.register_template_path 'doc'
|
57
|
+
base = Generators::Base.new
|
58
|
+
file = File.join('doc', 'default', 'base', 'html', 'name.erb')
|
59
|
+
File.should_receive(:file?).with(file).and_return(true)
|
60
|
+
File.should_receive(:read).with(file).and_return("output")
|
61
|
+
base.stub!(:sections_for).and_return([:name])
|
62
|
+
base.generate(Registry.root).should == "output"
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
describe YARD::Generators::Helpers::BaseHelper, "#linkify" do
|
2
|
+
include YARD::Generators::Helpers::BaseHelper
|
3
|
+
|
4
|
+
it "should pass off to #link_object if argument is an object" do
|
5
|
+
obj = CodeObjects::NamespaceObject.new(nil, :YARD)
|
6
|
+
should_receive(:link_object).with(obj)
|
7
|
+
linkify obj
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should pass off to #link_url if argument is recognized as a URL" do
|
11
|
+
url = "http://yard.soen.ca/"
|
12
|
+
should_receive(:link_url).with(url)
|
13
|
+
linkify url
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
describe YARD::Generators::Helpers::HtmlHelper, "basic HTML methods" do
|
2
|
+
include YARD::Generators::Helpers::HtmlHelper
|
3
|
+
|
4
|
+
it "should use #h to escape HTML" do
|
5
|
+
h('Usage: foo "bar" <baz>').should == "Usage: foo "bar" <baz>"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe YARD::Generators::Helpers::HtmlHelper, "#link_object" do
|
10
|
+
include YARD::Generators::Helpers::HtmlHelper
|
11
|
+
|
12
|
+
it "should return the object path if there's no serializer and no title" do
|
13
|
+
stub!(:serializer).and_return nil
|
14
|
+
link_object(CodeObjects::NamespaceObject.new(nil, :YARD)).should == "YARD"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return the title if there's a title but no serializer" do
|
18
|
+
stub!(:serializer).and_return nil
|
19
|
+
link_object(CodeObjects::NamespaceObject.new(nil, :YARD), 'title').should == "title"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe YARD::Generators::Helpers::HtmlHelper, '#url_for' do
|
24
|
+
include YARD::Generators::Helpers::HtmlHelper
|
25
|
+
|
26
|
+
before { Registry.clear }
|
27
|
+
|
28
|
+
it "should return nil if serializer is nil" do
|
29
|
+
stub!(:serializer).and_return nil
|
30
|
+
stub!(:current_object).and_return Registry.root
|
31
|
+
url_for(P("Mod::Class#meth")).should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return nil if serializer does not implement #serialized_path" do
|
35
|
+
stub!(:serializer).and_return Serializers::Base.new
|
36
|
+
stub!(:current_object).and_return Registry.root
|
37
|
+
url_for(P("Mod::Class#meth")).should be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should link to a path/file for a namespace object" do
|
41
|
+
stub!(:serializer).and_return Serializers::FileSystemSerializer.new
|
42
|
+
stub!(:current_object).and_return Registry.root
|
43
|
+
|
44
|
+
yard = CodeObjects::ModuleObject.new(:root, :YARD)
|
45
|
+
url_for(yard).should == 'YARD.html'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should link to the object's namespace path/file and use the object as the anchor" do
|
49
|
+
stub!(:serializer).and_return Serializers::FileSystemSerializer.new
|
50
|
+
stub!(:current_object).and_return Registry.root
|
51
|
+
|
52
|
+
yard = CodeObjects::ModuleObject.new(:root, :YARD)
|
53
|
+
meth = CodeObjects::MethodObject.new(yard, :meth)
|
54
|
+
url_for(meth).should == 'YARD.html#meth-instance_method'
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe YARD::Generators::QuickDocGenerator do
|
2
|
+
before { Registry.clear }
|
3
|
+
|
4
|
+
it "should call all sections" do
|
5
|
+
Parser::SourceParser.parse_string(<<-eof)
|
6
|
+
class A
|
7
|
+
# Docstring
|
8
|
+
def method1; end
|
9
|
+
end
|
10
|
+
eof
|
11
|
+
g = Generators::QuickDocGenerator.new
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::Handlers::AliasHandler do
|
4
|
+
before do
|
5
|
+
Registry.clear
|
6
|
+
parse_file :alias_handler_001, __FILE__
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should throw alias into namespace object list" do
|
10
|
+
P(:A).aliases[P("A#b")].should == :a
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should handle the Ruby 'alias' keyword syntax" do
|
14
|
+
['A#c', 'A#d?', 'A#[]', 'A#[]=', 'A#@-', 'A#%', 'A#*'].each do |a|
|
15
|
+
P(a).should be_instance_of(CodeObjects::MethodObject)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should create a new method object for the alias" do
|
20
|
+
P("A#b").should be_instance_of(CodeObjects::MethodObject)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should pull the method into the current class if it's from another one" do
|
24
|
+
P(:B).aliases[P("B#q")].should == :x
|
25
|
+
P(:B).aliases[P("B#r?")].should == :x
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should gracefully fail to pull a method in if the original method cannot be found" do
|
29
|
+
P(:B).aliases[P("B#s")].should == :to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should allow complex Ruby expressions after the alias parameters" do
|
33
|
+
P(:B).aliases[P("B#t")].should == :inspect
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should show up in #is_alias? for method" do
|
37
|
+
P("B#t").is_alias?.should == true
|
38
|
+
P('B#r?').is_alias?.should == true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise an UndocumentableError if only one parameter is passed" do
|
42
|
+
undoc_error "alias_method :q"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should raise an UndocumentableError if the parameter is not a Symbol or String" do
|
46
|
+
undoc_error "alias_method CONST, Something"
|
47
|
+
undoc_error "alias_method variable, ClassName"
|
48
|
+
undoc_error "alias_method variable, other_variable"
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::Handlers::AttributeHandler do
|
4
|
+
before { parse_file :attribute_handler_001, __FILE__ }
|
5
|
+
|
6
|
+
def read_write(namespace, name, read, write, scope = :instance)
|
7
|
+
rname, wname = namespace.to_s+"#"+name.to_s, namespace.to_s+"#"+name.to_s+"="
|
8
|
+
if read
|
9
|
+
Registry.at(rname).should be_instance_of(CodeObjects::MethodObject)
|
10
|
+
else
|
11
|
+
Registry.at(rname).should == nil
|
12
|
+
end
|
13
|
+
|
14
|
+
if write
|
15
|
+
Registry.at(wname).should be_kind_of(CodeObjects::MethodObject)
|
16
|
+
else
|
17
|
+
Registry.at(wname).should == nil
|
18
|
+
end
|
19
|
+
|
20
|
+
attrs = Registry.at(namespace).attributes[scope][name]
|
21
|
+
attrs[:read].should == (read ? Registry.at(rname) : nil)
|
22
|
+
attrs[:write].should == (write ? Registry.at(wname) : nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should parse attributes inside modules too" do
|
26
|
+
Registry.at("A#x=").should_not == nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should parse 'attr'" do
|
30
|
+
read_write(:B, :a, true, true)
|
31
|
+
read_write(:B, :a2, true, false)
|
32
|
+
read_write(:B, "a3", true, false)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should parse 'attr_reader'" do
|
36
|
+
read_write(:B, :b, true, false)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should parse 'attr_writer'" do
|
40
|
+
read_write(:B, :e, false, true)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should parse 'attr_accessor'" do
|
44
|
+
read_write(:B, :f, true, true)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should parse a list of attributes" do
|
48
|
+
read_write(:B, :b, true, false)
|
49
|
+
read_write(:B, :c, true, false)
|
50
|
+
read_write(:B, :d, true, false)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have a default docstring if one is not supplied" do
|
54
|
+
Registry.at("B#f=").docstring.should_not be_empty
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should set the correct docstring if one is supplied" do
|
58
|
+
Registry.at("B#b").docstring.should == "Docstring"
|
59
|
+
Registry.at("B#c").docstring.should == "Docstring"
|
60
|
+
Registry.at("B#d").docstring.should == "Docstring"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should be able to differentiate between class and instance attributes" do
|
64
|
+
P('B').class_attributes[:z][:read].scope.should == :class
|
65
|
+
P('B').instance_attributes[:z][:read].scope.should == :instance
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should respond true in method's #is_attribute?" do
|
69
|
+
P('B#a').is_attribute?.should == true
|
70
|
+
P('B#a=').is_attribute?.should == true
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should not return true for #is_explicit? in created methods" do
|
74
|
+
Registry.all(:method).each do |meth|
|
75
|
+
meth.is_explicit?.should == false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|