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,176 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::CodeObjects::ClassObject do
|
4
|
+
before do
|
5
|
+
Registry.clear
|
6
|
+
@mixin = ModuleObject.new(:root, :SomeMixin)
|
7
|
+
@mixin2 = ModuleObject.new(:root, :SomeMixin2)
|
8
|
+
@superyard = ClassObject.new(:root, :SuperYard)
|
9
|
+
@superyard.superclass = P("String")
|
10
|
+
@superyard.mixins << @mixin2
|
11
|
+
@yard = ClassObject.new(:root, :YARD)
|
12
|
+
@yard.superclass = @superyard
|
13
|
+
@yard.mixins << @mixin
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should show the proper inheritance tree" do
|
17
|
+
@yard.inheritance_tree.should == [@yard, @superyard, P(:String)]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should show proper inheritance tree when mixins are included" do
|
21
|
+
@yard.inheritance_tree(true).should == [@yard, @mixin, @superyard, P(:String)]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe YARD::CodeObjects::ClassObject, "#meths / #inherited_meths" do
|
26
|
+
before do
|
27
|
+
Registry.clear
|
28
|
+
|
29
|
+
Parser::SourceParser.parse_string <<-eof
|
30
|
+
class SuperYard < String
|
31
|
+
def foo; end
|
32
|
+
def foo2; end
|
33
|
+
def bar; end
|
34
|
+
def middle; end
|
35
|
+
protected :foo2
|
36
|
+
private
|
37
|
+
def self.bar; end
|
38
|
+
end
|
39
|
+
|
40
|
+
class MiddleYard < SuperYard
|
41
|
+
def middle; end
|
42
|
+
end
|
43
|
+
|
44
|
+
class YARD < MiddleYard
|
45
|
+
def mymethod; end
|
46
|
+
def bar; end
|
47
|
+
end
|
48
|
+
eof
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should show inherited methods by default" do
|
52
|
+
meths = P(:YARD).meths
|
53
|
+
meths.should include(P("YARD#mymethod"))
|
54
|
+
meths.should include(P("SuperYard#foo"))
|
55
|
+
meths.should include(P("SuperYard#foo2"))
|
56
|
+
meths.should include(P("SuperYard::bar"))
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should allow :inherited to be set to false" do
|
60
|
+
meths = P(:YARD).meths(:inherited => false)
|
61
|
+
meths.should include(P("YARD#mymethod"))
|
62
|
+
meths.should_not include(P("SuperYard#foo"))
|
63
|
+
meths.should_not include(P("SuperYard#foo2"))
|
64
|
+
meths.should_not include(P("SuperYard::bar"))
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not show overridden methods" do
|
68
|
+
meths = P(:YARD).meths
|
69
|
+
meths.should include(P("YARD#bar"))
|
70
|
+
meths.should_not include(P("SuperYard#bar"))
|
71
|
+
|
72
|
+
meths = P(:YARD).inherited_meths
|
73
|
+
meths.should_not include(P("YARD#bar"))
|
74
|
+
meths.should_not include(P("YARD#mymethod"))
|
75
|
+
meths.should include(P("SuperYard#foo"))
|
76
|
+
meths.should include(P("SuperYard#foo2"))
|
77
|
+
meths.should include(P("SuperYard::bar"))
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not show inherited methods overridden by other subclasses" do
|
81
|
+
meths = P(:YARD).inherited_meths
|
82
|
+
meths.should include(P('MiddleYard#middle'))
|
83
|
+
meths.should_not include(P('SuperYard#middle'))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe YARD::CodeObjects::ClassObject, "#constants / #inherited_constants" do
|
88
|
+
before do
|
89
|
+
Registry.clear
|
90
|
+
|
91
|
+
Parser::SourceParser.parse_string <<-eof
|
92
|
+
class YARD
|
93
|
+
CONST1 = 1
|
94
|
+
CONST2 = "hello"
|
95
|
+
CONST4 = 0
|
96
|
+
end
|
97
|
+
|
98
|
+
class SUPERYARD < YARD
|
99
|
+
CONST4 = 5
|
100
|
+
end
|
101
|
+
|
102
|
+
class SubYard < SUPERYARD
|
103
|
+
CONST2 = "hi"
|
104
|
+
CONST3 = "foo"
|
105
|
+
end
|
106
|
+
eof
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should list inherited constants by default" do
|
110
|
+
consts = P(:SubYard).constants
|
111
|
+
consts.should include(P("YARD::CONST1"))
|
112
|
+
consts.should include(P("SubYard::CONST3"))
|
113
|
+
|
114
|
+
consts = P(:SubYard).inherited_constants
|
115
|
+
consts.should include(P("YARD::CONST1"))
|
116
|
+
consts.should_not include(P("YARD::CONST2"))
|
117
|
+
consts.should_not include(P("SubYard::CONST2"))
|
118
|
+
consts.should_not include(P("SubYard::CONST3"))
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should not list inherited constants if turned off" do
|
122
|
+
consts = P(:SubYard).constants(:inherited => false)
|
123
|
+
consts.should_not include(P("YARD::CONST1"))
|
124
|
+
consts.should include(P("SubYard::CONST3"))
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should not include an inherited constant if it is overridden by the object" do
|
128
|
+
consts = P(:SubYard).constants
|
129
|
+
consts.should include(P("SubYard::CONST2"))
|
130
|
+
consts.should_not include(P("YARD::CONST2"))
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should not include an inherited constant if it is overridden by another subclass" do
|
134
|
+
consts = P(:SubYard).inherited_constants
|
135
|
+
consts.should include(P("SUPERYARD::CONST4"))
|
136
|
+
consts.should_not include(P("YARD::CONST4"))
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should not set a superclass on Object class" do
|
140
|
+
o = ClassObject.new(:root, :Object)
|
141
|
+
o.superclass.should be_nil
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should raise ArgumentError if superclass == self" do
|
145
|
+
lambda do
|
146
|
+
o = ClassObject.new(:root, :Object) do |o|
|
147
|
+
o.superclass = :Object
|
148
|
+
end
|
149
|
+
end.should raise_error(ArgumentError)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should tell the world if it is an exception class" do
|
153
|
+
o = ClassObject.new(:root, :MyClass)
|
154
|
+
o2 = ClassObject.new(:root, :OtherClass)
|
155
|
+
o2.superclass = :SystemCallError
|
156
|
+
o3 = ClassObject.new(:root, :StandardError)
|
157
|
+
o3.superclass = :Object
|
158
|
+
o4 = ClassObject.new(:root, :Object)
|
159
|
+
|
160
|
+
o.superclass = :Object
|
161
|
+
o.is_exception?.should == false
|
162
|
+
|
163
|
+
o.superclass = :Exception
|
164
|
+
o.is_exception?.should == true
|
165
|
+
|
166
|
+
o.superclass = :NoMethodError
|
167
|
+
o.is_exception?.should == true
|
168
|
+
|
169
|
+
o.superclass = o2
|
170
|
+
o.is_exception?.should == true
|
171
|
+
|
172
|
+
o.superclass = o3
|
173
|
+
o.is_exception?.should == true
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::CodeObjects::CodeObjectList do
|
4
|
+
before { Registry.clear }
|
5
|
+
|
6
|
+
it "pushing a value should only allow CodeObjects::Base, String or Symbol" do
|
7
|
+
list = CodeObjectList.new(nil)
|
8
|
+
lambda { list.push(:hash => 1) }.should raise_error(ArgumentError)
|
9
|
+
list << "Test"
|
10
|
+
list << :Test2
|
11
|
+
list << ModuleObject.new(nil, :YARD)
|
12
|
+
list.size.should == 3
|
13
|
+
end
|
14
|
+
|
15
|
+
it "added value should be a proxy if parameter was String or Symbol" do
|
16
|
+
list = CodeObjectList.new(nil)
|
17
|
+
list << "Test"
|
18
|
+
list.first.class.should == Proxy
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should contain a unique list of objects" do
|
22
|
+
obj = ModuleObject.new(nil, :YARD)
|
23
|
+
list = CodeObjectList.new(nil)
|
24
|
+
|
25
|
+
list << P(:YARD)
|
26
|
+
list << obj
|
27
|
+
list.size.should == 1
|
28
|
+
|
29
|
+
list << :Test
|
30
|
+
list << "Test"
|
31
|
+
list.size.should == 2
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::CodeObjects, "CONSTANTMATCH" do
|
4
|
+
it "should match a constant" do
|
5
|
+
"Constant"[CodeObjects::CONSTANTMATCH].should == "Constant"
|
6
|
+
"identifier"[CodeObjects::CONSTANTMATCH].should be_nil
|
7
|
+
"File.new"[CodeObjects::CONSTANTMATCH].should == "File"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe YARD::CodeObjects, "NAMESPACEMATCH" do
|
12
|
+
it "should match a namespace (multiple constants with ::)" do
|
13
|
+
"Constant"[CodeObjects::NAMESPACEMATCH].should == "Constant"
|
14
|
+
"A::B::C.new"[CodeObjects::NAMESPACEMATCH].should == "A::B::C"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe YARD::CodeObjects, "METHODNAMEMATCH" do
|
19
|
+
it "should match a method name" do
|
20
|
+
"method"[CodeObjects::METHODNAMEMATCH].should == "method"
|
21
|
+
"[]()"[CodeObjects::METHODNAMEMATCH].should == "[]"
|
22
|
+
"-@"[CodeObjects::METHODNAMEMATCH].should == "-@"
|
23
|
+
"method?"[CodeObjects::METHODNAMEMATCH].should == "method?"
|
24
|
+
"method!!"[CodeObjects::METHODNAMEMATCH].should == "method!"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe YARD::CodeObjects, "METHODMATCH" do
|
29
|
+
it "should match a full class method path" do
|
30
|
+
"method"[CodeObjects::METHODMATCH].should == "method"
|
31
|
+
"A::B::C.method?"[CodeObjects::METHODMATCH].should == "A::B::C.method?"
|
32
|
+
"A::B::C :: method"[CodeObjects::METHODMATCH].should == "A::B::C :: method"
|
33
|
+
"SomeClass . method"[CodeObjects::METHODMATCH].should == "SomeClass . method"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should match self.method" do
|
37
|
+
"self :: method!"[CodeObjects::METHODMATCH].should == "self :: method!"
|
38
|
+
"self.is_a?"[CodeObjects::METHODMATCH].should == "self.is_a?"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe YARD::CodeObjects, "BUILTIN_EXCEPTIONS" do
|
43
|
+
it "should include all base exceptions" do
|
44
|
+
YARD::CodeObjects::BUILTIN_EXCEPTIONS.each do |name|
|
45
|
+
eval(name).should <= Exception
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe YARD::CodeObjects, "BUILTIN_CLASSES" do
|
51
|
+
it "should include all base classes" do
|
52
|
+
YARD::CodeObjects::BUILTIN_CLASSES.each do |name|
|
53
|
+
eval(name).should be_instance_of(Class)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should include all exceptions" do
|
58
|
+
YARD::CodeObjects::BUILTIN_EXCEPTIONS.each do |name|
|
59
|
+
YARD::CodeObjects::BUILTIN_CLASSES.should include(name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe YARD::CodeObjects, "BUILTIN_ALL" do
|
65
|
+
it "should include classes modules and exceptions" do
|
66
|
+
a = YARD::CodeObjects::BUILTIN_ALL
|
67
|
+
b = YARD::CodeObjects::BUILTIN_CLASSES
|
68
|
+
c = YARD::CodeObjects::BUILTIN_MODULES
|
69
|
+
a.should == b+c
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe YARD::CodeObjects, "BUILTIN_MODULES" do
|
74
|
+
it "should include all base modules" do
|
75
|
+
YARD::CodeObjects::BUILTIN_MODULES.each do |name|
|
76
|
+
eval(name).should be_instance_of(Module)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::CodeObjects::MethodObject do
|
4
|
+
before do
|
5
|
+
Registry.clear
|
6
|
+
@yard = ModuleObject.new(:root, :YARD)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have a path of testing for an instance method in the root" do
|
10
|
+
meth = MethodObject.new(:root, :testing)
|
11
|
+
meth.path.should == "#testing"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have a path of YARD#testing for an instance method in YARD" do
|
15
|
+
meth = MethodObject.new(@yard, :testing)
|
16
|
+
meth.path.should == "YARD#testing"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have a path of YARD::testing for a class method in YARD" do
|
20
|
+
meth = MethodObject.new(@yard, :testing, :class)
|
21
|
+
meth.path.should == "YARD::testing"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should exist in the registry after successful creation" do
|
25
|
+
obj = MethodObject.new(@yard, :something, :class)
|
26
|
+
Registry.at("YARD::something").should_not == nil
|
27
|
+
obj = MethodObject.new(@yard, :somethingelse)
|
28
|
+
Registry.at("YARD#somethingelse").should_not == nil
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::CodeObjects::ModuleObject, "#meths" do
|
4
|
+
before do
|
5
|
+
Registry.clear
|
6
|
+
|
7
|
+
# setup the object space:
|
8
|
+
#
|
9
|
+
# YARD:module
|
10
|
+
# YARD#foo:method
|
11
|
+
# YARD#foo2:method
|
12
|
+
# YARD#xyz:method
|
13
|
+
# YARD::bar:method
|
14
|
+
# SomeMod#mixmethod
|
15
|
+
# SomeMod#xyz:method
|
16
|
+
#
|
17
|
+
@yard = ModuleObject.new(:root, :YARD)
|
18
|
+
MethodObject.new(@yard, :foo)
|
19
|
+
MethodObject.new(@yard, :xyz)
|
20
|
+
MethodObject.new(@yard, :foo2) do |o|
|
21
|
+
o.visibility = :protected
|
22
|
+
end
|
23
|
+
MethodObject.new(@yard, :bar, :class) do |o|
|
24
|
+
o.visibility = :private
|
25
|
+
end
|
26
|
+
@other = ModuleObject.new(:root, :SomeMod)
|
27
|
+
MethodObject.new(@other, :mixmethod)
|
28
|
+
MethodObject.new(@other, :xyz)
|
29
|
+
|
30
|
+
@yard.mixins << @other
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should list all methods (including mixin methods) via #meths" do
|
34
|
+
meths = @yard.meths
|
35
|
+
meths.should include(P("YARD#foo"))
|
36
|
+
meths.should include(P("YARD#foo2"))
|
37
|
+
meths.should include(P("YARD::bar"))
|
38
|
+
meths.should include(P("SomeMod#mixmethod"))
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should allow :visibility to be set" do
|
42
|
+
meths = @yard.meths(:visibility => :public)
|
43
|
+
meths.should_not include(P("YARD::bar"))
|
44
|
+
meths = @yard.meths(:visibility => [:public, :private])
|
45
|
+
meths.should include(P("YARD#foo"))
|
46
|
+
meths.should include(P("YARD::bar"))
|
47
|
+
meths.should_not include(P("YARD#foo2"))
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should allow :scope to be set" do
|
51
|
+
meths = @yard.meths(:scope => :class)
|
52
|
+
meths.should_not include(P("YARD#foo"))
|
53
|
+
meths.should_not include(P("YARD#foo2"))
|
54
|
+
meths.should_not include(P("SomeMod#mixmethod"))
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should allow :included to be set" do
|
58
|
+
meths = @yard.meths(:included => false)
|
59
|
+
meths.should_not include(P("SomeMod#mixmethod"))
|
60
|
+
meths.should include(P("YARD#foo"))
|
61
|
+
meths.should include(P("YARD#foo2"))
|
62
|
+
meths.should include(P("YARD::bar"))
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should choose the method defined in the class over an included module" do
|
66
|
+
meths = @yard.meths
|
67
|
+
meths.should_not include(P("SomeMod#xyz"))
|
68
|
+
meths.should include(P("YARD#xyz"))
|
69
|
+
|
70
|
+
meths = @other.meths
|
71
|
+
meths.should include(P("SomeMod#xyz"))
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe YARD::CodeObjects::NamespaceObject do
|
4
|
+
before { Registry.clear }
|
5
|
+
|
6
|
+
it "should respond to #child with the object name passed in" do
|
7
|
+
obj = NamespaceObject.new(nil, :YARD)
|
8
|
+
other = NamespaceObject.new(obj, :Other)
|
9
|
+
obj.child(:Other).should == other
|
10
|
+
obj.child('Other').should == other
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should respond to #child with hash of reader attributes with their response value" do
|
14
|
+
obj = NamespaceObject.new(nil, :YARD)
|
15
|
+
NamespaceObject.new(obj, :NotOther)
|
16
|
+
other = NamespaceObject.new(obj, :Other)
|
17
|
+
other.somevalue = 2
|
18
|
+
obj.child(:somevalue => 2).should == other
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return #meths even if parent is a Proxy" do
|
22
|
+
obj = NamespaceObject.new(P(:String), :YARD)
|
23
|
+
obj.meths.should be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not list included methods that are already defined in the namespace using #meths" do
|
27
|
+
a = ModuleObject.new(nil, :Mod)
|
28
|
+
ameth = MethodObject.new(a, :testing)
|
29
|
+
ameth2 = MethodObject.new(a, :foo, :class)
|
30
|
+
b = NamespaceObject.new(nil, :YARD)
|
31
|
+
bmeth = MethodObject.new(b, :testing)
|
32
|
+
bmeth2 = MethodObject.new(b, :foo)
|
33
|
+
b.mixins << a
|
34
|
+
|
35
|
+
meths = b.meths
|
36
|
+
meths.should include(bmeth)
|
37
|
+
meths.should include(bmeth2)
|
38
|
+
meths.should include(ameth2)
|
39
|
+
meths.should_not include(ameth)
|
40
|
+
|
41
|
+
meths = b.included_meths
|
42
|
+
meths.should include(ameth2)
|
43
|
+
meths.should_not include(ameth)
|
44
|
+
meths.should_not include(bmeth)
|
45
|
+
meths.should_not include(bmeth2)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not list methods overridden by another included module" do
|
49
|
+
a = ModuleObject.new(nil, :Mod)
|
50
|
+
ameth = MethodObject.new(a, :testing)
|
51
|
+
b = ModuleObject.new(nil, :Mod2)
|
52
|
+
bmeth = MethodObject.new(b, :testing)
|
53
|
+
c = NamespaceObject.new(nil, :YARD)
|
54
|
+
c.mixins << a
|
55
|
+
c.mixins << b
|
56
|
+
|
57
|
+
meths = c.included_meths
|
58
|
+
meths.should_not include(ameth)
|
59
|
+
meths.should include(bmeth)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should list class attributes using #class_attributes" do
|
63
|
+
a = NamespaceObject.new(nil, :Mod)
|
64
|
+
a.attributes[:instance][:a] = { :read => MethodObject.new(a, :a), :write => nil }
|
65
|
+
a.attributes[:instance][:b] = { :read => MethodObject.new(a, :b), :write => nil }
|
66
|
+
a.attributes[:class][:a] = { :read => MethodObject.new(a, :a, :class), :write => nil }
|
67
|
+
a.class_attributes.keys.should include(:a)
|
68
|
+
a.class_attributes.keys.should_not include(:b)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should list instance attributes using #instance attributes" do
|
72
|
+
a = NamespaceObject.new(nil, :Mod)
|
73
|
+
a.attributes[:instance][:a] = { :read => MethodObject.new(a, :a), :write => nil }
|
74
|
+
a.attributes[:instance][:b] = { :read => MethodObject.new(a, :b), :write => nil }
|
75
|
+
a.attributes[:class][:a] = { :read => MethodObject.new(a, :a, :class), :write => nil }
|
76
|
+
a.instance_attributes.keys.should include(:a)
|
77
|
+
a.instance_attributes.keys.should include(:b)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe YARD::CodeObjects::NamespaceObject, '#constants/#included_constants' do
|
82
|
+
before do
|
83
|
+
Registry.clear
|
84
|
+
|
85
|
+
Parser::SourceParser.parse_string <<-eof
|
86
|
+
module A
|
87
|
+
CONST1 = 1
|
88
|
+
CONST2 = 2
|
89
|
+
end
|
90
|
+
|
91
|
+
module B
|
92
|
+
CONST2 = -2
|
93
|
+
CONST3 = -3
|
94
|
+
end
|
95
|
+
|
96
|
+
class C
|
97
|
+
CONST3 = 3
|
98
|
+
CONST4 = 4
|
99
|
+
|
100
|
+
include A
|
101
|
+
include B
|
102
|
+
end
|
103
|
+
eof
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should list all included constants by default" do
|
107
|
+
consts = P(:C).constants
|
108
|
+
consts.should include(P('A::CONST1'))
|
109
|
+
consts.should include(P('C::CONST4'))
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should allow :included to be set to false to ignore included constants" do
|
113
|
+
consts = P(:C).constants(:included => false)
|
114
|
+
consts.should_not include(P('A::CONST1'))
|
115
|
+
consts.should include(P('C::CONST4'))
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should not list an included constant if it is defined in the object" do
|
119
|
+
consts = P(:C).constants
|
120
|
+
consts.should include(P('C::CONST3'))
|
121
|
+
consts.should_not include(P('B::CONST3'))
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should not list an included constant if it is shadowed by another included constant" do
|
125
|
+
consts = P(:C).included_constants
|
126
|
+
consts.should include(P('B::CONST2'))
|
127
|
+
consts.should_not include(P('A::CONST2'))
|
128
|
+
end
|
129
|
+
end
|