summaryrefslogtreecommitdiff
path: root/spec/ruby/language/variables_spec.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2021-07-29 22:11:21 +0200
committerBenoit Daloze <eregontp@gmail.com>2021-07-29 22:11:21 +0200
commit6998d758248d778fa95b008c78d05473e48b8428 (patch)
tree8abc6926f647ea5f374a5b34c3a4820c5861e32e /spec/ruby/language/variables_spec.rb
parent15d05f8120745a121b93fab9fd2addf5f094e8d2 (diff)
Update to ruby/spec@b65d01f
Diffstat (limited to 'spec/ruby/language/variables_spec.rb')
-rw-r--r--spec/ruby/language/variables_spec.rb63
1 files changed, 30 insertions, 33 deletions
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