parser 2.7.1.1 → 3.0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/lib/parser.rb +1 -0
  3. data/lib/parser/all.rb +2 -0
  4. data/lib/parser/ast/processor.rb +5 -0
  5. data/lib/parser/base.rb +7 -5
  6. data/lib/parser/builders/default.rb +263 -23
  7. data/lib/parser/context.rb +5 -0
  8. data/lib/parser/current.rb +24 -6
  9. data/lib/parser/current_arg_stack.rb +5 -2
  10. data/lib/parser/diagnostic.rb +1 -1
  11. data/lib/parser/diagnostic/engine.rb +1 -2
  12. data/lib/parser/lexer.rb +887 -803
  13. data/lib/parser/macruby.rb +2214 -2189
  14. data/lib/parser/max_numparam_stack.rb +13 -5
  15. data/lib/parser/messages.rb +18 -0
  16. data/lib/parser/meta.rb +6 -5
  17. data/lib/parser/ruby18.rb +9 -3
  18. data/lib/parser/ruby19.rb +2297 -2289
  19. data/lib/parser/ruby20.rb +2413 -2397
  20. data/lib/parser/ruby21.rb +2419 -2411
  21. data/lib/parser/ruby22.rb +2468 -2460
  22. data/lib/parser/ruby23.rb +2452 -2452
  23. data/lib/parser/ruby24.rb +2435 -2430
  24. data/lib/parser/ruby25.rb +2220 -2214
  25. data/lib/parser/ruby26.rb +2220 -2214
  26. data/lib/parser/ruby27.rb +3715 -3615
  27. data/lib/parser/ruby28.rb +8047 -0
  28. data/lib/parser/ruby30.rb +8060 -0
  29. data/lib/parser/ruby31.rb +8226 -0
  30. data/lib/parser/rubymotion.rb +2190 -2182
  31. data/lib/parser/runner.rb +31 -2
  32. data/lib/parser/runner/ruby_rewrite.rb +2 -2
  33. data/lib/parser/source/buffer.rb +53 -28
  34. data/lib/parser/source/comment.rb +14 -1
  35. data/lib/parser/source/comment/associator.rb +31 -8
  36. data/lib/parser/source/map/method_definition.rb +25 -0
  37. data/lib/parser/source/range.rb +10 -3
  38. data/lib/parser/source/tree_rewriter.rb +100 -10
  39. data/lib/parser/source/tree_rewriter/action.rb +114 -21
  40. data/lib/parser/static_environment.rb +4 -0
  41. data/lib/parser/tree_rewriter.rb +1 -2
  42. data/lib/parser/variables_stack.rb +4 -0
  43. data/lib/parser/version.rb +1 -1
  44. data/parser.gemspec +3 -18
  45. metadata +17 -98
  46. data/.gitignore +0 -33
  47. data/.travis.yml +0 -42
  48. data/.yardopts +0 -21
  49. data/CHANGELOG.md +0 -1075
  50. data/CONTRIBUTING.md +0 -17
  51. data/Gemfile +0 -10
  52. data/README.md +0 -309
  53. data/Rakefile +0 -166
  54. data/ci/run_rubocop_specs +0 -14
  55. data/doc/AST_FORMAT.md +0 -2180
  56. data/doc/CUSTOMIZATION.md +0 -37
  57. data/doc/INTERNALS.md +0 -21
  58. data/doc/css/.gitkeep +0 -0
  59. data/doc/css/common.css +0 -68
  60. data/lib/parser/lexer.rl +0 -2536
  61. data/lib/parser/macruby.y +0 -2198
  62. data/lib/parser/ruby18.y +0 -1934
  63. data/lib/parser/ruby19.y +0 -2175
  64. data/lib/parser/ruby20.y +0 -2353
  65. data/lib/parser/ruby21.y +0 -2357
  66. data/lib/parser/ruby22.y +0 -2364
  67. data/lib/parser/ruby23.y +0 -2370
  68. data/lib/parser/ruby24.y +0 -2408
  69. data/lib/parser/ruby25.y +0 -2405
  70. data/lib/parser/ruby26.y +0 -2413
  71. data/lib/parser/ruby27.y +0 -2941
  72. data/lib/parser/rubymotion.y +0 -2182
  73. data/test/bug_163/fixtures/input.rb +0 -5
  74. data/test/bug_163/fixtures/output.rb +0 -5
  75. data/test/bug_163/rewriter.rb +0 -20
  76. data/test/helper.rb +0 -60
  77. data/test/parse_helper.rb +0 -319
  78. data/test/racc_coverage_helper.rb +0 -133
  79. data/test/test_base.rb +0 -31
  80. data/test/test_current.rb +0 -29
  81. data/test/test_diagnostic.rb +0 -96
  82. data/test/test_diagnostic_engine.rb +0 -62
  83. data/test/test_encoding.rb +0 -99
  84. data/test/test_lexer.rb +0 -3608
  85. data/test/test_lexer_stack_state.rb +0 -78
  86. data/test/test_parse_helper.rb +0 -80
  87. data/test/test_parser.rb +0 -9430
  88. data/test/test_runner_parse.rb +0 -35
  89. data/test/test_runner_rewrite.rb +0 -47
  90. data/test/test_source_buffer.rb +0 -162
  91. data/test/test_source_comment.rb +0 -36
  92. data/test/test_source_comment_associator.rb +0 -367
  93. data/test/test_source_map.rb +0 -15
  94. data/test/test_source_range.rb +0 -187
  95. data/test/test_source_rewriter.rb +0 -541
  96. data/test/test_source_rewriter_action.rb +0 -46
  97. data/test/test_source_tree_rewriter.rb +0 -253
  98. data/test/test_static_environment.rb +0 -45
  99. data/test/using_tree_rewriter/fixtures/input.rb +0 -3
  100. data/test/using_tree_rewriter/fixtures/output.rb +0 -3
  101. data/test/using_tree_rewriter/using_tree_rewriter.rb +0 -9
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
- require 'open3'
5
-
6
- class TestRunnerParse < Minitest::Test
7
- PATH_TO_RUBY_PARSE = File.expand_path('../bin/ruby-parse', __dir__).freeze
8
-
9
- def assert_prints(argv, expected_output)
10
- stdout, stderr, status = Open3.capture3(PATH_TO_RUBY_PARSE, *argv)
11
-
12
- assert_equal 0, status.to_i
13
- assert_includes(stdout, expected_output)
14
- end
15
-
16
- def test_emit_ruby
17
- assert_prints ['--emit-ruby', '-e 123'],
18
- 's(:int, 123)'
19
- end
20
-
21
- def test_emit_json
22
- assert_prints ['--emit-json', '-e', '123'],
23
- '["int",123]'
24
- end
25
-
26
- def test_emit_ruby_empty
27
- assert_prints ['--emit-ruby', '-e', ''],
28
- "\n"
29
- end
30
-
31
- def test_emit_json_empty
32
- assert_prints ['--emit-json', '-e', ''],
33
- "\n"
34
- end
35
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'pathname'
4
- require 'fileutils'
5
- require 'shellwords'
6
- require 'open3'
7
-
8
- BASE_DIR = Pathname.new(__FILE__) + '..'
9
- require (BASE_DIR + 'helper').expand_path
10
-
11
- class TestRunnerRewrite < Minitest::Test
12
- def assert_rewriter_output(path, args, input: 'input.rb', output: 'output.rb', expected_output: '', expected_error: '')
13
- @ruby_rewrite = BASE_DIR.expand_path + '../bin/ruby-rewrite'
14
- @test_dir = BASE_DIR + path
15
- @fixtures_dir = @test_dir + 'fixtures'
16
-
17
- Dir.mktmpdir("parser", BASE_DIR.expand_path.to_s) do |tmp_dir|
18
- tmp_dir = Pathname.new(tmp_dir)
19
- sample_file = tmp_dir + "#{path}.rb"
20
- sample_file_expanded = sample_file.expand_path
21
- expected_file = @fixtures_dir + output
22
-
23
- FileUtils.cp(@fixtures_dir + input, sample_file_expanded)
24
- stdout, stderr, exit_code = Dir.chdir @test_dir do
25
- Open3.capture3 %Q{
26
- #{Shellwords.escape(@ruby_rewrite.to_s)} #{args} \
27
- #{Shellwords.escape(sample_file_expanded.to_s)}
28
- }
29
- end
30
-
31
- assert_equal expected_output.chomp, stdout.chomp
32
- assert_match expected_error.chomp, stderr.chomp
33
- assert_equal File.read(expected_file.expand_path), File.read(sample_file)
34
- end
35
- end
36
-
37
- def test_rewriter_bug_163
38
- assert_rewriter_output('bug_163',
39
- '--modify -l rewriter.rb',
40
- expected_error: Parser::Rewriter::DEPRECATION_WARNING
41
- )
42
- end
43
-
44
- def test_tree_rewriter
45
- assert_rewriter_output('using_tree_rewriter', '-l using_tree_rewriter.rb --modify')
46
- end
47
- end
@@ -1,162 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
-
5
- class TestSourceBuffer < Minitest::Test
6
- def setup
7
- @buffer = Parser::Source::Buffer.new('(string)')
8
- end
9
-
10
- def test_initialize
11
- buffer = Parser::Source::Buffer.new(nil)
12
- assert_equal '', buffer.name
13
-
14
- buffer = Parser::Source::Buffer.new(Pathname('a/b'))
15
- assert_equal 'a/b', buffer.name
16
-
17
- buffer = Parser::Source::Buffer.new('(string)')
18
- assert_equal '(string)', buffer.name
19
- assert_equal 1, buffer.first_line
20
-
21
- buffer = Parser::Source::Buffer.new('(string)', 5)
22
- assert_equal 5, buffer.first_line
23
- end
24
-
25
- def test_source_setter
26
- @buffer.source = 'foo'
27
- assert_equal 'foo', @buffer.source
28
-
29
- assert @buffer.source.frozen?
30
- end
31
-
32
- def test_source_double_setter
33
- @buffer.source = 'foo'
34
-
35
- assert_raises(ArgumentError) do
36
- @buffer.source = 'bar'
37
- end
38
- end
39
-
40
- def test_source_setter_encoding_error
41
- error = assert_raises EncodingError do
42
- @buffer.source = [
43
- '# encoding: utf-8',
44
- "# \xf9"
45
- ].join("\n")
46
- end
47
-
48
- assert_match /invalid byte sequence in UTF\-8/, error.message
49
- end
50
-
51
- def test_read
52
- tempfile = Tempfile.new('parser')
53
- tempfile.write('foobar')
54
- tempfile.flush
55
-
56
- buffer = Parser::Source::Buffer.new(tempfile.path)
57
- buffer.read
58
- assert_equal 'foobar', buffer.source
59
-
60
- assert buffer.source.frozen?
61
- end
62
-
63
- def test_uninitialized
64
- assert_raises RuntimeError do
65
- @buffer.source
66
- end
67
- end
68
-
69
- def test_decompose_position
70
- @buffer.source = "1\nfoo\nbar"
71
-
72
- assert_equal [1, 0], @buffer.decompose_position(0)
73
- assert_equal [1, 1], @buffer.decompose_position(1)
74
- assert_equal [2, 0], @buffer.decompose_position(2)
75
- assert_equal [3, 1], @buffer.decompose_position(7)
76
- end
77
-
78
- def test_decompose_position_mapped
79
- @buffer = Parser::Source::Buffer.new('(string)', 5)
80
- @buffer.source = "1\nfoo\nbar"
81
-
82
- assert_equal [5, 0], @buffer.decompose_position(0)
83
- assert_equal [6, 0], @buffer.decompose_position(2)
84
- end
85
-
86
- def test_line
87
- @buffer.source = "1\nfoo\nbar"
88
-
89
- assert_equal '1', @buffer.source_line(1)
90
- assert_equal 'foo', @buffer.source_line(2)
91
- end
92
-
93
- def test_line_mutate
94
- @buffer.source = "1\nfoo\nbar"
95
-
96
- assert_equal '1', @buffer.source_line(1)
97
-
98
- @buffer.source_line(1)[0] = '2'
99
- assert_equal '1', @buffer.source_line(1)
100
- end
101
-
102
- def test_line_mapped
103
- @buffer = Parser::Source::Buffer.new('(string)', 5)
104
- @buffer.source = "1\nfoo\nbar"
105
-
106
- assert_equal '1', @buffer.source_line(5)
107
- assert_equal 'foo', @buffer.source_line(6)
108
- end
109
-
110
- def test_line_range
111
- @buffer = Parser::Source::Buffer.new('(string)', 5)
112
- @buffer.source = "abc\ndef\nghi\n"
113
-
114
- assert_raises IndexError do
115
- @buffer.line_range(4)
116
- end
117
- assert_equal 'abc', @buffer.line_range(5).source
118
- assert_equal 'def', @buffer.line_range(6).source
119
- assert_equal 'ghi', @buffer.line_range(7).source
120
- assert_equal '', @buffer.line_range(8).source
121
- assert_raises IndexError do
122
- @buffer.line_range(9)
123
- end
124
- end
125
-
126
- def test_source_range
127
- @buffer = Parser::Source::Buffer.new('(string)', 5)
128
-
129
- assert_raises RuntimeError do
130
- @buffer.source_range
131
- end
132
-
133
- @buffer.source = "abc\ndef\nghi\n"
134
-
135
- assert_equal Parser::Source::Range.new(@buffer, 0, @buffer.source.size), @buffer.source_range
136
- end
137
-
138
- def test_last_line
139
- @buffer.source = "1\nfoo\nbar"
140
- assert_equal 3, @buffer.last_line
141
-
142
- @buffer = Parser::Source::Buffer.new('(string)', 5)
143
- @buffer.source = ""
144
- assert_equal 5, @buffer.last_line
145
-
146
- @buffer = Parser::Source::Buffer.new('(string)', 5)
147
- @buffer.source = "abc\n"
148
- assert_equal 6, @buffer.last_line
149
- end
150
-
151
- def test_source_lines
152
- @buffer.source = "1\nfoo\nbar\n"
153
-
154
- assert_equal ['1', 'foo', 'bar', ''], @buffer.source_lines
155
- assert @buffer.source_lines.frozen?
156
- assert @buffer.source_lines.all?(&:frozen?)
157
-
158
- @buffer = Parser::Source::Buffer.new('(string)', 5)
159
- @buffer.source = "foo\nbar"
160
- assert_equal ['foo', 'bar'], @buffer.source_lines
161
- end
162
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
-
5
- class TestSourceComment < Minitest::Test
6
- def setup
7
- @buf = Parser::Source::Buffer.new('(string)')
8
- @buf.source = "# foo\n=begin foo\nbar\n=end baz\n"
9
- end
10
-
11
- def range(s, e)
12
- Parser::Source::Range.new(@buf, s, e)
13
- end
14
-
15
- def test_initialize
16
- comment = Parser::Source::Comment.new(range(0, 5))
17
- assert comment.frozen?
18
- end
19
-
20
- def test_text
21
- comment = Parser::Source::Comment.new(range(0, 5))
22
- assert_equal '# foo', comment.text
23
- end
24
-
25
- def test_inline
26
- comment = Parser::Source::Comment.new(range(0, 5))
27
- assert_equal :inline, comment.type
28
- assert comment.inline?
29
- end
30
-
31
- def test_document
32
- comment = Parser::Source::Comment.new(range(6, 25))
33
- assert_equal :document, comment.type
34
- assert comment.document?
35
- end
36
- end
@@ -1,367 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
- require 'parser/ruby18'
5
-
6
- class TestSourceCommentAssociator < Minitest::Test
7
- def parse_with_comments(code)
8
- parser = Parser::Ruby18.new
9
-
10
- buffer = Parser::Source::Buffer.new('(comments)')
11
- buffer.source = code
12
-
13
- parser.parse_with_comments(buffer)
14
- end
15
-
16
- def associate(code)
17
- ast, comments = parse_with_comments(code)
18
- associations = Parser::Source::Comment.associate(ast, comments)
19
-
20
- [ ast, associations ]
21
- end
22
-
23
- def associate_locations(code)
24
- ast, comments = parse_with_comments(code)
25
- associations = Parser::Source::Comment.associate_locations(ast, comments)
26
-
27
- [ ast, associations ]
28
- end
29
-
30
- def test_associate
31
- ast, associations = associate(<<-END)
32
- #!/usr/bin/env ruby
33
- # coding: utf-8
34
- # class preceding
35
- # another class preceding
36
- class Foo # class keyword line
37
- # method foo preceding
38
- def foo
39
- puts 'foo'
40
- end # method foo decorating
41
- # method bar preceding
42
- def bar
43
- # expression preceding
44
- 1 + # 1 decorating
45
- 2
46
- # method bar sparse
47
- end # method bar decorating
48
- # class sparse
49
- end # class decorating
50
- END
51
-
52
- klass_node = ast
53
- klass_name_node = klass_node.children[0]
54
- foo_node = klass_node.children[2].children[0] # def foo
55
- bar_node = klass_node.children[2].children[1] # def bar
56
- expr_node = bar_node.children[2] # 1 + 2
57
- one_node = expr_node.children[0] # 1
58
-
59
- assert_equal 6, associations.size
60
- assert_equal [
61
- '# class preceding',
62
- '# another class preceding',
63
- '# class sparse',
64
- '# class decorating'
65
- ], associations[klass_node].map(&:text)
66
- assert_equal [
67
- '# class keyword line'
68
- ], associations[klass_name_node].map(&:text)
69
- assert_equal [
70
- '# method foo preceding',
71
- '# method foo decorating'
72
- ], associations[foo_node].map(&:text)
73
- assert_equal [
74
- '# method bar preceding',
75
- '# method bar sparse',
76
- '# method bar decorating'
77
- ], associations[bar_node].map(&:text)
78
- assert_equal [
79
- '# expression preceding'
80
- ], associations[expr_node].map(&:text)
81
- assert_equal [
82
- '# 1 decorating'
83
- ], associations[one_node].map(&:text)
84
- end
85
-
86
- # The bug below is fixed by using associate_locations
87
- def test_associate_dupe_statement
88
- ast, associations = associate(<<-END)
89
- class Foo
90
- def bar
91
- f1 # comment on 1st call to f1
92
- f2
93
- f1 # comment on 2nd call to f1
94
- end
95
- end
96
- END
97
-
98
- klass_node = ast
99
- method_node = ast.children[2]
100
- body = method_node.children[2]
101
- f1_1_node = body.children[0]
102
- f1_2_node = body.children[2]
103
-
104
- assert_equal 1, associations.size
105
- assert_equal ['# comment on 1st call to f1', '# comment on 2nd call to f1'],
106
- associations[f1_1_node].map(&:text)
107
- assert_equal ['# comment on 1st call to f1', '# comment on 2nd call to f1'],
108
- associations[f1_2_node].map(&:text)
109
- end
110
-
111
- def test_associate_locations
112
- ast, associations = associate_locations(<<-END)
113
- #!/usr/bin/env ruby
114
- # coding: utf-8
115
- # class preceding
116
- # another class preceding
117
- class Foo # class keyword line
118
- # method foo preceding
119
- def foo
120
- puts 'foo'
121
- end # method foo decorating
122
- # method bar preceding
123
- def bar
124
- # expression preceding
125
- 1 + # 1 decorating
126
- 2
127
- # method bar sparse
128
- end # method bar decorating
129
- # class sparse
130
- end # class decorating
131
- END
132
-
133
- klass_node = ast
134
- klass_name_node = klass_node.children[0]
135
- foo_node = klass_node.children[2].children[0] # def foo
136
- bar_node = klass_node.children[2].children[1] # def bar
137
- expr_node = bar_node.children[2] # 1 + 2
138
- one_node = expr_node.children[0] # 1
139
-
140
- assert_equal 6, associations.size
141
- assert_equal [
142
- '# class preceding',
143
- '# another class preceding',
144
- '# class sparse',
145
- '# class decorating'
146
- ], associations[klass_node.loc].map(&:text)
147
- assert_equal [
148
- '# class keyword line'
149
- ], associations[klass_name_node.loc].map(&:text)
150
- assert_equal [
151
- '# method foo preceding',
152
- '# method foo decorating'
153
- ], associations[foo_node.loc].map(&:text)
154
- assert_equal [
155
- '# method bar preceding',
156
- '# method bar sparse',
157
- '# method bar decorating'
158
- ], associations[bar_node.loc].map(&:text)
159
- assert_equal [
160
- '# expression preceding'
161
- ], associations[expr_node.loc].map(&:text)
162
- assert_equal [
163
- '# 1 decorating'
164
- ], associations[one_node.loc].map(&:text)
165
- end
166
-
167
- def test_associate_locations_dupe_statement
168
- ast, associations = associate_locations(<<-END)
169
- class Foo
170
- def bar
171
- f1 # comment on 1st call to f1
172
- f2
173
- f1 # comment on 2nd call to f1
174
- end
175
- end
176
- END
177
-
178
- klass_node = ast
179
- method_node = ast.children[2]
180
- body = method_node.children[2]
181
- f1_1_node = body.children[0]
182
- f1_2_node = body.children[2]
183
-
184
- assert_equal 2, associations.size
185
- assert_equal ['# comment on 1st call to f1'],
186
- associations[f1_1_node.loc].map(&:text)
187
- assert_equal ['# comment on 2nd call to f1'],
188
- associations[f1_2_node.loc].map(&:text)
189
- end
190
-
191
- def test_associate_no_body
192
- ast, associations = associate(<<-END)
193
- # foo
194
- class Foo
195
- end
196
- END
197
-
198
- assert_equal 1, associations.size
199
- assert_equal ['# foo'],
200
- associations[ast].map(&:text)
201
- end
202
-
203
- def test_associate_empty_tree
204
- ast, associations = associate("")
205
- assert_equal 0, associations.size
206
- end
207
-
208
- def test_associate_shebang_only
209
- ast, associations = associate(<<-END)
210
- #!ruby
211
- class Foo
212
- end
213
- END
214
-
215
- assert_equal 0, associations.size
216
- end
217
-
218
- def test_associate_frozen_string_literal
219
- ast, associations = associate(<<-END)
220
- # frozen_string_literal: true
221
- class Foo
222
- end
223
- END
224
-
225
- assert_equal 0, associations.size
226
- end
227
-
228
- def test_associate_frozen_string_literal_dash_star_dash
229
- ast, associations = associate(<<-END)
230
- # -*- frozen_string_literal: true -*-
231
- class Foo
232
- end
233
- END
234
-
235
- assert_equal 0, associations.size
236
- end
237
-
238
- def test_associate_frozen_string_literal_no_space_after_colon
239
- ast, associations = associate(<<-END)
240
- # frozen_string_literal:true
241
- class Foo
242
- end
243
- END
244
-
245
- assert_equal 0, associations.size
246
- end
247
-
248
- def test_associate_warn_indent
249
- ast, associations = associate(<<-END)
250
- # warn_indent: true
251
- class Foo
252
- end
253
- END
254
-
255
- assert_equal 0, associations.size
256
- end
257
-
258
- def test_associate_warn_indent_dash_star_dash
259
- ast, associations = associate(<<-END)
260
- # -*- warn_indent: true -*-
261
- class Foo
262
- end
263
- END
264
-
265
- assert_equal 0, associations.size
266
- end
267
-
268
- def test_associate_warn_past_scope
269
- ast, associations = associate(<<-END)
270
- # warn_past_scope: true
271
- class Foo
272
- end
273
- END
274
-
275
- assert_equal 0, associations.size
276
- end
277
-
278
- def test_associate_warn_past_scope_dash_star_dash
279
- ast, associations = associate(<<-END)
280
- # -*- warn_past_scope: true -*-
281
- class Foo
282
- end
283
- END
284
-
285
- assert_equal 0, associations.size
286
- end
287
-
288
- def test_associate_multiple
289
- ast, associations = associate(<<-END)
290
- # frozen_string_literal: true; warn_indent: true
291
- class Foo
292
- end
293
- END
294
-
295
- assert_equal 0, associations.size
296
- end
297
-
298
- def test_associate_multiple_dash_star_dash
299
- ast, associations = associate(<<-END)
300
- # -*- frozen_string_literal: true; warn_indent: true -*-
301
- class Foo
302
- end
303
- END
304
-
305
- assert_equal 0, associations.size
306
- end
307
-
308
- def test_associate_no_comments
309
- ast, associations = associate(<<-END)
310
- class Foo
311
- end
312
- END
313
-
314
- assert_equal 0, associations.size
315
- end
316
-
317
- def test_associate_comments_after_root_node
318
- ast, associations = associate(<<-END)
319
- class Foo
320
- end
321
- # not associated
322
- END
323
-
324
- assert_equal 0, associations.size
325
- end
326
-
327
-
328
- def test_associate_stray_comment
329
- ast, associations = associate(<<-END)
330
- def foo
331
- # foo
332
- end
333
- END
334
-
335
- assert_equal 1, associations.size
336
- assert_equal ['# foo'],
337
- associations[ast].map(&:text)
338
- end
339
-
340
- def test_associate___ENCODING__
341
- ast, associations = associate(<<-END)
342
- # foo
343
- __ENCODING__
344
- END
345
-
346
- assert_equal 1, associations.size
347
- assert_equal ['# foo'],
348
- associations[ast].map(&:text)
349
- end
350
-
351
- def test_associate_inside_heredoc
352
- ast, associations = associate(<<-END)
353
- <<x
354
- \#{
355
- foo # bar
356
- }
357
- x
358
- END
359
-
360
- begin_node = ast.children[0]
361
- send_node = begin_node.children[0]
362
-
363
- assert_equal 1, associations.size
364
- assert_equal ['# bar'],
365
- associations[send_node].map(&:text)
366
- end
367
- end