parser 2.0.0.pre2 → 2.0.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
@@ -794,12 +794,12 @@ class TestParser < Minitest::Test
794
794
  assert_diagnoses(
795
795
  [:error, :dynamic_const],
796
796
  %q{def f; Foo::Bar = 1; end},
797
- %q{ ~~~ location})
797
+ %q{ ~~~~~~~~ location})
798
798
 
799
799
  assert_diagnoses(
800
800
  [:error, :dynamic_const],
801
801
  %q{def f; ::Bar = 1; end},
802
- %q{ ~~~ location})
802
+ %q{ ~~~~~ location})
803
803
  end
804
804
 
805
805
  # Multiple assignment
@@ -1044,12 +1044,12 @@ class TestParser < Minitest::Test
1044
1044
  assert_diagnoses(
1045
1045
  [:error, :dynamic_const],
1046
1046
  %q{def f; self::A, foo = foo; end},
1047
- %q{ ~ location})
1047
+ %q{ ~~~~~~~ location})
1048
1048
 
1049
1049
  assert_diagnoses(
1050
1050
  [:error, :dynamic_const],
1051
1051
  %q{def f; ::A, foo = foo; end},
1052
- %q{ ~ location})
1052
+ %q{ ~~~ location})
1053
1053
  end
1054
1054
 
1055
1055
  # Variable binary operator-assignment
@@ -1114,6 +1114,24 @@ class TestParser < Minitest::Test
1114
1114
  %q{B::A += 1},
1115
1115
  %q{},
1116
1116
  ALL_VERSIONS - %w(1.8 1.9))
1117
+
1118
+ assert_parses(
1119
+ s(:def, :x, s(:args),
1120
+ s(:or_asgn,
1121
+ s(:casgn, s(:self), :A),
1122
+ s(:int, 1))),
1123
+ %q{def x; self::A ||= 1; end},
1124
+ %q{},
1125
+ ALL_VERSIONS - %w(1.8 1.9))
1126
+
1127
+ assert_parses(
1128
+ s(:def, :x, s(:args),
1129
+ s(:or_asgn,
1130
+ s(:casgn, s(:cbase), :A),
1131
+ s(:int, 1))),
1132
+ %q{def x; ::A ||= 1; end},
1133
+ %q{},
1134
+ ALL_VERSIONS - %w(1.8 1.9))
1117
1135
  end
1118
1136
 
1119
1137
  def test_const_op_asgn_invalid
@@ -1132,12 +1150,14 @@ class TestParser < Minitest::Test
1132
1150
  assert_diagnoses(
1133
1151
  [:error, :dynamic_const],
1134
1152
  %q{def foo; Foo::Bar += 1; end},
1135
- %q{ ~~~ location})
1153
+ %q{ ~~~ location},
1154
+ %w(1.8 1.9))
1136
1155
 
1137
1156
  assert_diagnoses(
1138
1157
  [:error, :dynamic_const],
1139
1158
  %q{def foo; ::Bar += 1; end},
1140
- %q{ ~~~ location})
1159
+ %q{ ~~~ location},
1160
+ %w(1.8 1.9))
1141
1161
  end
1142
1162
 
1143
1163
  # Method binary operator-assignment
@@ -2191,6 +2211,14 @@ class TestParser < Minitest::Test
2191
2211
  ALL_VERSIONS - %w(1.8 1.9))
2192
2212
  end
2193
2213
 
2214
+ def test_block_kwarg
2215
+ assert_parses_blockargs(
2216
+ s(:args,
2217
+ s(:kwarg, :foo)),
2218
+ %q{|foo:|},
2219
+ ALL_VERSIONS - %w(1.8 1.9 2.0))
2220
+ end
2221
+
2194
2222
  def test_arg_invalid
2195
2223
  assert_diagnoses(
2196
2224
  [:error, :argument_const],
@@ -2312,6 +2340,22 @@ class TestParser < Minitest::Test
2312
2340
  ALL_VERSIONS - %w(1.8 1.9))
2313
2341
  end
2314
2342
 
2343
+ def test_arg_duplicate_proc
2344
+ assert_parses(
2345
+ s(:block, s(:send, nil, :proc),
2346
+ s(:args, s(:arg, :a), s(:arg, :a)),
2347
+ nil),
2348
+ %q{proc{|a,a|}},
2349
+ %q{},
2350
+ %w(1.8))
2351
+
2352
+ assert_diagnoses(
2353
+ [:error, :duplicate_argument],
2354
+ %q{proc{|a,a|}},
2355
+ %q{},
2356
+ ALL_VERSIONS - %w(1.8))
2357
+ end
2358
+
2315
2359
  def test_kwarg_invalid
2316
2360
  assert_diagnoses(
2317
2361
  [:error, :argument_const],
@@ -3180,17 +3224,37 @@ class TestParser < Minitest::Test
3180
3224
  s(:args), nil),
3181
3225
  %q{fun (1) {}})
3182
3226
 
3227
+ assert_parses(
3228
+ s(:block,
3229
+ s(:send, s(:lvar, :foo), :fun, s(:int, 1)),
3230
+ s(:args), nil),
3231
+ %q{foo.fun (1) {}},
3232
+ %q{},
3233
+ %w(1.8))
3234
+
3183
3235
  assert_parses(
3184
3236
  s(:block,
3185
3237
  s(:send, s(:lvar, :foo), :fun, s(:begin, s(:int, 1))),
3186
3238
  s(:args), nil),
3187
- %q{foo.fun (1) {}})
3239
+ %q{foo.fun (1) {}},
3240
+ %q{},
3241
+ ALL_VERSIONS - %w(1.8))
3242
+
3243
+ assert_parses(
3244
+ s(:block,
3245
+ s(:send, s(:lvar, :foo), :fun, s(:int, 1)),
3246
+ s(:args), nil),
3247
+ %q{foo::fun (1) {}},
3248
+ %q{},
3249
+ %w(1.8))
3188
3250
 
3189
3251
  assert_parses(
3190
3252
  s(:block,
3191
3253
  s(:send, s(:lvar, :foo), :fun, s(:begin, s(:int, 1))),
3192
3254
  s(:args), nil),
3193
- %q{foo::fun (1) {}})
3255
+ %q{foo::fun (1) {}},
3256
+ %q{},
3257
+ ALL_VERSIONS - %w(1.8))
3194
3258
  end
3195
3259
 
3196
3260
  def test_space_args_arg_call
@@ -3667,12 +3731,28 @@ class TestParser < Minitest::Test
3667
3731
  assert_diagnoses(
3668
3732
  [:error, :masgn_as_condition],
3669
3733
  %q{if foo && (a, b = bar); end},
3670
- %q{ ~~~~~~~~~~ location})
3734
+ %q{ ~~~~~~~~~~ location},
3735
+ ALL_VERSIONS - %w(1.8))
3671
3736
 
3672
3737
  assert_diagnoses(
3673
3738
  [:error, :masgn_as_condition],
3674
3739
  %q{if foo || (a, b = bar); end},
3675
- %q{ ~~~~~~~~~~ location})
3740
+ %q{ ~~~~~~~~~~ location},
3741
+ ALL_VERSIONS - %w(1.8))
3742
+
3743
+ assert_parses(
3744
+ s(:if,
3745
+ s(:and,
3746
+ s(:begin,
3747
+ s(:masgn,
3748
+ s(:mlhs,
3749
+ s(:lvasgn, :a), s(:lvasgn, :b)),
3750
+ s(:lvar, :foo))),
3751
+ s(:lvar, :bar)),
3752
+ nil, nil),
3753
+ %q{if (a, b = foo) && bar; end},
3754
+ %q{},
3755
+ %w(1.8))
3676
3756
  end
3677
3757
 
3678
3758
  def test_cond_iflipflop
@@ -4297,7 +4377,7 @@ class TestParser < Minitest::Test
4297
4377
  assert_equal s(:lvar, :foo),
4298
4378
  ast
4299
4379
 
4300
- assert_equal range.call(2, 5),
4380
+ assert_equal range.call(1, 4),
4301
4381
  ast.loc.expression
4302
4382
  end
4303
4383
  end
@@ -4315,6 +4395,46 @@ class TestParser < Minitest::Test
4315
4395
  ALL_VERSIONS - %w(1.8 1.9))
4316
4396
  end
4317
4397
 
4398
+ def test_bug_cmdarg
4399
+ assert_parses(
4400
+ s(:send, nil, :meth,
4401
+ s(:begin,
4402
+ s(:block,
4403
+ s(:send, nil, :lambda),
4404
+ s(:args), nil))),
4405
+ %q{meth (lambda do end)},
4406
+ %q{},
4407
+ %w(1.8))
4408
+
4409
+ assert_parses(
4410
+ s(:send, nil, :assert,
4411
+ s(:send, nil, :dogs)),
4412
+ %q{assert dogs})
4413
+
4414
+ assert_parses(
4415
+ s(:send, nil, :assert,
4416
+ s(:hash,
4417
+ s(:pair, s(:sym, :do), s(:true)))),
4418
+ %q{assert do: true},
4419
+ %q{},
4420
+ ALL_VERSIONS - %w(1.8))
4421
+
4422
+ assert_parses(
4423
+ s(:send, nil, :f,
4424
+ s(:hash,
4425
+ s(:pair,
4426
+ s(:sym, :x),
4427
+ s(:block,
4428
+ s(:send, nil, :lambda),
4429
+ s(:args),
4430
+ s(:block,
4431
+ s(:send, nil, :meth),
4432
+ s(:args), nil))))),
4433
+ %q{f x: -> do meth do end end},
4434
+ %q{},
4435
+ ALL_VERSIONS - %w(1.8))
4436
+ end
4437
+
4318
4438
  def test_file_line_non_literals
4319
4439
  with_versions(ALL_VERSIONS) do |_ver, parser|
4320
4440
  parser.builder.emit_file_line_as_literals = false
@@ -4349,6 +4469,18 @@ class TestParser < Minitest::Test
4349
4469
  %q{},
4350
4470
  %w(1.9 2.0 2.1))
4351
4471
  end
4472
+
4473
+ def test_regexp_encoding
4474
+ assert_parses(
4475
+ s(:match_with_lvasgn,
4476
+ s(:regexp,
4477
+ s(:str, "\\xa8"),
4478
+ s(:regopt, :n)),
4479
+ s(:str, "")),
4480
+ %q{/\xa8/n =~ ""}.force_encoding(Encoding::UTF_8),
4481
+ %{},
4482
+ ALL_VERSIONS - %w(1.8))
4483
+ end
4352
4484
  end
4353
4485
 
4354
4486
  #
@@ -4480,4 +4612,46 @@ class TestParser < Minitest::Test
4480
4612
  s(:def, :foo, s(:args), nil),
4481
4613
  %Q{def foo\n=begin\n=end\nend})
4482
4614
  end
4615
+
4616
+ def test_bug_while_not_parens_do
4617
+ assert_parses(
4618
+ s(:while, s(:send, s(:begin, s(:true)), :"!"), nil),
4619
+ %q{while not (true) do end},
4620
+ %q{},
4621
+ ALL_VERSIONS - %w(1.8))
4622
+ end
4623
+
4624
+ def test_bug_rescue_empty_else
4625
+ assert_parses(
4626
+ s(:kwbegin,
4627
+ s(:rescue, nil,
4628
+ s(:resbody,
4629
+ s(:array,
4630
+ s(:const, nil, :LoadError)), nil, nil), nil)),
4631
+ %q{begin; rescue LoadError; else; end},
4632
+ %q{ ~~~~ else (rescue)
4633
+ | ~~~~~~~~~~~~~~~~~~~~~~ expression (rescue)})
4634
+ end
4635
+
4636
+ def test_bug_heredoc_do
4637
+ assert_parses(
4638
+ s(:block,
4639
+ s(:send, nil, :f,
4640
+ s(:dstr)),
4641
+ s(:args), nil),
4642
+ %Q{f <<-TABLE do\nTABLE\nend})
4643
+ end
4644
+
4645
+ def test_bug_lambda_leakage
4646
+ assert_parses(
4647
+ s(:begin,
4648
+ s(:block,
4649
+ s(:send, nil, :lambda),
4650
+ s(:args,
4651
+ s(:arg, :scope)), nil),
4652
+ s(:send, nil, :scope)),
4653
+ %q{->(scope) {}; scope},
4654
+ %q{},
4655
+ ALL_VERSIONS - %w(1.8))
4656
+ end
4483
4657
  end
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.0.0.pre2
4
+ version: 2.0.0.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Zotov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-11 00:00:00.000000000 Z
11
+ date: 2013-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -198,6 +198,20 @@ dependencies:
198
198
  - - '>='
199
199
  - !ruby/object:Gem::Version
200
200
  version: '0'
201
+ - !ruby/object:Gem::Dependency
202
+ name: gauntlet
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - '>='
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
201
215
  description: A Ruby parser written in pure Ruby.
202
216
  email:
203
217
  - whitequark@whitequark.org
@@ -224,6 +238,7 @@ files:
224
238
  - doc/INTERNALS.md
225
239
  - doc/css/.gitkeep
226
240
  - doc/css/common.css
241
+ - lib/gauntlet_parser.rb
227
242
  - lib/parser.rb
228
243
  - lib/parser/all.rb
229
244
  - lib/parser/ast/node.rb