parser 2.4.0.0 → 2.4.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -65,13 +65,13 @@ class TestParseHelper < Minitest::Test
65
65
  assert_equal ast, traverse_ast(ast, %w())
66
66
 
67
67
  assert_equal s(:int, 1), traverse_ast(ast, %w(int))
68
- assert_equal nil, traverse_ast(ast, %w(str))
69
-
70
68
  assert_equal s(:str, 'foo'), traverse_ast(ast, %w(dstr str))
71
69
  assert_equal s(:int, 2), traverse_ast(ast, %w(dstr int))
72
70
  assert_equal s(:int, 2), traverse_ast(ast, %w(dstr int/1))
73
71
  assert_equal s(:int, 3), traverse_ast(ast, %w(dstr int/2))
74
- assert_equal nil, traverse_ast(ast, %w(dstr int/3))
72
+
73
+ assert_nil traverse_ast(ast, %w(str))
74
+ assert_nil traverse_ast(ast, %w(dstr int/3))
75
75
  end
76
76
 
77
77
  def test_assert_parses
@@ -25,6 +25,7 @@ class TestParser < Minitest::Test
25
25
  SINCE_2_2 = SINCE_2_1 - %w(2.1)
26
26
  SINCE_2_3 = SINCE_2_2 - %w(2.2)
27
27
  SINCE_2_4 = SINCE_2_3 - %w(2.3)
28
+ SINCE_2_5 = SINCE_2_4 - %w(2.4)
28
29
 
29
30
  # Guidelines for test naming:
30
31
  # * Test structure follows structure of AST_FORMAT.md.
@@ -98,6 +99,12 @@ class TestParser < Minitest::Test
98
99
  %q{42},
99
100
  %q{~~ expression})
100
101
 
102
+ assert_parses(
103
+ s(:int, 42),
104
+ %q{+42},
105
+ %q{^ operator
106
+ |~~~ expression})
107
+
101
108
  assert_parses(
102
109
  s(:int, -42),
103
110
  %q{-42},
@@ -2868,7 +2875,7 @@ class TestParser < Minitest::Test
2868
2875
  %q{fun(1, bar: 2, 3, nil)},
2869
2876
  %q{ ~~~~~~~~~ expression (hash.pair.objc_varargs)},
2870
2877
  %w(mac))
2871
- end
2878
+ end
2872
2879
 
2873
2880
  # To receiver
2874
2881
 
@@ -3251,13 +3258,35 @@ class TestParser < Minitest::Test
3251
3258
  SINCE_1_9)
3252
3259
  end
3253
3260
 
3254
- def test_pow_precedence
3261
+ def test_unary_num_pow_precedence
3255
3262
  assert_parses(
3256
- s(:send, s(:send, s(:int, 2), :**, s(:int, 10)), :-@),
3263
+ s(:send,
3264
+ s(:send,
3265
+ s(:int, 2), :**, s(:int, 10)),
3266
+ :+@),
3267
+ %q{+2 ** 10},
3268
+ %{},
3269
+ %w{2.1})
3270
+
3271
+ assert_parses(
3272
+ s(:send,
3273
+ s(:send,
3274
+ s(:float, 2.0), :**, s(:int, 10)),
3275
+ :+@),
3276
+ %q{+2.0 ** 10})
3277
+
3278
+ assert_parses(
3279
+ s(:send,
3280
+ s(:send,
3281
+ s(:int, 2), :**, s(:int, 10)),
3282
+ :-@),
3257
3283
  %q{-2 ** 10})
3258
3284
 
3259
3285
  assert_parses(
3260
- s(:send, s(:send, s(:float, 2.0), :**, s(:int, 10)), :-@),
3286
+ s(:send,
3287
+ s(:send,
3288
+ s(:float, 2.0), :**, s(:int, 10)),
3289
+ :-@),
3261
3290
  %q{-2.0 ** 10})
3262
3291
  end
3263
3292
 
@@ -4255,7 +4284,12 @@ class TestParser < Minitest::Test
4255
4284
  def test_if_masgn__24
4256
4285
  assert_parses(
4257
4286
  s(:if,
4258
- s(:begin, nil), nil, nil),
4287
+ s(:begin,
4288
+ s(:masgn,
4289
+ s(:mlhs,
4290
+ s(:lvasgn, :a),
4291
+ s(:lvasgn, :b)),
4292
+ s(:lvar, :foo))), nil, nil),
4259
4293
  %q{if (a, b = foo); end},
4260
4294
  %q{},
4261
4295
  SINCE_2_4)
@@ -4277,6 +4311,28 @@ class TestParser < Minitest::Test
4277
4311
  %w(1.8 1.9 2.0 2.1 2.2 2.3 ios mac))
4278
4312
  end
4279
4313
 
4314
+ def test_not_masgn
4315
+ assert_diagnoses(
4316
+ [:error, :masgn_as_condition],
4317
+ %q{!(a, b = foo)},
4318
+ %q{ ~~~~~~~~~~ location},
4319
+ %w(1.8 1.9 2.0 2.1 2.2 2.3 ios mac))
4320
+ end
4321
+
4322
+ def test_not_masgn__24
4323
+ assert_parses(
4324
+ s(:send,
4325
+ s(:begin,
4326
+ s(:masgn,
4327
+ s(:mlhs,
4328
+ s(:lvasgn, :a),
4329
+ s(:lvasgn, :b)),
4330
+ s(:lvar, :foo))), :'!'),
4331
+ %q{!(a, b = foo)},
4332
+ %q{},
4333
+ SINCE_2_4)
4334
+ end
4335
+
4280
4336
  def test_cond_begin
4281
4337
  assert_parses(
4282
4338
  s(:if,
@@ -4333,6 +4389,20 @@ class TestParser < Minitest::Test
4333
4389
  %q{if foo..bar; end},
4334
4390
  %q{ ~~~~~~~~ expression (iflipflop)
4335
4391
  | ~~ operator (iflipflop)})
4392
+
4393
+ assert_parses(
4394
+ s(:not, s(:begin, s(:iflipflop, s(:lvar, :foo), s(:lvar, :bar)))),
4395
+ %q{!(foo..bar)},
4396
+ %q{ ~~~~~~~~ expression (begin.iflipflop)
4397
+ | ~~ operator (begin.iflipflop)},
4398
+ %w(1.8))
4399
+
4400
+ assert_parses(
4401
+ s(:send, s(:begin, s(:iflipflop, s(:lvar, :foo), s(:lvar, :bar))), :'!'),
4402
+ %q{!(foo..bar)},
4403
+ %q{ ~~~~~~~~ expression (begin.iflipflop)
4404
+ | ~~ operator (begin.iflipflop)},
4405
+ SINCE_1_9)
4336
4406
  end
4337
4407
 
4338
4408
  def test_cond_eflipflop
@@ -4342,6 +4412,20 @@ class TestParser < Minitest::Test
4342
4412
  %q{if foo...bar; end},
4343
4413
  %q{ ~~~~~~~~~ expression (eflipflop)
4344
4414
  | ~~~ operator (eflipflop)})
4415
+
4416
+ assert_parses(
4417
+ s(:not, s(:begin, s(:eflipflop, s(:lvar, :foo), s(:lvar, :bar)))),
4418
+ %q{!(foo...bar)},
4419
+ %q{ ~~~~~~~~~ expression (begin.eflipflop)
4420
+ | ~~~ operator (begin.eflipflop)},
4421
+ %w(1.8))
4422
+
4423
+ assert_parses(
4424
+ s(:send, s(:begin, s(:eflipflop, s(:lvar, :foo), s(:lvar, :bar))), :'!'),
4425
+ %q{!(foo...bar)},
4426
+ %q{ ~~~~~~~~~ expression (begin.eflipflop)
4427
+ | ~~~ operator (begin.eflipflop)},
4428
+ SINCE_1_9)
4345
4429
  end
4346
4430
 
4347
4431
  def test_cond_match_current_line
@@ -4354,6 +4438,27 @@ class TestParser < Minitest::Test
4354
4438
  nil, nil),
4355
4439
  %q{if /wat/; end},
4356
4440
  %q{ ~~~~~ expression (match_current_line)})
4441
+
4442
+ assert_parses(
4443
+ s(:not,
4444
+ s(:match_current_line,
4445
+ s(:regexp,
4446
+ s(:str, 'wat'),
4447
+ s(:regopt)))),
4448
+ %q{!/wat/},
4449
+ %q{ ~~~~~ expression (match_current_line)},
4450
+ %w(1.8))
4451
+
4452
+ assert_parses(
4453
+ s(:send,
4454
+ s(:match_current_line,
4455
+ s(:regexp,
4456
+ s(:str, 'wat'),
4457
+ s(:regopt))),
4458
+ :'!'),
4459
+ %q{!/wat/},
4460
+ %q{ ~~~~~ expression (match_current_line)},
4461
+ SINCE_1_9)
4357
4462
  end
4358
4463
 
4359
4464
  # Case matching
@@ -4887,6 +4992,23 @@ class TestParser < Minitest::Test
4887
4992
  SINCE_1_9)
4888
4993
  end
4889
4994
 
4995
+ def test_rescue_without_begin_end
4996
+ assert_parses(
4997
+ s(:block,
4998
+ s(:send, nil, :meth),
4999
+ s(:args),
5000
+ s(:rescue,
5001
+ s(:lvar, :foo),
5002
+ s(:resbody, nil, nil,
5003
+ s(:lvar, :bar)),
5004
+ nil)),
5005
+ %q{meth do; foo; rescue; bar; end},
5006
+ %q{ ~~~~~~ keyword (rescue.resbody)
5007
+ | ~~~~~~~~~~~ expression (rescue.resbody)
5008
+ | ~~~~~~~~~~~~~~~~ expression (rescue)},
5009
+ SINCE_2_5)
5010
+ end
5011
+
4890
5012
  def test_resbody_list
4891
5013
  assert_parses(
4892
5014
  s(:kwbegin,
@@ -5229,7 +5351,7 @@ class TestParser < Minitest::Test
5229
5351
 
5230
5352
  ast, comments, tokens = parser.tokenize(source_file, true)
5231
5353
 
5232
- assert_equal nil, ast
5354
+ assert_nil ast
5233
5355
 
5234
5356
  assert_equal [
5235
5357
  Parser::Source::Comment.new(range.call(4, 9))
@@ -5320,6 +5442,14 @@ class TestParser < Minitest::Test
5320
5442
  | ~~~~~~~~~~~~~~~~~~~~~~ expression (rescue)})
5321
5443
  end
5322
5444
 
5445
+ def test_bug_def_empty_else
5446
+ assert_parses(
5447
+ s(:def, :foo, s(:args),
5448
+ s(:begin,
5449
+ s(:begin, nil))),
5450
+ %q{def foo; else; end})
5451
+ end
5452
+
5323
5453
  def test_bug_heredoc_do
5324
5454
  assert_parses(
5325
5455
  s(:block,
@@ -213,6 +213,96 @@ end
213
213
  assert_equal 0, associations.size
214
214
  end
215
215
 
216
+ def test_associate_frozen_string_literal
217
+ ast, associations = associate(<<-END)
218
+ # frozen_string_literal: true
219
+ class Foo
220
+ end
221
+ END
222
+
223
+ assert_equal 0, associations.size
224
+ end
225
+
226
+ def test_associate_frozen_string_literal_dash_star_dash
227
+ ast, associations = associate(<<-END)
228
+ # -*- frozen_string_literal: true -*-
229
+ class Foo
230
+ end
231
+ END
232
+
233
+ assert_equal 0, associations.size
234
+ end
235
+
236
+ def test_associate_frozen_string_literal_no_space_after_colon
237
+ ast, associations = associate(<<-END)
238
+ # frozen_string_literal:true
239
+ class Foo
240
+ end
241
+ END
242
+
243
+ assert_equal 0, associations.size
244
+ end
245
+
246
+ def test_associate_warn_indent
247
+ ast, associations = associate(<<-END)
248
+ # warn_indent: true
249
+ class Foo
250
+ end
251
+ END
252
+
253
+ assert_equal 0, associations.size
254
+ end
255
+
256
+ def test_associate_warn_indent_dash_star_dash
257
+ ast, associations = associate(<<-END)
258
+ # -*- warn_indent: true -*-
259
+ class Foo
260
+ end
261
+ END
262
+
263
+ assert_equal 0, associations.size
264
+ end
265
+
266
+ def test_associate_warn_past_scope
267
+ ast, associations = associate(<<-END)
268
+ # warn_past_scope: true
269
+ class Foo
270
+ end
271
+ END
272
+
273
+ assert_equal 0, associations.size
274
+ end
275
+
276
+ def test_associate_warn_past_scope_dash_star_dash
277
+ ast, associations = associate(<<-END)
278
+ # -*- warn_past_scope: true -*-
279
+ class Foo
280
+ end
281
+ END
282
+
283
+ assert_equal 0, associations.size
284
+ end
285
+
286
+ def test_associate_multiple
287
+ ast, associations = associate(<<-END)
288
+ # frozen_string_literal: true; warn_indent: true
289
+ class Foo
290
+ end
291
+ END
292
+
293
+ assert_equal 0, associations.size
294
+ end
295
+
296
+ def test_associate_multiple_dash_star_dash
297
+ ast, associations = associate(<<-END)
298
+ # -*- frozen_string_literal: true; warn_indent: true -*-
299
+ class Foo
300
+ end
301
+ END
302
+
303
+ assert_equal 0, associations.size
304
+ end
305
+
216
306
  def test_associate_no_comments
217
307
  ast, associations = associate(<<-END)
218
308
  class Foo
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
  require 'parse_helper'
3
3
 
4
- class TestSourceComment < Minitest::Test
4
+ class TestSourceMap < Minitest::Test
5
5
  include ParseHelper
6
6
 
7
7
  def test_to_hash
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0.0
4
+ version: 2.4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - whitequark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-07 00:00:00.000000000 Z
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
19
+ version: '2.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.2'
26
+ version: '2.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.2'
33
+ version: '1.16'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.2'
40
+ version: '1.16'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.3.0
75
+ version: 0.3.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.3.0
82
+ version: 0.3.2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: yard
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -114,28 +114,28 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '5.0'
117
+ version: '5.10'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '5.0'
124
+ version: '5.10'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 0.8.2
131
+ version: 0.15.1
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 0.8.2
138
+ version: 0.15.1
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: gauntlet
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -213,6 +213,8 @@ files:
213
213
  - lib/parser/ruby23.y
214
214
  - lib/parser/ruby24.rb
215
215
  - lib/parser/ruby24.y
216
+ - lib/parser/ruby25.rb
217
+ - lib/parser/ruby25.y
216
218
  - lib/parser/rubymotion.rb
217
219
  - lib/parser/rubymotion.y
218
220
  - lib/parser/runner.rb
@@ -286,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
288
  version: '0'
287
289
  requirements: []
288
290
  rubyforge_project:
289
- rubygems_version: 2.5.2
291
+ rubygems_version: 2.5.2.1
290
292
  signing_key:
291
293
  specification_version: 4
292
294
  summary: A Ruby parser written in pure Ruby.