yard 0.6.4 → 0.6.5
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/ChangeLog +341 -0
- data/LICENSE +1 -1
- data/README.md +31 -6
- data/Rakefile +22 -3
- data/docs/Tags.md +5 -1
- data/docs/WhatsNew.md +18 -1
- data/lib/rubygems_plugin.rb +3 -99
- data/lib/yard.rb +1 -1
- data/lib/yard/autoload.rb +37 -35
- data/lib/yard/cli/config.rb +25 -2
- data/lib/yard/cli/graph.rb +1 -1
- data/lib/yard/cli/yardoc.rb +4 -0
- data/lib/yard/code_objects/base.rb +17 -9
- data/lib/yard/code_objects/method_object.rb +0 -9
- data/lib/yard/code_objects/proxy.rb +6 -0
- data/lib/yard/docstring.rb +5 -0
- data/lib/yard/handlers/base.rb +3 -1
- data/lib/yard/handlers/processor.rb +1 -1
- data/lib/yard/handlers/ruby/alias_handler.rb +9 -8
- data/lib/yard/handlers/ruby/class_handler.rb +3 -3
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +9 -7
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -0
- data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +21 -0
- data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
- data/lib/yard/handlers/ruby/method_handler.rb +7 -0
- data/lib/yard/handlers/ruby/private_constant_handler.rb +36 -0
- data/lib/yard/parser/ruby/ast_node.rb +41 -24
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +3 -0
- data/lib/yard/parser/ruby/legacy/statement.rb +2 -0
- data/lib/yard/parser/ruby/legacy/statement_list.rb +27 -4
- data/lib/yard/parser/ruby/ruby_parser.rb +71 -36
- data/lib/yard/parser/source_parser.rb +11 -10
- data/lib/yard/registry.rb +62 -24
- data/lib/yard/registry_store.rb +18 -5
- data/lib/yard/rubygems/doc_manager.rb +75 -0
- data/lib/yard/rubygems/specification.rb +23 -0
- data/lib/yard/serializers/process_serializer.rb +1 -1
- data/lib/yard/serializers/yardoc_serializer.rb +7 -2
- data/lib/yard/server/commands/display_object_command.rb +1 -1
- data/lib/yard/server/commands/library_command.rb +2 -2
- data/lib/yard/tags/default_factory.rb +1 -1
- data/lib/yard/tags/library.rb +2 -2
- data/lib/yard/templates/helpers/base_helper.rb +19 -0
- data/lib/yard/templates/helpers/html_helper.rb +22 -9
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +28 -0
- data/lib/yard/templates/helpers/markup_helper.rb +14 -22
- data/lib/yard/templates/template.rb +1 -1
- data/spec/cli/config_spec.rb +20 -0
- data/spec/cli/yardoc_spec.rb +12 -0
- data/spec/code_objects/base_spec.rb +13 -0
- data/spec/code_objects/proxy_spec.rb +9 -0
- data/spec/config_spec.rb +4 -1
- data/spec/docstring_spec.rb +5 -0
- data/spec/handlers/alias_handler_spec.rb +14 -1
- data/spec/handlers/attribute_handler_spec.rb +1 -1
- data/spec/handlers/base_spec.rb +21 -21
- data/spec/handlers/class_condition_handler_spec.rb +1 -1
- data/spec/handlers/class_handler_spec.rb +1 -1
- data/spec/handlers/class_variable_handler_spec.rb +1 -1
- data/spec/handlers/constant_handler_spec.rb +2 -2
- data/spec/handlers/examples/alias_handler_001.rb.txt +14 -0
- data/spec/handlers/examples/method_handler_001.rb.txt +6 -0
- data/spec/handlers/examples/module_handler_001.rb.txt +4 -0
- data/spec/handlers/examples/private_constant_handler_001.rb.txt +8 -0
- data/spec/handlers/exception_handler_spec.rb +1 -1
- data/spec/handlers/extend_handler_spec.rb +1 -1
- data/spec/handlers/method_condition_handler_spec.rb +1 -1
- data/spec/handlers/method_handler_spec.rb +7 -1
- data/spec/handlers/mixin_handler_spec.rb +1 -1
- data/spec/handlers/module_handler_spec.rb +5 -1
- data/spec/handlers/private_constant_handler_spec.rb +24 -0
- data/spec/handlers/process_handler_spec.rb +1 -1
- data/spec/handlers/ruby/base_spec.rb +4 -4
- data/spec/handlers/visibility_handler_spec.rb +1 -1
- data/spec/handlers/yield_handler_spec.rb +1 -1
- data/spec/parser/base_spec.rb +3 -5
- data/spec/parser/c_parser_spec.rb +1 -1
- data/spec/parser/ruby/ast_node_spec.rb +23 -26
- data/spec/parser/ruby/legacy/statement_list_spec.rb +9 -0
- data/spec/parser/ruby/ruby_parser_spec.rb +179 -177
- data/spec/parser/source_parser_spec.rb +41 -7
- data/spec/rake/yardoc_task_spec.rb +3 -3
- data/spec/registry_spec.rb +52 -0
- data/spec/registry_store_spec.rb +71 -1
- data/spec/serializers/yardoc_serializer_spec.rb +18 -7
- data/spec/server/rack_adapter_spec.rb +2 -2
- data/spec/spec_helper.rb +10 -0
- data/spec/tags/default_factory_spec.rb +122 -120
- data/spec/templates/helpers/base_helper_spec.rb +38 -14
- data/spec/templates/helpers/html_helper_spec.rb +19 -0
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +10 -6
- data/spec/templates/helpers/markup_helper_spec.rb +21 -5
- data/templates/default/class/dot/superklass.erb +1 -1
- data/templates/default/docstring/setup.rb +1 -1
- data/templates/default/fulldoc/html/css/style.css +12 -4
- data/templates/default/fulldoc/html/js/app.js +1 -1
- data/templates/default/fulldoc/html/js/jquery.js +5 -143
- data/templates/default/layout/html/files.erb +11 -0
- data/templates/default/layout/html/headers.erb +1 -1
- data/templates/default/layout/html/index.erb +2 -49
- data/templates/default/layout/html/listing.erb +4 -0
- data/templates/default/layout/html/objects.erb +32 -0
- data/templates/default/layout/html/setup.rb +1 -1
- data/templates/default/module/dot/info.erb +1 -1
- data/templates/default/module/dot/setup.rb +1 -1
- metadata +15 -6
- data/lib/yard/templates/helpers/html_syntax_highlight_helper18.rb +0 -25
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}PrivateConstantHandler" do
|
4
|
+
before(:all) { parse_file :private_constant_handler_001, __FILE__ }
|
5
|
+
|
6
|
+
it "should handle private_constant statement" do
|
7
|
+
Registry.at('A::Foo').visibility.should == :private
|
8
|
+
Registry.at('A::B').visibility.should == :private
|
9
|
+
Registry.at('A::C').visibility.should == :private
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should make all other constants public" do
|
13
|
+
Registry.at('A::D').visibility.should == :public
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should fail if parameter is not String, Symbol or Constant" do
|
17
|
+
undoc_error 'class Foo; private_constant x; end'
|
18
|
+
undoc_error 'class Foo; X = 1; private_constant X.new("hi"); end'
|
19
|
+
end unless LEGACY_PARSER
|
20
|
+
|
21
|
+
it "should fail if constant can't be recognized" do
|
22
|
+
undoc_error 'class Foo2; private_constant :X end'
|
23
|
+
end
|
24
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
describe "YARD::Handlers::Ruby::#{
|
3
|
+
describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ProcessHandler" do
|
4
4
|
before(:all) { parse_file :process_handler_001, __FILE__ }
|
5
5
|
|
6
6
|
it "should only work for classes that extend YARD::Handlers::*" do
|
@@ -32,7 +32,7 @@ describe YARD::Handlers::Ruby::Base, '#valid_handler?' do
|
|
32
32
|
handles "x"
|
33
33
|
end
|
34
34
|
Handlers::Base.stub!(:subclasses).and_return [StringHandler]
|
35
|
-
ast = RubyParser.parse("if x == 2 then true end").ast
|
35
|
+
ast = Parser::Ruby::RubyParser.parse("if x == 2 then true end").ast
|
36
36
|
valid StringHandler, ast[0][0][0]
|
37
37
|
invalid StringHandler, ast[0][1]
|
38
38
|
end
|
@@ -51,7 +51,7 @@ describe YARD::Handlers::Ruby::Base, '#valid_handler?' do
|
|
51
51
|
handles %r{^if x ==}
|
52
52
|
end
|
53
53
|
Handlers::Base.stub!(:subclasses).and_return [RegexHandler]
|
54
|
-
ast = RubyParser.parse("if x == 2 then true end").ast
|
54
|
+
ast = Parser::Ruby::RubyParser.parse("if x == 2 then true end").ast
|
55
55
|
valid RegexHandler, ast
|
56
56
|
invalid RegexHandler, ast[0][1]
|
57
57
|
end
|
@@ -70,7 +70,7 @@ describe YARD::Handlers::Ruby::Base, '#valid_handler?' do
|
|
70
70
|
handles method_call(:meth)
|
71
71
|
end
|
72
72
|
Handlers::Base.stub!(:subclasses).and_return [MethCallHandler]
|
73
|
-
ast = RubyParser.parse(<<-"eof").ast
|
73
|
+
ast = Parser::Ruby::RubyParser.parse(<<-"eof").ast
|
74
74
|
meth # 0
|
75
75
|
meth() # 1
|
76
76
|
meth(1,2,3) # 2
|
@@ -87,4 +87,4 @@ describe YARD::Handlers::Ruby::Base, '#valid_handler?' do
|
|
87
87
|
end
|
88
88
|
invalid MethCallHandler, ast[9]
|
89
89
|
end
|
90
|
-
end if
|
90
|
+
end if HAVE_RIPPER
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
describe "YARD::Handlers::Ruby::#{
|
3
|
+
describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}VisibilityHandler" do
|
4
4
|
before(:all) { parse_file :visibility_handler_001, __FILE__ }
|
5
5
|
|
6
6
|
it "should be able to set visibility to public" do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
describe "YARD::Handlers::Ruby::#{
|
3
|
+
describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}YieldHandler" do
|
4
4
|
before(:all) { parse_file :yield_handler_001, __FILE__ }
|
5
5
|
|
6
6
|
it "should only parse yield blocks in methods" do
|
data/spec/parser/base_spec.rb
CHANGED
@@ -2,16 +2,14 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
|
2
2
|
|
3
3
|
describe YARD::Parser::Base do
|
4
4
|
describe '#initialize' do
|
5
|
-
|
6
|
-
class MyParser < Parser::Base; def initialize(a, b) end end
|
7
|
-
end
|
5
|
+
class MyParser < Parser::Base; def initialize(a, b) end end
|
8
6
|
|
9
7
|
it "should take 2 arguments" do
|
10
|
-
lambda { Parser::Base.new }.should raise_error(ArgumentError, /wrong (number|#) of arguments/)
|
8
|
+
lambda { YARD::Parser::Base.new }.should raise_error(ArgumentError, /wrong (number|#) of arguments/)
|
11
9
|
end
|
12
10
|
|
13
11
|
it "should raise NotImplementedError on #initialize" do
|
14
|
-
lambda { Parser::Base.new('a', 'b') }.should raise_error(NotImplementedError)
|
12
|
+
lambda { YARD::Parser::Base.new('a', 'b') }.should raise_error(NotImplementedError)
|
15
13
|
end
|
16
14
|
|
17
15
|
it "should raise NotImplementedError on #parse" do
|
@@ -4,32 +4,29 @@ require 'stringio'
|
|
4
4
|
|
5
5
|
include YARD::Parser::Ruby
|
6
6
|
|
7
|
-
|
8
|
-
describe
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ast.jump(:params).object_id.should == ast.object_id
|
18
|
-
end
|
7
|
+
describe YARD::Parser::Ruby::AstNode do
|
8
|
+
describe "#jump" do
|
9
|
+
it "should jump to the first specific inner node if found" do
|
10
|
+
ast = s(:paren, s(:paren, s(:params, s(s(:ident, "hi"), s(:ident, "bye")))))
|
11
|
+
ast.jump(:params)[0][0].type.should equal(:ident)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return the original ast if no inner node is found" do
|
15
|
+
ast = s(:paren, s(:list, s(:list, s(s(:ident, "hi"), s(:ident, "bye")))))
|
16
|
+
ast.jump(:params).object_id.should == ast.object_id
|
19
17
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#pretty_print' do
|
21
|
+
it "should show a list of nodes" do
|
22
|
+
obj = YARD::Parser::Ruby::RubyParser.parse("# x\nbye", "x").ast
|
23
|
+
out = StringIO.new
|
24
|
+
PP.pp(obj, out)
|
25
|
+
out.string.should == "s(s(:var_ref,\n" +
|
26
|
+
" s(:ident, \"bye\", line: 2..2, source: 4..6),\n" +
|
27
|
+
" docstring: \"x\",\n" +
|
28
|
+
" line: 2..2,\n" +
|
29
|
+
" source: 4..6))\n"
|
33
30
|
end
|
34
31
|
end
|
35
|
-
end
|
32
|
+
end if HAVE_RIPPER
|
@@ -282,6 +282,15 @@ eof
|
|
282
282
|
s.tokens.to_s.should == "alias do x if 2 ==\n 2"
|
283
283
|
end
|
284
284
|
|
285
|
+
it "should not open a block on an aliased keyword block opener" do
|
286
|
+
s = stmts(<<-eof)
|
287
|
+
class A; alias x do end
|
288
|
+
class B; end
|
289
|
+
eof
|
290
|
+
s[0].block.to_s.should == 'alias x do'
|
291
|
+
s.size.should > 1
|
292
|
+
end
|
293
|
+
|
285
294
|
it "should convert heredoc to string" do
|
286
295
|
src = "<<-XML\n foo\n\nXML"
|
287
296
|
s = stmt(src)
|
@@ -1,200 +1,202 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
# comments
|
3
|
+
describe YARD::Parser::Ruby::RubyParser do
|
4
|
+
def stmt(stmt)
|
5
|
+
YARD::Parser::Ruby::RubyParser.new(stmt, nil).parse.root.first
|
6
|
+
end
|
7
|
+
|
8
|
+
def stmts(stmts)
|
9
|
+
YARD::Parser::Ruby::RubyParser.new(stmts, nil).parse.root
|
10
|
+
end
|
11
|
+
|
12
|
+
def tokenize(stmt)
|
13
|
+
YARD::Parser::Ruby::RubyParser.new(stmt, nil).parse.tokens
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#parse' do
|
17
|
+
it "should get comment line numbers" do
|
18
|
+
s = stmt <<-eof
|
19
|
+
# comment
|
20
|
+
# comment
|
21
|
+
# comment
|
22
|
+
def method; end
|
23
|
+
eof
|
24
|
+
s.comments.should == "comment\ncomment\ncomment"
|
25
|
+
s.comments_range.should == (1..3)
|
26
|
+
|
27
|
+
s = stmt <<-eof
|
28
|
+
|
29
|
+
# comment
|
30
|
+
# comment
|
31
|
+
def method; end
|
32
|
+
eof
|
33
|
+
s.comments.should == "comment\ncomment"
|
34
|
+
s.comments_range.should == (2..3)
|
35
|
+
|
36
|
+
s = stmt <<-eof
|
37
|
+
# comment
|
38
|
+
# comment
|
39
|
+
|
40
|
+
def method; end
|
41
|
+
eof
|
42
|
+
s.comments.should == "comment\ncomment"
|
43
|
+
s.comments_range.should == (1..2)
|
44
|
+
|
45
|
+
s = stmt <<-eof
|
46
|
+
# comment
|
47
|
+
def method; end
|
48
|
+
eof
|
49
|
+
s.comments.should == "comment"
|
50
|
+
s.comments_range.should == (1..1)
|
51
|
+
|
52
|
+
s = stmt <<-eof
|
53
|
+
def method; end # comment
|
54
|
+
eof
|
55
|
+
s.comments.should == "comment"
|
56
|
+
s.comments_range.should == (1..1)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should only look up to two lines back for comments" do
|
60
|
+
s = stmt <<-eof
|
61
|
+
# comments
|
63
62
|
|
64
|
-
|
63
|
+
# comments
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
def method; end
|
66
|
+
eof
|
67
|
+
s.comments.should == "comments"
|
69
68
|
|
70
|
-
|
71
|
-
|
69
|
+
s = stmt <<-eof
|
70
|
+
# comments
|
72
71
|
|
73
72
|
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
def method; end
|
74
|
+
eof
|
75
|
+
s.comments.should == nil
|
77
76
|
|
78
|
-
|
79
|
-
|
77
|
+
ss = stmts <<-eof
|
78
|
+
# comments
|
80
79
|
|
81
80
|
|
82
|
-
|
81
|
+
def method; end
|
83
82
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
it "should handle standard lambda syntax" do
|
102
|
-
src = "lambda { hello_world }"
|
103
|
-
stmt(src).source.should == src
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should throw a ParserSyntaxError on invalid code" do
|
107
|
-
lambda { stmt("Foo, bar.") }.should raise_error(YARD::Parser::ParserSyntaxError)
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should handle bare hashes as method parameters" do
|
111
|
-
src = "command :a => 1, :b => 2, :c => 3"
|
112
|
-
stmt(src).jump(:command)[1].source.should == ":a => 1, :b => 2, :c => 3"
|
83
|
+
# hello
|
84
|
+
def method2; end
|
85
|
+
eof
|
86
|
+
ss[0].comments.should == nil
|
87
|
+
ss[1].comments.should == 'hello'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should handle 1.9 lambda syntax with args" do
|
91
|
+
src = "->(a,b,c=1,*args,&block) { hello_world }"
|
92
|
+
stmt(src).source.should == src
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should handle 1.9 lambda syntax" do
|
96
|
+
src = "-> { hello_world }"
|
97
|
+
stmt(src).source.should == src
|
98
|
+
end
|
113
99
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
it "new hash label syntax should show label without colon" do
|
128
|
-
ast = stmt("{ a: 1 }").jump(:label)
|
129
|
-
ast[0].should == "a"
|
130
|
-
ast.source.should == "a:"
|
131
|
-
end
|
100
|
+
it "should handle standard lambda syntax" do
|
101
|
+
src = "lambda { hello_world }"
|
102
|
+
stmt(src).source.should == src
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should throw a ParserSyntaxError on invalid code" do
|
106
|
+
lambda { stmt("Foo, bar.") }.should raise_error(YARD::Parser::ParserSyntaxError)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should handle bare hashes as method parameters" do
|
110
|
+
src = "command :a => 1, :b => 2, :c => 3"
|
111
|
+
stmt(src).jump(:command)[1].source.should == ":a => 1, :b => 2, :c => 3"
|
132
112
|
|
133
|
-
|
134
|
-
|
135
|
-
|
113
|
+
src = "command a: 1, b: 2, c: 3"
|
114
|
+
stmt(src).jump(:command)[1].source.should == "a: 1, b: 2, c: 3"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should handle source for hash syntax" do
|
118
|
+
src = "{ :a => 1, :b => 2, :c => 3 }"
|
119
|
+
stmt(src).jump(:hash).source.should == "{ :a => 1, :b => 2, :c => 3 }"
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should handle an empty hash" do
|
123
|
+
stmt("{}").jump(:hash).source.should == "{}"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "new hash label syntax should show label without colon" do
|
127
|
+
ast = stmt("{ a: 1 }").jump(:label)
|
128
|
+
ast[0].should == "a"
|
129
|
+
ast.source.should == "a:"
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should handle begin/rescue blocks" do
|
133
|
+
ast = stmt("begin; X; rescue => e; Y end").jump(:rescue)
|
134
|
+
ast.source.should == "rescue => e; Y end"
|
136
135
|
|
137
|
-
|
138
|
-
|
136
|
+
ast = stmt("begin; X; rescue A => e; Y end").jump(:rescue)
|
137
|
+
ast.source.should == "rescue A => e; Y end"
|
139
138
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
139
|
+
ast = stmt("begin; X; rescue A, B => e; Y end").jump(:rescue)
|
140
|
+
ast.source.should == "rescue A, B => e; Y end"
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should handle method rescue blocks" do
|
144
|
+
ast = stmt("def x; A; rescue Y; B end")
|
145
|
+
ast.source.should == "def x; A; rescue Y; B end"
|
146
|
+
ast.jump(:rescue).source.should == "rescue Y; B end"
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should handle defs with keywords as method name" do
|
150
|
+
ast = stmt("# docstring\nclass A;\ndef class; end\nend")
|
151
|
+
ast.jump(:class).docstring.should == "docstring"
|
152
|
+
ast.jump(:class).line_range.should == (2..4)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should end source properly on array reference" do
|
156
|
+
ast = stmt("AS[0, 1 ] ")
|
157
|
+
ast.source.should == 'AS[0, 1 ]'
|
159
158
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should show proper source for assignment" do
|
171
|
-
stmt("A=1").jump(:assign).source.should == "A=1"
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should show proper source for a top_const_ref" do
|
175
|
-
s = stmt("::\nFoo::Bar")
|
176
|
-
s.jump(:top_const_ref).source.should == "::\nFoo"
|
177
|
-
s.should be_ref
|
178
|
-
s.jump(:top_const_ref).should be_ref
|
179
|
-
s.source.should == "::\nFoo::Bar"
|
180
|
-
s.line_range.to_a.should == [1, 2]
|
159
|
+
ast = stmt("def x(a = S[1]) end").jump(:default_arg)
|
160
|
+
ast.source.should == 'a = S[1]'
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should end source properly on if/unless mod" do
|
164
|
+
%w(if unless while).each do |mod|
|
165
|
+
stmt("A=1 #{mod} true").source.should == "A=1 #{mod} true"
|
181
166
|
end
|
182
|
-
|
183
|
-
|
184
|
-
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should show proper source for assignment" do
|
170
|
+
stmt("A=1").jump(:assign).source.should == "A=1"
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should show proper source for a top_const_ref" do
|
174
|
+
s = stmt("::\nFoo::Bar")
|
175
|
+
s.jump(:top_const_ref).source.should == "::\nFoo"
|
176
|
+
s.should be_ref
|
177
|
+
s.jump(:top_const_ref).should be_ref
|
178
|
+
s.source.should == "::\nFoo::Bar"
|
179
|
+
s.line_range.to_a.should == [1, 2]
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should show proper source for heredoc" do
|
183
|
+
src = "def foo\n foo(<<-XML, 1, 2)\n bar\n\n XML\nend"
|
184
|
+
s = stmt(src)
|
185
|
+
t = tokenize(src)
|
186
|
+
s.source.should == src
|
187
|
+
t.map {|x| x[1] }.join.should == src
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should show proper source for string" do
|
191
|
+
["'", '"'].each do |q|
|
192
|
+
src = "#{q}hello\n\nworld#{q}"
|
185
193
|
s = stmt(src)
|
186
|
-
|
194
|
+
s.jump(:string_content)[0].should == "hello\n\nworld"
|
187
195
|
s.source.should == src
|
188
|
-
t.map {|x| x[1] }.join.should == src
|
189
196
|
end
|
190
197
|
|
191
|
-
|
192
|
-
|
193
|
-
src = "#{q}hello\n\nworld#{q}"
|
194
|
-
s = stmt(src)
|
195
|
-
s.source.should == src
|
196
|
-
end
|
197
|
-
end
|
198
|
+
src = '("this is a string")'
|
199
|
+
stmt(src).jump(:string_literal).source.should == '"this is a string"'
|
198
200
|
end
|
199
201
|
end
|
200
|
-
end
|
202
|
+
end if HAVE_RIPPER
|