From 6998d758248d778fa95b008c78d05473e48b8428 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 29 Jul 2021 22:11:21 +0200 Subject: Update to ruby/spec@b65d01f --- spec/ruby/language/variables_spec.rb | 63 +++++++++++++++++------------------- 1 file changed, 30 insertions(+), 33 deletions(-) (limited to 'spec/ruby/language/variables_spec.rb') diff --git a/spec/ruby/language/variables_spec.rb b/spec/ruby/language/variables_spec.rb index ce072baa2c..7d6969e659 100644 --- a/spec/ruby/language/variables_spec.rb +++ b/spec/ruby/language/variables_spec.rb @@ -715,6 +715,18 @@ describe "Multiple assignment" do x.should == [1, 2, 3, 4, 5] end + it "can be used to swap array elements" do + a = [1, 2] + a[0], a[1] = a[1], a[0] + a.should == [2, 1] + end + + it "can be used to swap range of array elements" do + a = [1, 2, 3, 4] + a[0, 2], a[2, 2] = a[2, 2], a[0, 2] + a.should == [3, 4, 1, 2] + end + it "assigns RHS values to LHS constants" do module VariableSpecs MRHS_VALUES_1, MRHS_VALUES_2 = 1, 2 @@ -770,45 +782,30 @@ describe "A local variable assigned only within a conditional block" do end describe 'Local variable shadowing' do - ruby_version_is ""..."2.6" do - it "leads to warning in verbose mode" do - -> do - eval <<-CODE - a = [1, 2, 3] - a.each { |a| a = 3 } - CODE - end.should complain(/shadowing outer local variable/, verbose: true) - end - end - - ruby_version_is "2.6" do - it "does not warn in verbose mode" do - result = nil + it "does not warn in verbose mode" do + result = nil - -> do - eval <<-CODE - a = [1, 2, 3] - result = a.map { |a| a = 3 } - CODE - end.should_not complain(verbose: true) + -> do + eval <<-CODE + a = [1, 2, 3] + result = a.map { |a| a = 3 } + CODE + end.should_not complain(verbose: true) - result.should == [3, 3, 3] - end + result.should == [3, 3, 3] end end describe 'Allowed characters' do - ruby_version_is "2.6" do - # new feature in 2.6 -- https://bugs.ruby-lang.org/issues/13770 - it 'does not allow non-ASCII upcased characters at the beginning' do - -> do - eval <<-CODE - def test - ἍBB = 1 - end - CODE - end.should raise_error(SyntaxError, /dynamic constant assignment/) - end + # new feature in 2.6 -- https://bugs.ruby-lang.org/issues/13770 + it 'does not allow non-ASCII upcased characters at the beginning' do + -> do + eval <<-CODE + def test + ἍBB = 1 + end + CODE + end.should raise_error(SyntaxError, /dynamic constant assignment/) end it 'allows non-ASCII lowercased characters at the beginning' do -- cgit v1.2.3