yard 0.2.3 → 0.2.3.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.

Files changed (46) hide show
  1. data/.yardopts +12 -0
  2. data/README.markdown +20 -2
  3. data/Rakefile +3 -2
  4. data/lib/rubygems_plugin.rb +91 -0
  5. data/lib/yard.rb +2 -1
  6. data/lib/yard/cli/yardoc.rb +41 -9
  7. data/lib/yard/code_objects/base.rb +2 -12
  8. data/lib/yard/docstring.rb +19 -8
  9. data/lib/yard/generators/full_doc_generator.rb +2 -1
  10. data/lib/yard/generators/helpers/html_helper.rb +6 -2
  11. data/lib/yard/generators/tags_generator.rb +23 -2
  12. data/lib/yard/handlers/base.rb +6 -5
  13. data/lib/yard/parser/ruby/ast_node.rb +2 -1
  14. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +9 -1
  15. data/lib/yard/parser/ruby/legacy/statement.rb +24 -16
  16. data/lib/yard/parser/ruby/legacy/statement_list.rb +82 -13
  17. data/lib/yard/parser/ruby/legacy/token_list.rb +10 -2
  18. data/lib/yard/parser/ruby/ruby_parser.rb +1 -0
  19. data/lib/yard/parser/source_parser.rb +1 -5
  20. data/lib/yard/tags/library.rb +1 -1
  21. data/lib/yard/tags/overload_tag.rb +1 -0
  22. data/spec/cli/yardoc_spec.rb +33 -0
  23. data/spec/docstring_spec.rb +24 -0
  24. data/spec/generators/helpers/html_helper_spec.rb +104 -102
  25. data/spec/handlers/ruby/legacy/base_spec.rb +25 -0
  26. data/spec/parser/examples/parse_in_order_001.rb.txt +2 -0
  27. data/spec/parser/examples/parse_in_order_002.rb.txt +2 -0
  28. data/spec/parser/ruby/ast_node_spec.rb +13 -9
  29. data/spec/parser/ruby/legacy/statement_list_spec.rb +122 -44
  30. data/spec/parser/ruby/legacy/token_list_spec.rb +57 -23
  31. data/spec/parser/ruby/ruby_parser_spec.rb +53 -0
  32. data/spec/parser/source_parser_spec.rb +59 -16
  33. data/spec/spec_helper.rb +2 -4
  34. data/spec/tags/library_spec.rb +23 -0
  35. data/templates/default/deprecated/html/main.erb +5 -3
  36. data/templates/default/fulldoc/html/all_methods.erb +1 -1
  37. data/templates/default/fulldoc/html/all_namespaces.erb +1 -1
  38. data/templates/default/fulldoc/html/custom.css +1 -0
  39. data/templates/default/fulldoc/html/file.erb +1 -0
  40. data/templates/default/fulldoc/html/footer.erb +5 -0
  41. data/templates/default/fulldoc/html/header.erb +1 -0
  42. data/templates/default/fulldoc/html/html_head.erb +1 -0
  43. data/templates/default/fulldoc/html/index.erb +1 -1
  44. data/templates/default/fulldoc/html/style.css +6 -0
  45. data/templates/default/tags/html/see.erb +1 -1
  46. metadata +13 -5
@@ -50,4 +50,29 @@ describe YARD::Handlers::Ruby::Legacy::Base, "#handles and inheritance" do
50
50
  TestTokenHandler.handles?(stmt("module")).should be_true
51
51
  TestTokenHandler.handles?(stmt("if")).should be_false
52
52
  end
53
+
54
+ it "should parse a do/end or { } block with #parse_block" do
55
+ class MyBlockHandler < Handlers::Ruby::Legacy::Base
56
+ handles /\AmyMethod\b/
57
+ def process
58
+ parse_block(:owner => "test")
59
+ end
60
+ end
61
+
62
+ class MyBlockInnerHandler < Handlers::Ruby::Legacy::Base
63
+ handles "inner"
64
+ def self.reset; @@reached = false end
65
+ def self.reached?; @@reached ||= false end
66
+ def process; @@reached = true end
67
+ end
68
+
69
+ Handlers::Base.stub!(:subclasses).and_return [MyBlockHandler, MyBlockInnerHandler]
70
+ Parser::SourceParser.parser_type = :ruby18
71
+ Parser::SourceParser.parse_string "myMethod do inner end"
72
+ MyBlockInnerHandler.should be_reached
73
+ MyBlockInnerHandler.reset
74
+ Parser::SourceParser.parse_string "myMethod { inner }"
75
+ MyBlockInnerHandler.should be_reached
76
+ Parser::SourceParser.parser_type = :ruby
77
+ end
53
78
  end
@@ -0,0 +1,2 @@
1
+ class MyModule::MyClass
2
+ end
@@ -0,0 +1,2 @@
1
+ module MyModule
2
+ end
@@ -2,14 +2,18 @@ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
2
 
3
3
  include YARD::Parser::Ruby
4
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
5
+ if RUBY19
6
+ describe YARD::Parser::Ruby::AstNode do
7
+ describe "#jump" do
8
+ it "should jump to the first specific inner node if found" do
9
+ ast = s(:paren, s(:paren, s(:params, s(s(:ident, "hi"), s(:ident, "bye")))))
10
+ ast.jump(:params)[0][0].type.should equal(:ident)
11
+ end
10
12
 
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
13
+ it "should return the original ast if no inner node is found" do
14
+ ast = s(:paren, s(:list, s(:list, s(s(:ident, "hi"), s(:ident, "bye")))))
15
+ ast.jump(:params).object_id.should == ast.object_id
16
+ end
17
+ end
14
18
  end
15
- end if RUBY19
19
+ end
@@ -1,7 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
2
2
 
3
3
  describe YARD::Parser::Ruby::Legacy::StatementList do
4
- def stmt(code) YARD::Parser::Ruby::Legacy::StatementList.new(code).first end
4
+ def stmts(code) YARD::Parser::Ruby::Legacy::StatementList.new(code) end
5
+ def stmt(code) stmts(code).first end
5
6
 
6
7
  it "should parse dangling block expressions" do
7
8
  s = stmt <<-eof
@@ -11,8 +12,9 @@ describe YARD::Parser::Ruby::Legacy::StatementList do
11
12
  end
12
13
  eof
13
14
 
14
- s.tokens.to_s.should == "if foo"
15
- s.block.to_s.should == "\n puts 'hi'\n end\n"
15
+ s.tokens.to_s(true).should == "if\n foo\n ...\n end"
16
+ s.tokens.to_s.should == "if\n foo"
17
+ s.block.to_s.should == "puts 'hi'"
16
18
 
17
19
  s = stmt <<-eof
18
20
  if foo ||
@@ -21,64 +23,72 @@ eof
21
23
  end
22
24
  eof
23
25
 
24
- s.tokens.to_s.should == "if foo || bar"
25
- s.block.to_s.should == "\n puts 'hi'\n end\n"
26
+ s.tokens.to_s(true).should == "if foo ||\n bar\n ...\n end"
27
+ s.tokens.to_s.should == "if foo ||\n bar"
28
+ s.block.to_s.should == "puts 'hi'"
26
29
  end
27
30
 
28
31
  it "should allow semicolons within parentheses" do
29
32
  s = stmt "(foo; bar)"
30
33
 
31
- s.tokens.to_s.should == "(foo; bar)"
32
- s.block.to_s.should == ""
34
+ s.tokens.to_s(true).should == "(foo; bar)"
35
+ s.block.should be_nil
36
+ end
37
+
38
+ it "should allow for non-block statements" do
39
+ s = stmt "hello_world(1, 2, 3)"
40
+ s.tokens.to_s.should == "hello_world(1, 2, 3)"
41
+ s.block.should be_nil
33
42
  end
34
43
 
35
44
  it "should allow block statements to be used as part of other block statements" do
36
- s = stmt "while (foo; bar); foo = 12; end"
45
+ s = stmt "while (foo; bar); foo = 12; end; while"
37
46
 
47
+ s.tokens.to_s(true).should == "while (foo; bar); ... end"
38
48
  s.tokens.to_s.should == "while (foo; bar)"
39
- s.block.to_s.should == " foo = 12; end\n"
49
+ s.block.to_s.should == "foo = 12"
40
50
  end
41
51
 
42
52
  it "should allow continued processing after a block" do
43
53
  s = stmt "if foo; end.stuff"
44
- s.tokens.to_s.should == "if foo"
45
- s.block.to_s.should == " end.stuff\n"
54
+ s.tokens.to_s(true).should == "if foo; end.stuff"
55
+ s.block.to_s.should == ""
46
56
 
47
57
  s = stmt "if foo; end[stuff]"
48
- s.tokens.to_s.should == "if foo"
49
- s.block.to_s.should == " end[stuff]\n"
58
+ s.tokens.to_s(true).should == "if foo; end[stuff]"
59
+ s.block.to_s.should == ""
50
60
 
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"
61
+ s = stmt "if foo; hi end.map do; 123; end"
62
+ s.tokens.to_s(true).should == "if foo; ... end.map do; 123; end"
63
+ s.block.to_s.should == "hi"
54
64
  end
55
65
 
56
66
  it "should parse default arguments" do
57
67
  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"
68
+ s.tokens.to_s(true).should == "def foo(bar, baz = 1, bang = 2) ... end"
69
+ s.block.to_s.should == "bar"
60
70
 
61
71
  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"
72
+ s.tokens.to_s(true).should == "def foo bar, baz = 1, bang = 2; ... end"
73
+ s.block.to_s.should == "bar"
64
74
 
65
75
  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"
76
+ s.tokens.to_s(true).should == "def foo bar , baz = 1 , bang = 2; ... end"
77
+ s.block.to_s.should == "bar"
68
78
  end
69
79
 
70
80
  it "should parse complex default arguments" do
71
81
  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"
82
+ s.tokens.to_s(true).should == "def foo(bar, baz = File.new(1, 2), bang = 3) ... end"
83
+ s.block.to_s.should == "bar"
74
84
 
75
85
  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"
86
+ s.tokens.to_s(true).should == "def foo bar, baz = File.new(1, 2), bang = 3; ... end"
87
+ s.block.to_s.should == "bar"
78
88
 
79
89
  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"
90
+ s.tokens.to_s(true).should == "def foo bar , baz = File.new(1, 2) , bang = 3; ... end"
91
+ s.block.to_s.should == "bar"
82
92
  end
83
93
 
84
94
  it "should parse blocks with do/end" do
@@ -88,58 +98,126 @@ eof
88
98
  end
89
99
  eof
90
100
 
91
- s.tokens.to_s.should == "foo "
92
- s.block.to_s.should == "do\n puts 'hi'\n end\n"
101
+ s.tokens.to_s(true).should == "foo do\n ...\n end"
102
+ s.block.to_s.should == "puts 'hi'"
93
103
  end
94
104
 
95
105
  it "should parse blocks with {}" do
96
106
  s = stmt "x { y }"
97
- s.tokens.to_s.should == "x "
98
- s.block.to_s.should == "{ y }\n"
107
+ s.tokens.to_s(true).should == "x { ... }"
108
+ s.block.to_s.should == "y"
99
109
 
100
110
  s = stmt "x() { y }"
101
- s.tokens.to_s.should == "x() "
102
- s.block.to_s.should == "{ y }\n"
111
+ s.tokens.to_s(true).should == "x() { ... }"
112
+ s.block.to_s.should == "y"
103
113
  end
104
114
 
105
115
  it "should parse blocks with begin/end" do
106
116
  s = stmt "begin xyz end"
107
- s.tokens.to_s.should == ""
108
- s.block.to_s.should == "begin xyz end\n"
117
+ s.tokens.to_s(true).should == "begin ... end"
118
+ s.block.to_s.should == "xyz"
109
119
  end
110
120
 
111
121
  it "should parse nested blocks" do
112
122
  s = stmt "foo(:x) { baz(:y) { skippy } }"
113
123
 
114
- s.tokens.to_s.should == "foo(:x) "
115
- s.block.to_s.should == "{ baz(:y) { skippy } }\n"
124
+ s.tokens.to_s(true).should == "foo(:x) { ... }"
125
+ s.block.to_s.should == "baz(:y) { skippy }"
116
126
  end
117
127
 
118
128
  it "should not parse hashes as blocks" do
119
129
  s = stmt "x({})"
120
- s.tokens.to_s.should == "x({})"
130
+ s.tokens.to_s(true).should == "x({})"
121
131
  s.block.to_s.should == ""
122
132
 
123
133
  s = stmt "x = {}"
124
- s.tokens.to_s.should == "x = {}"
134
+ s.tokens.to_s(true).should == "x = {}"
125
135
  s.block.to_s.should == ""
126
136
 
127
137
  s = stmt "x(y, {})"
128
- s.tokens.to_s.should == "x(y, {})"
138
+ s.tokens.to_s(true).should == "x(y, {})"
129
139
  s.block.to_s.should == ""
130
140
  end
131
141
 
132
142
  it "should parse hashes in blocks with {}" do
133
143
  s = stmt "x {x = {}}"
134
144
 
135
- s.tokens.to_s.should == "x "
136
- s.block.to_s.should == "{x = {}}\n"
145
+ s.tokens.to_s(true).should == "x {...}"
146
+ s.block.to_s.should == "x = {}"
137
147
  end
138
148
 
139
149
  it "should parse blocks with {} in hashes" do
140
150
  s = stmt "[:foo, x {}]"
141
151
 
142
- s.tokens.to_s.should == "[:foo, x {}]"
152
+ s.tokens.to_s(true).should == "[:foo, x {}]"
143
153
  s.block.to_s.should == ""
144
154
  end
155
+
156
+ it "should handle multiple methods" do
157
+ s = stmt <<-eof
158
+ def %; end
159
+ def b; end
160
+ eof
161
+ s.to_s.should == "def %; end"
162
+ end
163
+
164
+ it "should handle nested methods" do
165
+ s = stmt <<-eof
166
+ def *(o) def +@; end
167
+ def ~@
168
+ end end
169
+ eof
170
+ s.tokens.to_s(true).should == "def *(o) ... end"
171
+ s.block.to_s.should == "def +@; end\n def ~@\n end"
172
+
173
+ s = stmts(<<-eof)
174
+ def /(other) 'hi' end
175
+ def method1
176
+ def dynamic; end
177
+ end
178
+ eof
179
+ s[1].to_s.should == "def method1\n def dynamic; end\n end"
180
+ end
181
+
182
+ it "should get comment line numbers" do
183
+ s = stmt <<-eof
184
+ # comment
185
+ # comment
186
+ # comment
187
+ def method; end
188
+ eof
189
+ s.comments.should == ["comment", "comment", "comment"]
190
+ s.comments_range.should == (1..3)
191
+
192
+ s = stmt <<-eof
193
+
194
+ # comment
195
+ # comment
196
+ def method; end
197
+ eof
198
+ s.comments.should == ["comment", "comment"]
199
+ s.comments_range.should == (2..3)
200
+
201
+ s = stmt <<-eof
202
+ # comment
203
+ # comment
204
+
205
+ def method; end
206
+ eof
207
+ s.comments.should == ["comment", "comment"]
208
+ s.comments_range.should == (1..2)
209
+
210
+ s = stmt <<-eof
211
+ # comment
212
+ def method; end
213
+ eof
214
+ s.comments.should == ["comment"]
215
+ s.comments_range.should == (1..1)
216
+
217
+ s = stmt <<-eof
218
+ def method; end # comment
219
+ eof
220
+ s.comments.should == ["comment"]
221
+ s.comments_range.should == (1..1)
222
+ end
145
223
  end
@@ -3,33 +3,67 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
3
3
  include YARD::Parser::Ruby::Legacy
4
4
  include YARD::Parser::Ruby::Legacy::RubyToken
5
5
 
6
- describe YARD::Parser::Ruby::Legacy::TokenList, "#initialize / #push" do
7
- it "should accept a tokenlist (via constructor or push)" do
8
- lambda { TokenList.new(TokenList.new) }.should_not raise_error(ArgumentError)
9
- TokenList.new.push(TokenList.new("x = 2")).size.should == 6
10
- end
6
+ describe YARD::Parser::Ruby::Legacy::TokenList do
7
+ describe "#initialize / #push" do
8
+ it "should accept a tokenlist (via constructor or push)" do
9
+ lambda { TokenList.new(TokenList.new) }.should_not raise_error(ArgumentError)
10
+ TokenList.new.push(TokenList.new("x = 2")).size.should == 6
11
+ end
11
12
 
12
- it "accept a token (via constructor or push)" do
13
- lambda { TokenList.new(Token.new(0, 0)) }.should_not raise_error(ArgumentError)
14
- TokenList.new.push(Token.new(0, 0), Token.new(1, 1)).size.should == 2
15
- end
13
+ it "accept a token (via constructor or push)" do
14
+ lambda { TokenList.new(Token.new(0, 0)) }.should_not raise_error(ArgumentError)
15
+ TokenList.new.push(Token.new(0, 0), Token.new(1, 1)).size.should == 2
16
+ end
16
17
 
17
- it "should accept a string and parse it as code (via constructor or push)" do
18
- lambda { TokenList.new("x = 2") }.should_not raise_error(ArgumentError)
19
- x = TokenList.new
20
- x.push("x", "=", "2")
21
- x.size.should == 6
22
- x.to_s.should == "x\n=\n2\n"
23
- end
18
+ it "should accept a string and parse it as code (via constructor or push)" do
19
+ lambda { TokenList.new("x = 2") }.should_not raise_error(ArgumentError)
20
+ x = TokenList.new
21
+ x.push("x", "=", "2")
22
+ x.size.should == 6
23
+ x.to_s.should == "x\n=\n2\n"
24
+ end
24
25
 
25
- it "should not accept any other input" do
26
- lambda { TokenList.new(:notcode) }.should raise_error(ArgumentError)
26
+ it "should not accept any other input" do
27
+ lambda { TokenList.new(:notcode) }.should raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should not interpolate string data" do
31
+ x = TokenList.new('x = "hello #{world}"')
32
+ x.size.should == 6
33
+ x[4].class.should == TkDSTRING
34
+ x.to_s.should == 'x = "hello #{world}"' + "\n"
35
+ end
27
36
  end
28
37
 
29
- it "should not interpolate string data" do
30
- x = TokenList.new('x = "hello #{world}"')
31
- x.size.should == 6
32
- x[4].class.should == TkDSTRING
33
- x.to_s.should == 'x = "hello #{world}"' + "\n"
38
+ describe '#to_s' do
39
+ before do
40
+ @t = TokenList.new
41
+ @t << TkDEF.new(1, 1, "def")
42
+ @t << TkSPACE.new(1, 1)
43
+ @t << TkIDENTIFIER.new(1, 1, "x")
44
+ @t << TkStatementEnd.new(1, 1)
45
+ @t << TkSEMICOLON.new(1, 1) << TkSPACE.new(1, 1)
46
+ @t << TkBlockContents.new(1, 1)
47
+ @t << TkSPACE.new(1, 1) << TkEND.new(1, 1, "end")
48
+ @t[0].set_text "def"
49
+ @t[1].set_text " "
50
+ @t[2].set_text "x"
51
+ @t[4].set_text ";"
52
+ @t[5].set_text " "
53
+ @t[7].set_text " "
54
+ @t[8].set_text "end"
55
+ end
56
+
57
+ it "should only show the statement portion of the tokens by default" do
58
+ @t.to_s.should == "def x"
59
+ end
60
+
61
+ it "should show ... for the block token if all of the tokens are shown" do
62
+ @t.to_s(true).should == "def x; ... end"
63
+ end
64
+
65
+ it "should ignore ... if show_block = false" do
66
+ @t.to_s(true, false).should == "def x; end"
67
+ end
34
68
  end
35
69
  end
@@ -0,0 +1,53 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ if RUBY19
4
+ describe YARD::Parser::Ruby::RubyParser do
5
+ def stmt(stmt)
6
+ YARD::Parser::Ruby::RubyParser.new(stmt, nil).parse.root.first
7
+ end
8
+
9
+ describe '#parse' do
10
+ it "should get comment line numbers" do
11
+ s = stmt <<-eof
12
+ # comment
13
+ # comment
14
+ # comment
15
+ def method; end
16
+ eof
17
+ s.comments.should == "comment\ncomment\ncomment"
18
+ s.comments_range.should == (1..3)
19
+
20
+ s = stmt <<-eof
21
+
22
+ # comment
23
+ # comment
24
+ def method; end
25
+ eof
26
+ s.comments.should == "comment\ncomment"
27
+ s.comments_range.should == (2..3)
28
+
29
+ s = stmt <<-eof
30
+ # comment
31
+ # comment
32
+
33
+ def method; end
34
+ eof
35
+ s.comments.should == "comment\ncomment"
36
+ s.comments_range.should == (1..2)
37
+
38
+ s = stmt <<-eof
39
+ # comment
40
+ def method; end
41
+ eof
42
+ s.comments.should == "comment"
43
+ s.comments_range.should == (1..1)
44
+
45
+ s = stmt <<-eof
46
+ def method; end # comment
47
+ eof
48
+ s.comments.should == "comment"
49
+ s.comments_range.should == (1..1)
50
+ end
51
+ end
52
+ end
53
+ end