summaryrefslogtreecommitdiff
path: root/spec/ruby/language
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2022-01-10 16:29:54 +0100
committerBenoit Daloze <eregontp@gmail.com>2022-01-10 16:29:54 +0100
commit4053e8ba0d39b688440fedee2ab3fffabcd64312 (patch)
tree8a29366a09cd159798fada68fb1007a2fece5ec6 /spec/ruby/language
parent8abfc106058d09840d13f64e7e87cb7e40c3d6fa (diff)
Update to ruby/spec@226cfdc
Diffstat (limited to 'spec/ruby/language')
-rw-r--r--spec/ruby/language/case_spec.rb9
-rw-r--r--spec/ruby/language/class_spec.rb13
-rw-r--r--spec/ruby/language/constants_spec.rb14
-rw-r--r--spec/ruby/language/def_spec.rb2
-rw-r--r--spec/ruby/language/pattern_matching_spec.rb59
-rw-r--r--spec/ruby/language/variables_spec.rb21
6 files changed, 106 insertions, 12 deletions
diff --git a/spec/ruby/language/case_spec.rb b/spec/ruby/language/case_spec.rb
index 410cb9afb1..bf06803764 100644
--- a/spec/ruby/language/case_spec.rb
+++ b/spec/ruby/language/case_spec.rb
@@ -156,6 +156,15 @@ describe "The 'case'-construct" do
end.should == "foo"
end
+ it "tests an empty array" do
+ case []
+ when []
+ 'foo'
+ else
+ 'bar'
+ end.should == 'foo'
+ end
+
it "expands arrays to lists of values" do
case 'z'
when *['a', 'b', 'c', 'd']
diff --git a/spec/ruby/language/class_spec.rb b/spec/ruby/language/class_spec.rb
index 83db164e1a..877895bf15 100644
--- a/spec/ruby/language/class_spec.rb
+++ b/spec/ruby/language/class_spec.rb
@@ -17,6 +17,19 @@ describe "The class keyword" do
eval "class ClassSpecsKeywordWithoutSemicolon end"
ClassSpecsKeywordWithoutSemicolon.should be_an_instance_of(Class)
end
+
+ it "can redefine a class when called from a block" do
+ ClassSpecs::DEFINE_CLASS.call
+ A.should be_an_instance_of(Class)
+
+ Object.send(:remove_const, :A)
+ defined?(A).should be_nil
+
+ ClassSpecs::DEFINE_CLASS.call
+ A.should be_an_instance_of(Class)
+ ensure
+ Object.send(:remove_const, :A) if defined?(::A)
+ end
end
describe "A class definition" do
diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb
index 03f1272401..bc76c60d20 100644
--- a/spec/ruby/language/constants_spec.rb
+++ b/spec/ruby/language/constants_spec.rb
@@ -718,3 +718,17 @@ describe 'Allowed characters' do
eval("mod::ἍBB").should == 1
end
end
+
+describe 'Assignment' do
+ context 'dynamic assignment' do
+ it 'raises SyntaxError' do
+ -> do
+ eval <<-CODE
+ def test
+ B = 1
+ end
+ CODE
+ end.should raise_error(SyntaxError, /dynamic constant assignment/)
+ end
+ end
+end
diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb
index 6b0be19d90..d72f8fa888 100644
--- a/spec/ruby/language/def_spec.rb
+++ b/spec/ruby/language/def_spec.rb
@@ -213,7 +213,7 @@ describe "An instance method with a default argument" do
end
ruby_version_is '2.7' do
- it "raises a syntaxError an existing method with the same name as the local variable" do
+ it "raises a SyntaxError when there is an existing method with the same name as the local variable" do
def bar
1
end
diff --git a/spec/ruby/language/pattern_matching_spec.rb b/spec/ruby/language/pattern_matching_spec.rb
index e4abae9412..5f5e2f4902 100644
--- a/spec/ruby/language/pattern_matching_spec.rb
+++ b/spec/ruby/language/pattern_matching_spec.rb
@@ -1297,6 +1297,65 @@ ruby_version_is "2.7" do
a
RUBY
end
+
+ it "supports pinning instance variables" do
+ eval(<<~RUBY).should == true
+ @a = /a/
+ case 'abc'
+ in ^@a
+ true
+ end
+ RUBY
+ end
+
+ it "supports pinning class variables" do
+ result = nil
+ Module.new do
+ result = module_eval(<<~RUBY)
+ @@a = 0..10
+
+ case 2
+ in ^@@a
+ true
+ end
+ RUBY
+ end
+
+ result.should == true
+ end
+
+ it "supports pinning global variables" do
+ eval(<<~RUBY).should == true
+ $a = /a/
+ case 'abc'
+ in ^$a
+ true
+ end
+ RUBY
+ end
+
+ it "supports pinning expressions" do
+ eval(<<~RUBY).should == true
+ case 'abc'
+ in ^(/a/)
+ true
+ end
+ RUBY
+
+ eval(<<~RUBY).should == true
+ case {name: '2.6', released_at: Time.new(2018, 12, 25)}
+ in {released_at: ^(Time.new(2010)..Time.new(2020))}
+ true
+ end
+ RUBY
+
+ eval(<<~RUBY).should == true
+ case 0
+ in ^(0+0)
+ true
+ end
+ RUBY
+ end
end
end
end
diff --git a/spec/ruby/language/variables_spec.rb b/spec/ruby/language/variables_spec.rb
index 699187335c..431c5aca99 100644
--- a/spec/ruby/language/variables_spec.rb
+++ b/spec/ruby/language/variables_spec.rb
@@ -797,17 +797,6 @@ describe 'Local variable shadowing' do
end
describe 'Allowed characters' 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
-
it 'allows non-ASCII lowercased characters at the beginning' do
result = nil
@@ -821,6 +810,16 @@ describe 'Allowed characters' do
result.should == 1
end
+
+ it 'parses a non-ASCII upcased character as a constant identifier' do
+ -> do
+ eval <<-CODE
+ def test
+ ἍBB = 1
+ end
+ CODE
+ end.should raise_error(SyntaxError, /dynamic constant assignment/)
+ end
end
describe "Instance variables" do