yard 0.2.3.3 → 0.2.3.4

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/README.markdown CHANGED
@@ -1,4 +1,4 @@
1
- YARD Release 0.2.3.3 (July 26th 2009)
1
+ YARD Release 0.2.3.4 (August 7th 2009)
2
2
  =====================================
3
3
 
4
4
  **Homepage**: [http://yard.rubyforge.org](http://yard.rubyforge.org)
data/Rakefile CHANGED
@@ -26,6 +26,7 @@ desc "Run all specs"
26
26
  Spec::Rake::SpecTask.new("specs") do |t|
27
27
  $DEBUG = true if ENV['DEBUG']
28
28
  t.spec_opts = ["--format", "specdoc", "--colour"]
29
+ t.spec_opts += ["--require", File.join(File.dirname(__FILE__), 'spec', 'spec_helper')]
29
30
  t.spec_files = Dir["spec/**/*_spec.rb"].sort
30
31
  t.rcov = true if ENV['RCOV']
31
32
  t.rcov_opts = ['-x', '_spec\.rb$,spec_helper\.rb$']
@@ -14,6 +14,7 @@ class Gem::Specification
14
14
  @has_rdoc == 'yard'
15
15
  end
16
16
 
17
+ undef has_rdoc? # redefining
17
18
  def has_rdoc?
18
19
  @has_rdoc && @has_rdoc != 'yard'
19
20
  end
@@ -53,6 +54,7 @@ class Gem::DocManager
53
54
  Dir.chdir(old_pwd)
54
55
  end
55
56
 
57
+ undef setup_rdoc # redefining
56
58
  def setup_rdoc
57
59
  if File.exist?(@doc_dir) && !File.writable?(@doc_dir) then
58
60
  raise Gem::FilePermissionError.new(@doc_dir)
@@ -77,9 +79,9 @@ class Gem::DocManager
77
79
  @@install_ri_yard_orig.bind(self).call if @spec.has_rdoc?
78
80
  end
79
81
  @@install_ri_yard_orig = instance_method(:install_ri)
82
+ undef install_ri # redefining
80
83
  alias install_ri install_ri_yard
81
84
 
82
-
83
85
  def install_rdoc_yard
84
86
  if @spec.has_rdoc?
85
87
  @@install_rdoc_yard_orig.bind(self).call
@@ -88,5 +90,6 @@ class Gem::DocManager
88
90
  end
89
91
  end
90
92
  @@install_rdoc_yard_orig = instance_method(:install_rdoc)
93
+ undef install_rdoc # redefining
91
94
  alias install_rdoc install_rdoc_yard
92
95
  end
data/lib/yard.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module YARD
2
- VERSION = "0.2.3.3"
2
+ VERSION = "0.2.3.4"
3
3
  ROOT = File.dirname(__FILE__)
4
4
  TEMPLATE_ROOT = File.join(File.dirname(__FILE__), '..', 'templates')
5
5
 
@@ -7,6 +7,9 @@ module YARD
7
7
  def self.parse_string(*args) Parser::SourceParser.parse_string(*args) end
8
8
  end
9
9
 
10
+ # Ruby 1.9.2 removes '.' which is not exactly a good idea
11
+ $LOAD_PATH.push('.') if RUBY_VERSION >= '1.9.2'
12
+
10
13
  # Keep track of Ruby version for compatibility code
11
14
  RUBY19, RUBY18 = *(RUBY_VERSION >= "1.9" ? [true, false] : [false, true])
12
15
 
data/lib/yard/autoload.rb CHANGED
@@ -124,10 +124,10 @@ module YARD
124
124
  end
125
125
 
126
126
  autoload :AstNode, __p('parser/ruby/ast_node')
127
- autoload :ParserSyntaxError, __p('parser/ruby/ruby_parser')
128
127
  autoload :RubyParser, __p('parser/ruby/ruby_parser')
129
128
  end
130
129
 
130
+ autoload :ParserSyntaxError, __p('parser/source_parser')
131
131
  autoload :SourceParser, __p('parser/source_parser')
132
132
  autoload :UndocumentableError, __p('parser/source_parser')
133
133
  end
@@ -28,6 +28,8 @@ module YARD
28
28
  end
29
29
  end
30
30
  end
31
+
32
+ private
31
33
 
32
34
  # The string value of a token. For example, the return value for the symbol :sym
33
35
  # would be :sym. The return value for a string "foo #{bar}" would be the literal
@@ -3,8 +3,6 @@ require 'ripper'
3
3
  module YARD
4
4
  module Parser
5
5
  module Ruby
6
- class ParserSyntaxError < UndocumentableError; end
7
-
8
6
  class RubyParser < Ripper
9
7
  attr_reader :ast, :charno, :comments, :file, :tokens
10
8
  alias root ast
@@ -59,7 +57,7 @@ module YARD
59
57
  :for => "for",
60
58
  :hash => :lbrace,
61
59
  :if => "if",
62
- :lambda => "lambda",
60
+ :lambda => [:tlambda, "lambda"],
63
61
  :module => "module",
64
62
  :next => "next",
65
63
  :paren => :lparen,
@@ -234,6 +232,10 @@ module YARD
234
232
  visit_event_arr AstNode.new(:string_literal, args)
235
233
  end
236
234
 
235
+ def on_lambda(*args)
236
+ visit_event_arr AstNode.new(:lambda, args)
237
+ end
238
+
237
239
  def on_string_content(*args)
238
240
  AstNode.new(:string_content, args, listline: lineno..lineno, listchar: charno..charno)
239
241
  end
@@ -4,6 +4,7 @@ require 'continuation' unless RUBY18
4
4
  module YARD
5
5
  module Parser
6
6
  class UndocumentableError < Exception; end
7
+ class ParserSyntaxError < UndocumentableError; end
7
8
  class LoadOrderError < Exception; end
8
9
 
9
10
  # Responsible for parsing a source file into the namespace
@@ -84,6 +85,10 @@ module YARD
84
85
  @parser = parse_statements(content)
85
86
  post_process
86
87
  @parser
88
+ rescue ArgumentError, NotImplementedError => e
89
+ log.warn("Cannot parse `#{file}': #{e.message}")
90
+ rescue ParserSyntaxError => e
91
+ log.warn(e.message.capitalize)
87
92
  end
88
93
 
89
94
  def tokenize(content)
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe YARD::CodeObjects::ClassObject do
4
- before do
4
+ before(:all) do
5
5
  Registry.clear
6
6
  @mixin = ModuleObject.new(:root, :SomeMixin)
7
7
  @mixin2 = ModuleObject.new(:root, :SomeMixin2)
@@ -27,7 +27,7 @@ describe YARD::CodeObjects::ClassObject do
27
27
  end
28
28
 
29
29
  describe YARD::CodeObjects::ClassObject, "#meths / #inherited_meths" do
30
- before do
30
+ before(:all) do
31
31
  Registry.clear
32
32
 
33
33
  Parser::SourceParser.parse_string <<-eof
@@ -89,7 +89,7 @@ describe YARD::CodeObjects::ClassObject, "#meths / #inherited_meths" do
89
89
  end
90
90
 
91
91
  describe YARD::CodeObjects::ClassObject, "#constants / #inherited_constants" do
92
- before do
92
+ before(:all) do
93
93
  Registry.clear
94
94
 
95
95
  Parser::SourceParser.parse_string <<-eof
@@ -1,18 +1,15 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}AliasHandler" do
4
- before do
5
- Registry.clear
6
- parse_file :alias_handler_001, __FILE__
7
- end
4
+ before(:all) { parse_file :alias_handler_001, __FILE__ }
8
5
 
9
6
  it "should throw alias into namespace object list" do
10
7
  P(:A).aliases[P("A#b")].should == :a
11
8
  end
12
9
 
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)
10
+ ['c', 'd?', '[]', '[]=', '-@', '%', '*'].each do |a|
11
+ it "should handle the Ruby 'alias' keyword syntax for method ##{a}" do
12
+ P('A#' + a).should be_instance_of(CodeObjects::MethodObject)
16
13
  end
17
14
  end
18
15
 
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}AttributeHandler" do
4
- before { parse_file :attribute_handler_001, __FILE__ }
4
+ before(:all) { parse_file :attribute_handler_001, __FILE__ }
5
5
 
6
6
  def read_write(namespace, name, read, write, scope = :instance)
7
7
  rname, wname = namespace.to_s+"#"+name.to_s, namespace.to_s+"#"+name.to_s+"="
@@ -1,10 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ClassConditionHandler" do
4
- before do
5
- Registry.clear
6
- parse_file :class_condition_handler_001, __FILE__
7
- end
4
+ before(:all) { parse_file :class_condition_handler_001, __FILE__ }
8
5
 
9
6
  def verify_method(*names)
10
7
  names.each {|name| Registry.at("A##{name}").should_not be_nil }
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ClassHandler" do
4
- before { parse_file :class_handler_001, __FILE__ }
4
+ before(:all) { parse_file :class_handler_001, __FILE__ }
5
5
 
6
6
  it "should parse a class block with docstring" do
7
7
  P("A").docstring.should == "Docstring"
@@ -36,12 +36,6 @@ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ClassHandler" do
36
36
  P('B::A').superclass.should == P('A')
37
37
  end
38
38
 
39
- it "should raise an UndocumentableError if the class is invalid" do
40
- ["CallMethod('test')", "VSD^#}}", 'not.aclass', 'self'].each do |klass|
41
- undoc_error "class #{klass}; end"
42
- end
43
- end
44
-
45
39
  it "should handle class definitions in the form ::ClassName" do
46
40
  Registry.at("MyRootClass").should_not be_nil
47
41
  end
@@ -65,15 +59,32 @@ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ClassHandler" do
65
59
  P('Q::Logger').superclass.should == P(:Logger)
66
60
  end
67
61
 
68
- it "should raise an UndocumentableError if the superclass is invalid but it should create the class." do
69
- ['@@INVALID', 'hi', '$MYCLASS', 'AnotherClass.new'].each do |klass|
70
- Registry.clear
71
- undoc_error "class A < #{klass}; end"
72
- Registry.at('A').should_not be_nil
62
+ ["CallMethod('test')", "VSD^#}}", 'not.aclass', 'self'].each do |klass|
63
+ it "should raise an UndocumentableError for invalid class '#{klass}'" do
64
+ with_parser(:ruby18) { undoc_error "class #{klass}; end" }
65
+ end
66
+ end
67
+
68
+ ['@@INVALID', 'hi', '$MYCLASS', 'AnotherClass.new'].each do |klass|
69
+ it "should raise an UndocumentableError for invalid superclass '#{klass}' but it should create the class." do
70
+ YARD::CodeObjects::ClassObject.should_receive(:new).with(Registry.root, 'A')
71
+ with_parser(:ruby18) { undoc_error "class A < #{klass}; end" }
73
72
  Registry.at('A').superclass.should == P(:Object)
74
73
  end
75
74
  end
76
75
 
76
+ ['not.aclass', 'self', 'AnotherClass.new'].each do |klass|
77
+ it "should raise an UndocumentableError if the constant class reference 'class << SomeConstant' does not point to a valid class name" do
78
+ with_parser(:ruby18) do
79
+ undoc_error <<-eof
80
+ CONST = #{klass}
81
+ class << CONST; end
82
+ eof
83
+ end
84
+ Registry.at(klass).should be_nil
85
+ end
86
+ end
87
+
77
88
  it "should document 'class << SomeConstant' by using SomeConstant's value as a reference to the real class name" do
78
89
  Registry.at('String.classmethod').should_not be_nil
79
90
  end
@@ -82,17 +93,6 @@ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ClassHandler" do
82
93
  Registry.at('Symbol.toString').should_not be_nil
83
94
  end
84
95
 
85
- it "should raise an UndocumentableError if the constant class reference 'class << SomeConstant' does not point to a valid class name" do
86
- ['not.aclass', 'self', 'AnotherClass.new'].each do |klass|
87
- Registry.clear
88
- undoc_error <<-eof
89
- CONST = #{klass}
90
- class << CONST; end
91
- eof
92
- Registry.at(klass).should be_nil
93
- end
94
- end
95
-
96
96
  it "should document 'class Exception' without running into superclass issues" do
97
97
  Parser::SourceParser.parse_string <<-eof
98
98
  class Exception
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ClassVariableHandler" do
4
- before { parse_file :class_variable_handler_001, __FILE__ }
4
+ before(:all) { parse_file :class_variable_handler_001, __FILE__ }
5
5
 
6
6
  it "should not parse class variables inside methods" do
7
7
  Registry.at("A::B::@@somevar").source.should == "@@somevar = \"hello\""
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ConstantHandler" do
4
- before { parse_file :constant_handler_001, __FILE__ }
4
+ before(:all) { parse_file :constant_handler_001, __FILE__ }
5
5
 
6
6
  it "should not parse constants inside methods" do
7
7
  Registry.at("A::B::SOMECONSTANT").source.should == "SOMECONSTANT= \"hello\""
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ExceptionHandler" do
4
- before { parse_file :exception_handler_001, __FILE__ }
4
+ before(:all) { parse_file :exception_handler_001, __FILE__ }
5
5
 
6
6
  it "should not document an exception outside of a method" do
7
7
  P('Testing').has_tag?(:raise).should == false
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ExtendHandler" do
4
- before { parse_file :extend_handler_001, __FILE__ }
4
+ before(:all) { parse_file :extend_handler_001, __FILE__ }
5
5
 
6
6
  it "should include modules at class scope" do
7
7
  Registry.at(:B).class_mixins.should == [P(:A)]
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}MethodConditionHandler" do
4
- before { parse_file :method_condition_handler_001, __FILE__ }
4
+ before(:all) { parse_file :method_condition_handler_001, __FILE__ }
5
5
 
6
6
  it "should not parse regular if blocks in methods" do
7
7
  Registry.at('#b').should be_nil
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}MethodHandler" do
4
- before do
4
+ before(:all) do
5
5
  log.enter_level(Logger::ERROR) do
6
6
  parse_file :method_handler_001, __FILE__
7
7
  end
@@ -19,8 +19,8 @@ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}MethodHandler" do
19
19
  P("String.hello").should be_instance_of(CodeObjects::MethodObject)
20
20
  end
21
21
 
22
- it "should allow punctuation in method names ([], ?, =~, <<, etc.)" do
23
- [:[], :[]=, :allowed?, :/, :=~, :==, :`, :|, :*, :&, :%, :'^', :-@, :+@, :'~@'].each do |name|
22
+ [:[], :[]=, :allowed?, :/, :=~, :==, :`, :|, :*, :&, :%, :'^', :-@, :+@, :'~@'].each do |name|
23
+ it "should allow valid method #{name}" do
24
24
  Registry.at("Foo##{name}").should_not be_nil
25
25
  end
26
26
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}MixinHandler" do
4
- before { parse_file :mixin_handler_001, __FILE__ }
4
+ before(:all) { parse_file :mixin_handler_001, __FILE__ }
5
5
 
6
6
  it "should handle includes from classes or modules" do
7
7
  Registry.at(:X).instance_mixins.should include(P(:A))
@@ -24,7 +24,7 @@ describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}MixinHandler" do
24
24
  end
25
25
 
26
26
  it "should handle includes with multiple parameters" do
27
- Registry.at(:X)
27
+ Registry.at(:X).should_not be_nil
28
28
  end
29
29
 
30
30
  it "should handle complex include statements" do
@@ -1,10 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}ModuleHandler" do
4
- before do
5
- Registry.clear
6
- parse_file :module_handler_001, __FILE__
7
- end
4
+ before(:all) { parse_file :module_handler_001, __FILE__ }
8
5
 
9
6
  it "should parse a module block" do
10
7
  Registry.at(:ModName).should_not == nil
@@ -7,6 +7,13 @@ def undoc_error(code)
7
7
  lambda { StubbedSourceParser.parse_string(code) }.should raise_error(Parser::UndocumentableError)
8
8
  end
9
9
 
10
+ def with_parser(parser_type, &block)
11
+ tmp = StubbedSourceParser.parser_type
12
+ StubbedSourceParser.parser_type = parser_type
13
+ yield
14
+ StubbedSourceParser.parser_type = tmp
15
+ end
16
+
10
17
  class StubbedProcessor < Processor
11
18
  def process(statements)
12
19
  statements.each_with_index do |stmt, index|
@@ -18,7 +25,7 @@ class StubbedProcessor < Processor
18
25
  end
19
26
 
20
27
  class StubbedSourceParser < Parser::SourceParser
21
- self.parser_type = :ruby
28
+ StubbedSourceParser.parser_type = :ruby
22
29
  def post_process
23
30
  post = StubbedProcessor.new(@file, @load_order_errors, @parser_type)
24
31
  post.process(@parser.enumerator)
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}VisibilityHandler" do
4
- before { parse_file :visibility_handler_001, __FILE__ }
4
+ before(:all) { parse_file :visibility_handler_001, __FILE__ }
5
5
 
6
6
  it "should be able to set visibility to public" do
7
7
  Registry.at("Testing#pub").visibility.should == :public
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}YieldHandler" do
4
- before { parse_file :yield_handler_001, __FILE__ }
4
+ before(:all) { parse_file :yield_handler_001, __FILE__ }
5
5
 
6
6
  it "should only parse yield blocks in methods" do
7
7
  P(:Testing).tag(:yield).should be_nil
@@ -48,6 +48,25 @@ if RUBY19
48
48
  s.comments.should == "comment"
49
49
  s.comments_range.should == (1..1)
50
50
  end
51
+
52
+ it "should handle 1.9 lambda syntax with args" do
53
+ src = "->(a,b,c=1,*args,&block) { hello_world }"
54
+ stmt(src).source.should == src
55
+ end
56
+
57
+ it "should handle 1.9 lambda syntax" do
58
+ src = "-> { hello_world }"
59
+ stmt(src).source.should == src
60
+ end
61
+
62
+ it "should handle standard lambda syntax" do
63
+ src = "lambda { hello_world }"
64
+ stmt(src).source.should == src
65
+ end
66
+
67
+ it "should throw a ParserSyntaxError on invalid code" do
68
+ lambda { stmt("Foo, bar.") }.should raise_error(YARD::Parser::ParserSyntaxError)
69
+ end
51
70
  end
52
71
  end
53
72
  end
@@ -68,4 +68,24 @@ describe YARD::Parser::SourceParser do
68
68
  msgs[5].should =~ /Object MyModule successfully resolved/
69
69
  end
70
70
  end
71
+
72
+ describe '#parse_statements' do
73
+ it "should display a warning for C/C++ files" do
74
+ log.should_receive(:warn).with(/no support/)
75
+ YARD::Parser::SourceParser.parse_string("int main() { }", :c)
76
+ end
77
+
78
+ it "should display a warning for invalid parser type" do
79
+ log.should_receive(:warn).with(/unrecognized file/)
80
+ YARD::Parser::SourceParser.parse_string("int main() { }", :d)
81
+ end
82
+
83
+ if RUBY19
84
+ it "should display a warning for a syntax error (with new parser)" do
85
+ err_msg = "Syntax error in `(stdin)`:(1,3): syntax error, unexpected $undefined, expecting $end"
86
+ log.should_receive(:warn).with(err_msg)
87
+ YARD::Parser::SourceParser.parse_string("$$$", :ruby)
88
+ end
89
+ end
90
+ end
71
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3.3
4
+ version: 0.2.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loren Segal
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-26 00:00:00 -04:00
12
+ date: 2009-08-07 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15