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.

Files changed (107) hide show
  1. data/ChangeLog +341 -0
  2. data/LICENSE +1 -1
  3. data/README.md +31 -6
  4. data/Rakefile +22 -3
  5. data/docs/Tags.md +5 -1
  6. data/docs/WhatsNew.md +18 -1
  7. data/lib/rubygems_plugin.rb +3 -99
  8. data/lib/yard.rb +1 -1
  9. data/lib/yard/autoload.rb +37 -35
  10. data/lib/yard/cli/config.rb +25 -2
  11. data/lib/yard/cli/graph.rb +1 -1
  12. data/lib/yard/cli/yardoc.rb +4 -0
  13. data/lib/yard/code_objects/base.rb +17 -9
  14. data/lib/yard/code_objects/method_object.rb +0 -9
  15. data/lib/yard/code_objects/proxy.rb +6 -0
  16. data/lib/yard/docstring.rb +5 -0
  17. data/lib/yard/handlers/base.rb +3 -1
  18. data/lib/yard/handlers/processor.rb +1 -1
  19. data/lib/yard/handlers/ruby/alias_handler.rb +9 -8
  20. data/lib/yard/handlers/ruby/class_handler.rb +3 -3
  21. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +9 -7
  22. data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -0
  23. data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +21 -0
  24. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
  25. data/lib/yard/handlers/ruby/method_handler.rb +7 -0
  26. data/lib/yard/handlers/ruby/private_constant_handler.rb +36 -0
  27. data/lib/yard/parser/ruby/ast_node.rb +41 -24
  28. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +3 -0
  29. data/lib/yard/parser/ruby/legacy/statement.rb +2 -0
  30. data/lib/yard/parser/ruby/legacy/statement_list.rb +27 -4
  31. data/lib/yard/parser/ruby/ruby_parser.rb +71 -36
  32. data/lib/yard/parser/source_parser.rb +11 -10
  33. data/lib/yard/registry.rb +62 -24
  34. data/lib/yard/registry_store.rb +18 -5
  35. data/lib/yard/rubygems/doc_manager.rb +75 -0
  36. data/lib/yard/rubygems/specification.rb +23 -0
  37. data/lib/yard/serializers/process_serializer.rb +1 -1
  38. data/lib/yard/serializers/yardoc_serializer.rb +7 -2
  39. data/lib/yard/server/commands/display_object_command.rb +1 -1
  40. data/lib/yard/server/commands/library_command.rb +2 -2
  41. data/lib/yard/tags/default_factory.rb +1 -1
  42. data/lib/yard/tags/library.rb +2 -2
  43. data/lib/yard/templates/helpers/base_helper.rb +19 -0
  44. data/lib/yard/templates/helpers/html_helper.rb +22 -9
  45. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +28 -0
  46. data/lib/yard/templates/helpers/markup_helper.rb +14 -22
  47. data/lib/yard/templates/template.rb +1 -1
  48. data/spec/cli/config_spec.rb +20 -0
  49. data/spec/cli/yardoc_spec.rb +12 -0
  50. data/spec/code_objects/base_spec.rb +13 -0
  51. data/spec/code_objects/proxy_spec.rb +9 -0
  52. data/spec/config_spec.rb +4 -1
  53. data/spec/docstring_spec.rb +5 -0
  54. data/spec/handlers/alias_handler_spec.rb +14 -1
  55. data/spec/handlers/attribute_handler_spec.rb +1 -1
  56. data/spec/handlers/base_spec.rb +21 -21
  57. data/spec/handlers/class_condition_handler_spec.rb +1 -1
  58. data/spec/handlers/class_handler_spec.rb +1 -1
  59. data/spec/handlers/class_variable_handler_spec.rb +1 -1
  60. data/spec/handlers/constant_handler_spec.rb +2 -2
  61. data/spec/handlers/examples/alias_handler_001.rb.txt +14 -0
  62. data/spec/handlers/examples/method_handler_001.rb.txt +6 -0
  63. data/spec/handlers/examples/module_handler_001.rb.txt +4 -0
  64. data/spec/handlers/examples/private_constant_handler_001.rb.txt +8 -0
  65. data/spec/handlers/exception_handler_spec.rb +1 -1
  66. data/spec/handlers/extend_handler_spec.rb +1 -1
  67. data/spec/handlers/method_condition_handler_spec.rb +1 -1
  68. data/spec/handlers/method_handler_spec.rb +7 -1
  69. data/spec/handlers/mixin_handler_spec.rb +1 -1
  70. data/spec/handlers/module_handler_spec.rb +5 -1
  71. data/spec/handlers/private_constant_handler_spec.rb +24 -0
  72. data/spec/handlers/process_handler_spec.rb +1 -1
  73. data/spec/handlers/ruby/base_spec.rb +4 -4
  74. data/spec/handlers/visibility_handler_spec.rb +1 -1
  75. data/spec/handlers/yield_handler_spec.rb +1 -1
  76. data/spec/parser/base_spec.rb +3 -5
  77. data/spec/parser/c_parser_spec.rb +1 -1
  78. data/spec/parser/ruby/ast_node_spec.rb +23 -26
  79. data/spec/parser/ruby/legacy/statement_list_spec.rb +9 -0
  80. data/spec/parser/ruby/ruby_parser_spec.rb +179 -177
  81. data/spec/parser/source_parser_spec.rb +41 -7
  82. data/spec/rake/yardoc_task_spec.rb +3 -3
  83. data/spec/registry_spec.rb +52 -0
  84. data/spec/registry_store_spec.rb +71 -1
  85. data/spec/serializers/yardoc_serializer_spec.rb +18 -7
  86. data/spec/server/rack_adapter_spec.rb +2 -2
  87. data/spec/spec_helper.rb +10 -0
  88. data/spec/tags/default_factory_spec.rb +122 -120
  89. data/spec/templates/helpers/base_helper_spec.rb +38 -14
  90. data/spec/templates/helpers/html_helper_spec.rb +19 -0
  91. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +10 -6
  92. data/spec/templates/helpers/markup_helper_spec.rb +21 -5
  93. data/templates/default/class/dot/superklass.erb +1 -1
  94. data/templates/default/docstring/setup.rb +1 -1
  95. data/templates/default/fulldoc/html/css/style.css +12 -4
  96. data/templates/default/fulldoc/html/js/app.js +1 -1
  97. data/templates/default/fulldoc/html/js/jquery.js +5 -143
  98. data/templates/default/layout/html/files.erb +11 -0
  99. data/templates/default/layout/html/headers.erb +1 -1
  100. data/templates/default/layout/html/index.erb +2 -49
  101. data/templates/default/layout/html/listing.erb +4 -0
  102. data/templates/default/layout/html/objects.erb +32 -0
  103. data/templates/default/layout/html/setup.rb +1 -1
  104. data/templates/default/module/dot/info.erb +1 -1
  105. data/templates/default/module/dot/setup.rb +1 -1
  106. metadata +15 -6
  107. 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::#{RUBY18 ? "Legacy::" : ""}ProcessHandler" do
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 RUBY19
90
+ end if HAVE_RIPPER
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe "YARD::Handlers::Ruby::#{RUBY18 ? "Legacy::" : ""}VisibilityHandler" do
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::#{RUBY18 ? "Legacy::" : ""}YieldHandler" do
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
@@ -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
- before do
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
@@ -1,5 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
- require 'continuation' unless RUBY18
2
+ begin require 'continuation'; rescue LoadError; end unless RUBY18
3
3
 
4
4
  describe YARD::Parser::CParser do
5
5
  before(:all) do
@@ -4,32 +4,29 @@ require 'stringio'
4
4
 
5
5
  include YARD::Parser::Ruby
6
6
 
7
- if RUBY19
8
- describe YARD::Parser::Ruby::AstNode do
9
- describe "#jump" do
10
- it "should jump to the first specific inner node if found" do
11
- ast = s(:paren, s(:paren, s(:params, s(s(:ident, "hi"), s(:ident, "bye")))))
12
- ast.jump(:params)[0][0].type.should equal(:ident)
13
- end
14
-
15
- it "should return the original ast if no inner node is found" do
16
- ast = s(:paren, s(:list, s(:list, s(s(:ident, "hi"), s(:ident, "bye")))))
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
- describe '#pretty_print' do
22
- it "should show a list of nodes" do
23
- obj = YARD::Parser::Ruby::RubyParser.parse("# x\nbye", "x").ast
24
- out = StringIO.new
25
- PP.pp(obj, out)
26
- out.rewind
27
- out.read.should == "s(s(:var_ref,\n" +
28
- " s(:ident, \"bye\", line: 2..2, source: 4..6),\n" +
29
- " docstring: \"x\",\n" +
30
- " line: 2..2,\n" +
31
- " source: 4..6))\n"
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
- 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
- def stmts(stmts)
10
- YARD::Parser::Ruby::RubyParser.new(stmts, nil).parse.root
11
- end
12
-
13
- def tokenize(stmt)
14
- YARD::Parser::Ruby::RubyParser.new(stmt, nil).parse.tokens
15
- end
16
-
17
- describe '#parse' do
18
- it "should get comment line numbers" do
19
- s = stmt <<-eof
20
- # comment
21
- # comment
22
- # comment
23
- def method; end
24
- eof
25
- s.comments.should == "comment\ncomment\ncomment"
26
- s.comments_range.should == (1..3)
27
-
28
- s = stmt <<-eof
29
-
30
- # comment
31
- # comment
32
- def method; end
33
- eof
34
- s.comments.should == "comment\ncomment"
35
- s.comments_range.should == (2..3)
36
-
37
- s = stmt <<-eof
38
- # comment
39
- # comment
40
-
41
- def method; end
42
- eof
43
- s.comments.should == "comment\ncomment"
44
- s.comments_range.should == (1..2)
45
-
46
- s = stmt <<-eof
47
- # comment
48
- def method; end
49
- eof
50
- s.comments.should == "comment"
51
- s.comments_range.should == (1..1)
52
-
53
- s = stmt <<-eof
54
- def method; end # comment
55
- eof
56
- s.comments.should == "comment"
57
- s.comments_range.should == (1..1)
58
- end
59
-
60
- it "should only look up to two lines back for comments" do
61
- s = stmt <<-eof
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
- # comments
63
+ # comments
65
64
 
66
- def method; end
67
- eof
68
- s.comments.should == "comments"
65
+ def method; end
66
+ eof
67
+ s.comments.should == "comments"
69
68
 
70
- s = stmt <<-eof
71
- # comments
69
+ s = stmt <<-eof
70
+ # comments
72
71
 
73
72
 
74
- def method; end
75
- eof
76
- s.comments.should == nil
73
+ def method; end
74
+ eof
75
+ s.comments.should == nil
77
76
 
78
- ss = stmts <<-eof
79
- # comments
77
+ ss = stmts <<-eof
78
+ # comments
80
79
 
81
80
 
82
- def method; end
81
+ def method; end
83
82
 
84
- # hello
85
- def method2; end
86
- eof
87
- ss[0].comments.should == nil
88
- ss[1].comments.should == 'hello'
89
- end
90
-
91
- it "should handle 1.9 lambda syntax with args" do
92
- src = "->(a,b,c=1,*args,&block) { hello_world }"
93
- stmt(src).source.should == src
94
- end
95
-
96
- it "should handle 1.9 lambda syntax" do
97
- src = "-> { hello_world }"
98
- stmt(src).source.should == src
99
- end
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
- src = "command a: 1, b: 2, c: 3"
115
- stmt(src).jump(:command)[1].source.should == "a: 1, b: 2, c: 3"
116
- end
117
-
118
- it "should handle source for hash syntax" do
119
- src = "{ :a => 1, :b => 2, :c => 3 }"
120
- stmt(src).jump(:hash).source.should == "{ :a => 1, :b => 2, :c => 3 }"
121
- end
122
-
123
- it "should handle an empty hash" do
124
- stmt("{}").jump(:hash).source.should == "{}"
125
- end
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
- it "should handle begin/rescue blocks" do
134
- ast = stmt("begin; X; rescue => e; Y end").jump(:rescue)
135
- ast.source.should == "rescue => e; Y end"
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
- ast = stmt("begin; X; rescue A => e; Y end").jump(:rescue)
138
- ast.source.should == "rescue A => e; Y end"
136
+ ast = stmt("begin; X; rescue A => e; Y end").jump(:rescue)
137
+ ast.source.should == "rescue A => e; Y end"
139
138
 
140
- ast = stmt("begin; X; rescue A, B => e; Y end").jump(:rescue)
141
- ast.source.should == "rescue A, B => e; Y end"
142
- end
143
-
144
- it "should handle method rescue blocks" do
145
- ast = stmt("def x; A; rescue Y; B end")
146
- ast.source.should == "def x; A; rescue Y; B end"
147
- ast.jump(:rescue).source.should == "rescue Y; B end"
148
- end
149
-
150
- it "should handle defs with keywords as method name" do
151
- ast = stmt("# docstring\nclass A;\ndef class; end\nend")
152
- ast.jump(:class).docstring.should == "docstring"
153
- ast.jump(:class).line_range.should == (2..4)
154
- end
155
-
156
- it "should end source properly on array reference" do
157
- ast = stmt("AS[0, 1 ] ")
158
- ast.source.should == 'AS[0, 1 ]'
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
- ast = stmt("def x(a = S[1]) end").jump(:default_arg)
161
- ast.source.should == 'a = S[1]'
162
- end
163
-
164
- it "should end source properly on if/unless mod" do
165
- %w(if unless while).each do |mod|
166
- stmt("A=1 #{mod} true").source.should == "A=1 #{mod} true"
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
- it "should show proper source for heredoc" do
184
- src = "def foo\n foo(<<-XML, 1, 2)\n bar\n\n XML\nend"
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
- t = tokenize(src)
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
- it "should show proper source for string" do
192
- ["'", '"'].each do |q|
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