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.

Files changed (204) hide show
  1. data/LICENSE +1 -1
  2. data/README.markdown +200 -0
  3. data/Rakefile +6 -1
  4. data/benchmarks/format_args.rb +46 -0
  5. data/benchmarks/parsing.rb +13 -1
  6. data/benchmarks/rdoc_vs_yardoc.rb +10 -0
  7. data/benchmarks/ripper_parser.rb +12 -0
  8. data/docs/CODE_OBJECTS.markdown +121 -0
  9. data/docs/FAQ.markdown +34 -0
  10. data/docs/GENERATORS.markdown +211 -0
  11. data/docs/GETTING_STARTED.markdown +263 -0
  12. data/docs/GLOSSARY.markdown +13 -0
  13. data/docs/HANDLERS.markdown +158 -0
  14. data/docs/OVERVIEW.markdown +64 -0
  15. data/docs/PARSER.markdown +180 -0
  16. data/docs/TAGS.markdown +181 -0
  17. data/docs/WHATSNEW.markdown +96 -0
  18. data/docs/images/code-objects-class-diagram.png +0 -0
  19. data/docs/images/handlers-class-diagram.png +0 -0
  20. data/docs/images/overview-class-diagram.png +0 -0
  21. data/docs/images/parser-class-diagram.png +0 -0
  22. data/docs/images/tags-class-diagram.png +0 -0
  23. data/lib/yard.rb +4 -1
  24. data/lib/yard/autoload.rb +79 -31
  25. data/lib/yard/cli/yard_graph.rb +8 -2
  26. data/lib/yard/cli/yardoc.rb +61 -8
  27. data/lib/yard/code_objects/base.rb +78 -135
  28. data/lib/yard/code_objects/class_object.rb +9 -8
  29. data/lib/yard/code_objects/constant_object.rb +1 -0
  30. data/lib/yard/code_objects/extended_method_object.rb +9 -0
  31. data/lib/yard/code_objects/method_object.rb +18 -5
  32. data/lib/yard/code_objects/module_object.rb +8 -1
  33. data/lib/yard/code_objects/namespace_object.rb +25 -16
  34. data/lib/yard/code_objects/proxy.rb +22 -22
  35. data/lib/yard/core_ext/file.rb +1 -1
  36. data/lib/yard/core_ext/string.rb +0 -4
  37. data/lib/yard/core_ext/symbol_hash.rb +3 -2
  38. data/lib/yard/docstring.rb +180 -0
  39. data/lib/yard/generators/base.rb +33 -13
  40. data/lib/yard/generators/class_generator.rb +4 -2
  41. data/lib/yard/generators/constants_generator.rb +3 -2
  42. data/lib/yard/generators/full_doc_generator.rb +76 -9
  43. data/lib/yard/generators/helpers/base_helper.rb +18 -1
  44. data/lib/yard/generators/helpers/filter_helper.rb +2 -2
  45. data/lib/yard/generators/helpers/html_helper.rb +94 -39
  46. data/lib/yard/generators/helpers/html_syntax_highlight_helper.rb +49 -0
  47. data/lib/yard/generators/helpers/markup_helper.rb +86 -0
  48. data/lib/yard/generators/helpers/method_helper.rb +23 -7
  49. data/lib/yard/generators/method_generator.rb +15 -3
  50. data/lib/yard/generators/method_listing_generator.rb +3 -3
  51. data/lib/yard/generators/mixins_generator.rb +8 -2
  52. data/lib/yard/generators/module_generator.rb +3 -2
  53. data/lib/yard/generators/overloads_generator.rb +20 -0
  54. data/lib/yard/generators/quick_doc_generator.rb +3 -9
  55. data/lib/yard/generators/root_generator.rb +32 -0
  56. data/lib/yard/generators/source_generator.rb +2 -17
  57. data/lib/yard/generators/tags_generator.rb +34 -6
  58. data/lib/yard/generators/uml_generator.rb +16 -6
  59. data/lib/yard/handlers/base.rb +88 -253
  60. data/lib/yard/handlers/processor.rb +72 -0
  61. data/lib/yard/handlers/ruby/alias_handler.rb +38 -0
  62. data/lib/yard/handlers/ruby/attribute_handler.rb +69 -0
  63. data/lib/yard/handlers/ruby/base.rb +72 -0
  64. data/lib/yard/handlers/ruby/class_condition_handler.rb +70 -0
  65. data/lib/yard/handlers/ruby/class_handler.rb +74 -0
  66. data/lib/yard/handlers/ruby/class_variable_handler.rb +11 -0
  67. data/lib/yard/handlers/ruby/constant_handler.rb +12 -0
  68. data/lib/yard/handlers/ruby/exception_handler.rb +22 -0
  69. data/lib/yard/handlers/ruby/extend_handler.rb +19 -0
  70. data/lib/yard/handlers/{alias_handler.rb → ruby/legacy/alias_handler.rb} +3 -4
  71. data/lib/yard/handlers/{attribute_handler.rb → ruby/legacy/attribute_handler.rb} +2 -2
  72. data/lib/yard/handlers/ruby/legacy/base.rb +198 -0
  73. data/lib/yard/handlers/{class_handler.rb → ruby/legacy/class_handler.rb} +18 -6
  74. data/lib/yard/handlers/{class_variable_handler.rb → ruby/legacy/class_variable_handler.rb} +1 -1
  75. data/lib/yard/handlers/{constant_handler.rb → ruby/legacy/constant_handler.rb} +2 -2
  76. data/lib/yard/handlers/{exception_handler.rb → ruby/legacy/exception_handler.rb} +3 -3
  77. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +18 -0
  78. data/lib/yard/handlers/ruby/legacy/method_handler.rb +31 -0
  79. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +28 -0
  80. data/lib/yard/handlers/{module_handler.rb → ruby/legacy/module_handler.rb} +1 -1
  81. data/lib/yard/handlers/{visibility_handler.rb → ruby/legacy/visibility_handler.rb} +1 -1
  82. data/lib/yard/handlers/{yield_handler.rb → ruby/legacy/yield_handler.rb} +4 -4
  83. data/lib/yard/handlers/ruby/method_condition_handler.rb +7 -0
  84. data/lib/yard/handlers/ruby/method_handler.rb +48 -0
  85. data/lib/yard/handlers/ruby/mixin_handler.rb +25 -0
  86. data/lib/yard/handlers/ruby/module_handler.rb +9 -0
  87. data/lib/yard/handlers/ruby/visibility_handler.rb +18 -0
  88. data/lib/yard/handlers/ruby/yield_handler.rb +28 -0
  89. data/lib/yard/parser/ruby/ast_node.rb +263 -0
  90. data/lib/yard/parser/{ruby_lex.rb → ruby/legacy/ruby_lex.rb} +258 -259
  91. data/lib/yard/parser/{statement.rb → ruby/legacy/statement.rb} +8 -4
  92. data/lib/yard/parser/ruby/legacy/statement_list.rb +262 -0
  93. data/lib/yard/parser/{token_list.rb → ruby/legacy/token_list.rb} +1 -1
  94. data/lib/yard/parser/ruby/ruby_parser.rb +307 -0
  95. data/lib/yard/parser/source_parser.rb +76 -45
  96. data/lib/yard/rake/yardoc_task.rb +6 -1
  97. data/lib/yard/registry.rb +45 -19
  98. data/lib/yard/serializers/file_system_serializer.rb +8 -3
  99. data/lib/yard/tags/default_factory.rb +70 -10
  100. data/lib/yard/tags/default_tag.rb +12 -0
  101. data/lib/yard/tags/library.rb +65 -26
  102. data/lib/yard/tags/option_tag.rb +12 -0
  103. data/lib/yard/tags/overload_tag.rb +62 -0
  104. data/lib/yard/tags/ref_tag.rb +7 -0
  105. data/lib/yard/tags/ref_tag_list.rb +27 -0
  106. data/lib/yard/tags/tag.rb +1 -0
  107. data/lib/yard/tags/tag_format_error.rb +6 -0
  108. data/spec/cli/yardoc_spec.rb +43 -0
  109. data/spec/code_objects/base_spec.rb +56 -68
  110. data/spec/code_objects/class_object_spec.rb +18 -6
  111. data/spec/code_objects/constants_spec.rb +2 -0
  112. data/spec/code_objects/method_object_spec.rb +33 -5
  113. data/spec/code_objects/module_object_spec.rb +66 -8
  114. data/spec/code_objects/namespace_object_spec.rb +37 -17
  115. data/spec/code_objects/proxy_spec.rb +13 -2
  116. data/spec/core_ext/string_spec.rb +14 -2
  117. data/spec/core_ext/symbol_hash_spec.rb +9 -3
  118. data/spec/docstring_spec.rb +139 -0
  119. data/spec/generators/full_doc_generator_spec.rb +29 -0
  120. data/spec/generators/helpers/html_helper_spec.rb +74 -0
  121. data/spec/generators/helpers/markup_helper_spec.rb +95 -0
  122. data/spec/handlers/alias_handler_spec.rb +16 -3
  123. data/spec/handlers/attribute_handler_spec.rb +1 -1
  124. data/spec/handlers/base_spec.rb +15 -141
  125. data/spec/handlers/class_condition_handler_spec.rb +49 -0
  126. data/spec/handlers/class_handler_spec.rb +44 -3
  127. data/spec/handlers/class_variable_handler_spec.rb +1 -1
  128. data/spec/handlers/constant_handler_spec.rb +1 -1
  129. data/spec/handlers/examples/alias_handler_001.rb.txt +7 -3
  130. data/spec/handlers/examples/class_condition_handler_001.rb.txt +61 -0
  131. data/spec/handlers/examples/class_handler_001.rb.txt +33 -0
  132. data/spec/handlers/examples/exception_handler_001.rb.txt +1 -1
  133. data/spec/handlers/examples/extend_handler_001.rb.txt +8 -0
  134. data/spec/handlers/examples/method_condition_handler_001.rb.txt +10 -0
  135. data/spec/handlers/examples/method_handler_001.rb.txt +16 -4
  136. data/spec/handlers/examples/mixin_handler_001.rb.txt +10 -2
  137. data/spec/handlers/examples/module_handler_001.rb.txt +4 -0
  138. data/spec/handlers/examples/visibility_handler_001.rb.txt +1 -1
  139. data/spec/handlers/exception_handler_spec.rb +2 -2
  140. data/spec/handlers/extend_handler_spec.rb +15 -0
  141. data/spec/handlers/legacy_base_spec.rb +128 -0
  142. data/spec/handlers/method_condition_handler_spec.rb +14 -0
  143. data/spec/handlers/method_handler_spec.rb +38 -5
  144. data/spec/handlers/mixin_handler_spec.rb +15 -7
  145. data/spec/handlers/module_handler_spec.rb +5 -1
  146. data/spec/handlers/processor_spec.rb +19 -0
  147. data/spec/handlers/ruby/base_spec.rb +90 -0
  148. data/spec/handlers/ruby/legacy/base_spec.rb +53 -0
  149. data/spec/handlers/spec_helper.rb +22 -16
  150. data/spec/handlers/visibility_handler_spec.rb +4 -4
  151. data/spec/handlers/yield_handler_spec.rb +1 -1
  152. data/spec/parser/ruby/ast_node_spec.rb +15 -0
  153. data/spec/parser/ruby/legacy/statement_list_spec.rb +145 -0
  154. data/spec/parser/{token_list_spec.rb → ruby/legacy/token_list_spec.rb} +4 -4
  155. data/spec/parser/source_parser_spec.rb +0 -15
  156. data/spec/rake/yardoc_task_spec.rb +48 -0
  157. data/spec/registry_spec.rb +28 -2
  158. data/spec/serializers/file_system_serializer_spec.rb +7 -1
  159. data/spec/spec_helper.rb +1 -1
  160. data/spec/tags/default_factory_spec.rb +135 -0
  161. data/spec/tags/default_tag_spec.rb +11 -0
  162. data/spec/tags/overload_tag_spec.rb +35 -0
  163. data/spec/tags/ref_tag_list_spec.rb +53 -0
  164. data/templates/default/attributes/html/header.erb +17 -5
  165. data/templates/default/attributes/text/header.erb +1 -1
  166. data/templates/default/fulldoc/html/all_files.erb +19 -0
  167. data/templates/default/fulldoc/html/all_methods.erb +8 -7
  168. data/templates/default/fulldoc/html/all_namespaces.erb +4 -1
  169. data/templates/default/fulldoc/html/app.js +1 -1
  170. data/templates/default/fulldoc/html/{readme.erb → file.erb} +2 -2
  171. data/templates/default/fulldoc/html/header.erb +1 -1
  172. data/templates/default/fulldoc/html/index.erb +4 -3
  173. data/templates/default/fulldoc/html/style.css +13 -3
  174. data/templates/default/fulldoc/html/syntax_highlight.css +8 -5
  175. data/templates/default/method/text/header.erb +1 -0
  176. data/templates/default/method/text/title.erb +1 -0
  177. data/templates/default/methodsignature/html/main.erb +10 -8
  178. data/templates/default/methodsignature/text/main.erb +4 -1
  179. data/templates/default/methodsummary/html/summary.erb +8 -4
  180. data/templates/default/methodsummary/text/summary.erb +4 -1
  181. data/templates/default/mixins/html/header.erb +3 -3
  182. data/templates/default/overloads/html/header.erb +8 -0
  183. data/templates/default/overloads/text/header.erb +8 -0
  184. data/templates/default/root/html/header.erb +4 -0
  185. data/templates/default/tags/html/example.erb +20 -0
  186. data/templates/default/tags/html/option.erb +27 -0
  187. data/templates/default/tags/html/param.erb +21 -0
  188. data/templates/default/tags/html/tags.erb +4 -1
  189. data/templates/default/tags/html/todo.erb +8 -0
  190. data/templates/default/tags/text/example.erb +14 -0
  191. data/templates/default/tags/text/header.erb +3 -3
  192. data/templates/default/tags/text/option.erb +5 -0
  193. data/templates/default/tags/text/param.erb +9 -0
  194. data/templates/default/uml/dot/dependencies.erb +1 -1
  195. data/templates/default/uml/dot/info.erb +1 -1
  196. data/templates/default/uml/dot/superclasses.erb +2 -2
  197. data/templates/javadoc/methodsummary/html/summary.erb +2 -2
  198. data/templates/javadoc/mixins/html/header.erb +3 -3
  199. metadata +108 -139
  200. data/README +0 -211
  201. data/lib/yard/handlers/method_handler.rb +0 -27
  202. data/lib/yard/handlers/mixin_handler.rb +0 -16
  203. data/lib/yard/parser/statement_list.rb +0 -167
  204. data/lib/yard/tags/merbdoc_factory.rb +0 -47
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}MethodConditionHandler" do
4
+ before { parse_file :method_condition_handler_001, __FILE__ }
5
+
6
+ it "should not parse regular if blocks in methods" do
7
+ Registry.at('#b').should be_nil
8
+ end
9
+
10
+ it "should parse if/unless blocks in the form X if COND" do
11
+ Registry.at('#c').should_not be_nil
12
+ Registry.at('#d').should_not be_nil
13
+ end
14
+ end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe YARD::Handlers::MethodHandler do
3
+ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}MethodHandler" do
4
4
  before do
5
5
  log.enter_level(Logger::ERROR) do
6
6
  parse_file :method_handler_001, __FILE__
@@ -12,11 +12,11 @@ describe YARD::Handlers::MethodHandler do
12
12
  end
13
13
 
14
14
  it "should parse/add class methods (self.method2)" do
15
- P(:Foo).meths.should include(P("Foo::method2"))
15
+ P(:Foo).meths.should include(P("Foo.method2"))
16
16
  end
17
17
 
18
- it "should parse/add class methods from other namespaces (String::hello)" do
19
- P("String::hello").should_not be_nil
18
+ it "should parse/add class methods from other namespaces (String.hello)" do
19
+ P("String.hello").should be_instance_of(CodeObjects::MethodObject)
20
20
  end
21
21
 
22
22
  it "should allow punctuation in method names ([], ?, =~, <<, etc.)" do
@@ -32,4 +32,37 @@ describe YARD::Handlers::MethodHandler do
32
32
  it "should show that a method is explicitly defined (if it was originally defined implicitly by attribute)" do
33
33
  P('Foo#method1').is_explicit?.should == true
34
34
  end
35
- end
35
+
36
+ it "should handle parameters" do
37
+ P('Foo#[]').parameters.should == [['key', "'default'"]]
38
+ P('Foo#/').parameters.should == [['x', "File.new('x', 'w')"], ['y', '2']]
39
+ end
40
+
41
+ it "should handle opts = {} as parameter" do
42
+ P('Foo#optsmeth').parameters.should == [['x', nil], ['opts', '{}']]
43
+ end
44
+
45
+ it "should handle &block as parameter" do
46
+ P('Foo#blockmeth').parameters.should == [['x', nil], ['&block', nil]]
47
+ end
48
+
49
+ it "should handle overloads" do
50
+ meth = P('Foo#foo')
51
+
52
+ o1 = meth.tags(:overload).first
53
+ o1.name.should == :foo
54
+ o1.parameters.should == [[:a, nil], [:b, "1"]]
55
+ o1.tag(:return).type.should == "String"
56
+
57
+ o2 = meth.tags(:overload)[1]
58
+ o2.name.should == :foo
59
+ o2.parameters.should == [[:b, nil], [:c, nil]]
60
+ o2.tag(:return).type.should == "Fixnum"
61
+
62
+ o3 = meth.tags(:overload)[2]
63
+ o3.name.should == :foo
64
+ o3.parameters.should == [[:d, nil], [:e, nil]]
65
+ o3.docstring.should be_empty
66
+ o3.docstring.should be_blank
67
+ end
68
+ end
@@ -1,18 +1,22 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe YARD::Handlers::MixinHandler do
3
+ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}MixinHandler" do
4
4
  before { parse_file :mixin_handler_001, __FILE__ }
5
5
 
6
6
  it "should handle includes from classes or modules" do
7
- Registry.at(:X).mixins.should include(P(:A))
8
- Registry.at(:Y).mixins.should include(P(:A))
7
+ Registry.at(:X).instance_mixins.should include(P(:A))
8
+ Registry.at(:Y).instance_mixins.should include(P(:A))
9
+ end
10
+
11
+ it "should handle includes in class << self" do
12
+ Registry.at(:Y).class_mixins.should include(P(:A))
9
13
  end
10
14
 
11
15
  it "should handle includes for complex namespaces" do
12
16
  end
13
17
 
14
18
  it "should handle includes for modules that don't yet exist" do
15
- Registry.at(:X).mixins.should include(P(nil, :NOTEXIST))
19
+ Registry.at(:X).instance_mixins.should include(P(nil, :NOTEXIST))
16
20
  end
17
21
 
18
22
  it "should set the type of non-existing modules to :module" do
@@ -24,7 +28,11 @@ describe YARD::Handlers::MixinHandler do
24
28
  end
25
29
 
26
30
  it "should handle complex include statements" do
27
- P(:Y).mixins.should include(P('B::C'))
28
- P(:Y).mixins.should include(P(:B))
31
+ P(:Y).instance_mixins.should include(P('B::C'))
32
+ P(:Y).instance_mixins.should include(P(:B))
33
+ end
34
+
35
+ it "should treat a mixed in Constant by taking its value as the real object name" do
36
+ P(:Y).instance_mixins.should include(Registry.at('B::D'))
29
37
  end
30
- end
38
+ end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe YARD::Handlers::ModuleHandler do
3
+ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ModuleHandler" do
4
4
  before do
5
5
  Registry.clear
6
6
  parse_file :module_handler_001, __FILE__
@@ -22,4 +22,8 @@ describe YARD::Handlers::ModuleHandler do
22
22
  it "should handle complex module names" do
23
23
  Registry.at("A::B").should_not == nil
24
24
  end
25
+
26
+ it "should handle modules in the form ::ModName" do
27
+ Registry.at("Kernel").should_not be_nil
28
+ end
25
29
  end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe YARD::Handlers::Processor do
4
+ before do
5
+ @proc = Handlers::Processor.new
6
+ end
7
+
8
+ it "should start with public visibility" do
9
+ @proc.visibility.should == :public
10
+ end
11
+
12
+ it "should start in instance scope" do
13
+ @proc.scope.should == :instance
14
+ end
15
+
16
+ it "should start in root namespace" do
17
+ @proc.namespace.should == Registry.root
18
+ end
19
+ end
@@ -0,0 +1,90 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe YARD::Handlers::Ruby::Base, '#valid_handler?' do
4
+ include YARD::Parser::Ruby; AstNode
5
+
6
+ before do
7
+ Handlers::Ruby::Base.stub!(:inherited)
8
+ @processor = Handlers::Processor.new(nil, false, :ruby)
9
+ end
10
+
11
+ def valid(handler, stmt)
12
+ @processor.find_handlers(stmt).should include(handler)
13
+ end
14
+
15
+ def invalid(handler, stmt)
16
+ @processor.find_handlers(stmt).should_not include(handler)
17
+ end
18
+
19
+ it "should only handle Handlers inherited from Ruby::Base class" do
20
+ class IgnoredHandler < Handlers::Base
21
+ handles :list
22
+ end
23
+ class NotIgnoredHandler < Handlers::Ruby::Base
24
+ handles :list
25
+ end
26
+ Handlers::Base.stub!(:subclasses).and_return [IgnoredHandler, NotIgnoredHandler]
27
+ @processor.find_handlers(s()).should == [NotIgnoredHandler]
28
+ end
29
+
30
+ it "should handle string input (matches AstNode#source)" do
31
+ class StringHandler < Handlers::Ruby::Base
32
+ handles "x"
33
+ end
34
+ Handlers::Base.stub!(:subclasses).and_return [StringHandler]
35
+ ast = RubyParser.parse("if x == 2 then true end").ast
36
+ valid StringHandler, ast[0][0][0]
37
+ invalid StringHandler, ast[0][1]
38
+ end
39
+
40
+ it "should handle symbol input (matches AstNode#type)" do
41
+ class SymbolHandler < Handlers::Ruby::Base
42
+ handles :myNodeType
43
+ end
44
+ Handlers::Base.stub!(:subclasses).and_return [SymbolHandler]
45
+ valid SymbolHandler, s(:myNodeType, s(1, 2, 3))
46
+ invalid SymbolHandler, s(:NOTmyNodeType, s(1, 2, 3))
47
+ end
48
+
49
+ it "should handle regex input (matches AstNode#source)" do
50
+ class RegexHandler < Handlers::Ruby::Base
51
+ handles %r{^if x ==}
52
+ end
53
+ Handlers::Base.stub!(:subclasses).and_return [RegexHandler]
54
+ ast = RubyParser.parse("if x == 2 then true end").ast
55
+ valid RegexHandler, ast
56
+ invalid RegexHandler, ast[0][1]
57
+ end
58
+
59
+ it "should handle AstNode input (matches AST literally)" do
60
+ class ASTHandler < Handlers::Ruby::Base
61
+ handles s(:var_ref, s(:ident, "hello_world"))
62
+ end
63
+ Handlers::Base.stub!(:subclasses).and_return [ASTHandler]
64
+ valid ASTHandler, s(:var_ref, s(:ident, "hello_world"))
65
+ invalid ASTHandler, s(:var_ref, s(:ident, "NOTHELLOWORLD"))
66
+ end
67
+
68
+ it "should handle #method_call(:methname) on a valid AST" do
69
+ class MethCallHandler < Handlers::Ruby::Base
70
+ handles method_call(:meth)
71
+ end
72
+ Handlers::Base.stub!(:subclasses).and_return [MethCallHandler]
73
+ ast = RubyParser.parse(<<-"eof").ast
74
+ meth # 0
75
+ meth() # 1
76
+ meth(1,2,3) # 2
77
+ meth 1,2,3 # 3
78
+ NotMeth.meth # 4
79
+ NotMeth.meth { } # 5
80
+ NotMeth.meth do end # 6
81
+ NotMeth.meth 1, 2, 3 # 7
82
+ NotMeth.meth(1, 2, 3) # 8
83
+ NotMeth # 9
84
+ eof
85
+ (0..8).each do |i|
86
+ valid MethCallHandler, ast[i]
87
+ end
88
+ invalid MethCallHandler, ast[9]
89
+ end
90
+ end if RUBY19
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ include Parser::Ruby::Legacy
4
+
5
+ describe YARD::Handlers::Ruby::Legacy::Base, "#handles and inheritance" do
6
+ before do
7
+ Handlers::Ruby::Legacy::Base.stub!(:inherited)
8
+ Handlers::Ruby::Legacy::MixinHandler.stub!(:inherited) # fixes a Ruby1.9 issue
9
+ @processor = Handlers::Processor.new(nil, false, :ruby18)
10
+ end
11
+
12
+ def stmt(string)
13
+ Statement.new(TokenList.new(string))
14
+ end
15
+
16
+ it "should only handle Handlers inherited from Ruby::Legacy::Base class" do
17
+ class IgnoredHandler < Handlers::Base
18
+ handles "hello"
19
+ end
20
+ class NotIgnoredHandler < Handlers::Ruby::Legacy::Base
21
+ handles "hello"
22
+ end
23
+ Handlers::Base.stub!(:subclasses).and_return [IgnoredHandler, NotIgnoredHandler]
24
+ @processor.find_handlers(stmt("hello world")).should == [NotIgnoredHandler]
25
+ end
26
+
27
+ it "should handle a string input" do
28
+ class TestStringHandler < Handlers::Ruby::Legacy::Base
29
+ handles "hello"
30
+ end
31
+
32
+ TestStringHandler.handles?(stmt("hello world")).should be_true
33
+ TestStringHandler.handles?(stmt("nothello world")).should be_false
34
+ end
35
+
36
+ it "should handle regex input" do
37
+ class TestRegexHandler < Handlers::Ruby::Legacy::Base
38
+ handles /^nothello$/
39
+ end
40
+
41
+ TestRegexHandler.handles?(stmt("nothello")).should be_true
42
+ TestRegexHandler.handles?(stmt("not hello hello")).should be_false
43
+ end
44
+
45
+ it "should handle token input" do
46
+ class TestTokenHandler < Handlers::Ruby::Legacy::Base
47
+ handles TkMODULE
48
+ end
49
+
50
+ TestTokenHandler.handles?(stmt("module")).should be_true
51
+ TestTokenHandler.handles?(stmt("if")).should be_false
52
+ end
53
+ end
@@ -1,21 +1,27 @@
1
1
  require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
+ require 'stringio'
2
3
 
3
4
  include Handlers
4
5
 
5
6
  def undoc_error(code)
6
- mock = mock("parser")
7
- mock.stub!(:namespace).and_return(Registry.root)
8
- mock.stub!(:namespace=).and_return nil
9
- mock.stub!(:owner).and_return(Registry.root)
10
- mock.stub!(:owner=).and_return nil
11
- mock.stub!(:scope).and_return(:instance)
12
- mock.stub!(:scope=).and_return nil
13
- mock.stub!(:visibility).and_return(:public)
14
- mock.stub!(:visibility=).and_return nil
15
- mock.stub!(:file).and_return('<STDIN>')
16
- mock.stub!(:parse).and_return nil
17
- mock.stub!(:load_order_errors).and_return false
18
-
19
- c = self.class.described_type.new(mock, Parser::StatementList.new(code).first)
20
- lambda { c.process }.should raise_error(UndocumentableError)
21
- end
7
+ lambda { StubbedSourceParser.parse_string(code) }.should raise_error(Parser::UndocumentableError)
8
+ end
9
+
10
+ class StubbedProcessor < Processor
11
+ def process(statements)
12
+ statements.each_with_index do |stmt, index|
13
+ find_handlers(stmt).each do |handler|
14
+ handler.new(self, stmt).process
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ class StubbedSourceParser < Parser::SourceParser
21
+ self.parser_type = :ruby
22
+ def post_process
23
+ post = StubbedProcessor.new(@file, @load_order_errors, @parser_type)
24
+ post.process(@parser.enumerator)
25
+ end
26
+ end
27
+
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe YARD::Handlers::VisibilityHandler do
3
+ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}VisibilityHandler" do
4
4
  before { parse_file :visibility_handler_001, __FILE__ }
5
5
 
6
6
  it "should be able to set visibility to public" do
@@ -17,8 +17,8 @@ describe YARD::Handlers::VisibilityHandler do
17
17
  end
18
18
 
19
19
  it "should support parameters and only set visibility on those methods" do
20
- Registry['Testing#notpriv'].visibility.should == :public
21
- Registry['Testing#notpriv2'].visibility.should == :public
22
- Registry['Testing#notpriv?'].visibility.should == :public
20
+ Registry['Testing#notpriv'].visibility.should == :protected
21
+ Registry['Testing#notpriv2'].visibility.should == :protected
22
+ Registry['Testing#notpriv?'].visibility.should == :protected
23
23
  end
24
24
  end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe YARD::Handlers::YieldHandler do
3
+ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}YieldHandler" do
4
4
  before { parse_file :yield_handler_001, __FILE__ }
5
5
 
6
6
  it "should only parse yield blocks in methods" do
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ include YARD::Parser::Ruby
4
+
5
+ describe YARD::Parser::Ruby::AstNode, "#jump" do
6
+ it "should jump to the first specific inner node if found" do
7
+ ast = s(:paren, s(:paren, s(:params, s(s(:ident, "hi"), s(:ident, "bye")))))
8
+ ast.jump(:params)[0][0].type.should equal(:ident)
9
+ end
10
+
11
+ it "should return the original ast if no inner node is found" do
12
+ ast = s(:paren, s(:list, s(:list, s(s(:ident, "hi"), s(:ident, "bye")))))
13
+ ast.jump(:params).object_id.should == ast.object_id
14
+ end
15
+ end if RUBY19
@@ -0,0 +1,145 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
2
+
3
+ describe YARD::Parser::Ruby::Legacy::StatementList do
4
+ def stmt(code) YARD::Parser::Ruby::Legacy::StatementList.new(code).first end
5
+
6
+ it "should parse dangling block expressions" do
7
+ s = stmt <<-eof
8
+ if
9
+ foo
10
+ puts 'hi'
11
+ end
12
+ eof
13
+
14
+ s.tokens.to_s.should == "if foo"
15
+ s.block.to_s.should == "\n puts 'hi'\n end\n"
16
+
17
+ s = stmt <<-eof
18
+ if foo ||
19
+ bar
20
+ puts 'hi'
21
+ end
22
+ eof
23
+
24
+ s.tokens.to_s.should == "if foo || bar"
25
+ s.block.to_s.should == "\n puts 'hi'\n end\n"
26
+ end
27
+
28
+ it "should allow semicolons within parentheses" do
29
+ s = stmt "(foo; bar)"
30
+
31
+ s.tokens.to_s.should == "(foo; bar)"
32
+ s.block.to_s.should == ""
33
+ end
34
+
35
+ it "should allow block statements to be used as part of other block statements" do
36
+ s = stmt "while (foo; bar); foo = 12; end"
37
+
38
+ s.tokens.to_s.should == "while (foo; bar)"
39
+ s.block.to_s.should == " foo = 12; end\n"
40
+ end
41
+
42
+ it "should allow continued processing after a block" do
43
+ s = stmt "if foo; end.stuff"
44
+ s.tokens.to_s.should == "if foo"
45
+ s.block.to_s.should == " end.stuff\n"
46
+
47
+ s = stmt "if foo; end[stuff]"
48
+ s.tokens.to_s.should == "if foo"
49
+ s.block.to_s.should == " end[stuff]\n"
50
+
51
+ s = stmt "if foo; end.map do; 123; end"
52
+ s.tokens.to_s.should == "if foo"
53
+ s.block.to_s.should == " end.map do; 123; end\n"
54
+ end
55
+
56
+ it "should parse default arguments" do
57
+ s = stmt "def foo(bar, baz = 1, bang = 2); bar; end"
58
+ s.tokens.to_s.should == "def foo(bar, baz = 1, bang = 2)"
59
+ s.block.to_s.should == " bar; end\n"
60
+
61
+ s = stmt "def foo bar, baz = 1, bang = 2; bar; end"
62
+ s.tokens.to_s.should == "def foo bar, baz = 1, bang = 2"
63
+ s.block.to_s.should == " bar; end\n"
64
+
65
+ s = stmt "def foo bar , baz = 1 , bang = 2; bar; end"
66
+ s.tokens.to_s.should == "def foo bar , baz = 1 , bang = 2"
67
+ s.block.to_s.should == " bar; end\n"
68
+ end
69
+
70
+ it "should parse complex default arguments" do
71
+ s = stmt "def foo(bar, baz = File.new(1, 2), bang = 3); bar; end"
72
+ s.tokens.to_s.should == "def foo(bar, baz = File.new(1, 2), bang = 3)"
73
+ s.block.to_s.should == " bar; end\n"
74
+
75
+ s = stmt "def foo bar, baz = File.new(1, 2), bang = 3; bar; end"
76
+ s.tokens.to_s.should == "def foo bar, baz = File.new(1, 2), bang = 3"
77
+ s.block.to_s.should == " bar; end\n"
78
+
79
+ s = stmt "def foo bar , baz = File.new(1, 2) , bang = 3; bar; end"
80
+ s.tokens.to_s.should == "def foo bar , baz = File.new(1, 2) , bang = 3"
81
+ s.block.to_s.should == " bar; end\n"
82
+ end
83
+
84
+ it "should parse blocks with do/end" do
85
+ s = stmt <<-eof
86
+ foo do
87
+ puts 'hi'
88
+ end
89
+ eof
90
+
91
+ s.tokens.to_s.should == "foo "
92
+ s.block.to_s.should == "do\n puts 'hi'\n end\n"
93
+ end
94
+
95
+ it "should parse blocks with {}" do
96
+ s = stmt "x { y }"
97
+ s.tokens.to_s.should == "x "
98
+ s.block.to_s.should == "{ y }\n"
99
+
100
+ s = stmt "x() { y }"
101
+ s.tokens.to_s.should == "x() "
102
+ s.block.to_s.should == "{ y }\n"
103
+ end
104
+
105
+ it "should parse blocks with begin/end" do
106
+ s = stmt "begin xyz end"
107
+ s.tokens.to_s.should == ""
108
+ s.block.to_s.should == "begin xyz end\n"
109
+ end
110
+
111
+ it "should parse nested blocks" do
112
+ s = stmt "foo(:x) { baz(:y) { skippy } }"
113
+
114
+ s.tokens.to_s.should == "foo(:x) "
115
+ s.block.to_s.should == "{ baz(:y) { skippy } }\n"
116
+ end
117
+
118
+ it "should not parse hashes as blocks" do
119
+ s = stmt "x({})"
120
+ s.tokens.to_s.should == "x({})"
121
+ s.block.to_s.should == ""
122
+
123
+ s = stmt "x = {}"
124
+ s.tokens.to_s.should == "x = {}"
125
+ s.block.to_s.should == ""
126
+
127
+ s = stmt "x(y, {})"
128
+ s.tokens.to_s.should == "x(y, {})"
129
+ s.block.to_s.should == ""
130
+ end
131
+
132
+ it "should parse hashes in blocks with {}" do
133
+ s = stmt "x {x = {}}"
134
+
135
+ s.tokens.to_s.should == "x "
136
+ s.block.to_s.should == "{x = {}}\n"
137
+ end
138
+
139
+ it "should parse blocks with {} in hashes" do
140
+ s = stmt "[:foo, x {}]"
141
+
142
+ s.tokens.to_s.should == "[:foo, x {}]"
143
+ s.block.to_s.should == ""
144
+ end
145
+ end