aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/language
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2022-01-28 14:42:38 +0100
committerBenoit Daloze <eregontp@gmail.com>2022-01-28 14:42:38 +0100
commite0c5488ff9308b1a16718c64bc9096caca88ed83 (patch)
treeb0ede98f96c4477c470bef45547abff525215b21 /spec/ruby/language
parentbb5f71088774b14c96fe11718e5e1b7ffb20fff2 (diff)
downloadruby-e0c5488ff9308b1a16718c64bc9096caca88ed83.tar.gz
Update to ruby/spec@902ab83
Diffstat (limited to 'spec/ruby/language')
-rw-r--r--spec/ruby/language/pattern_matching_spec.rb44
-rw-r--r--spec/ruby/language/range_spec.rb6
-rw-r--r--spec/ruby/language/rescue_spec.rb12
3 files changed, 56 insertions, 6 deletions
diff --git a/spec/ruby/language/pattern_matching_spec.rb b/spec/ruby/language/pattern_matching_spec.rb
index 5f5e2f4902..c68b6caa34 100644
--- a/spec/ruby/language/pattern_matching_spec.rb
+++ b/spec/ruby/language/pattern_matching_spec.rb
@@ -74,6 +74,50 @@ ruby_version_is "2.7" do
end
RUBY
end
+
+ it "can be nested" do
+ eval(<<~RUBY).should == [[0, [2, 4, 6]], [[4, 16, 64]], 27]
+ case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]]
+ in [*pre, [*, 9, a], *post]
+ [pre, post, a]
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "can be nested with an array pattern" do
+ eval(<<~RUBY).should == [[4, 16, 64]]
+ case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]]
+ in [_, _, [*, 9, *], *post]
+ post
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "can be nested within a hash pattern" do
+ eval(<<~RUBY).should == [27]
+ case {a: [3, 9, 27]}
+ in {a: [*, 9, *post]}
+ post
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "can nest hash and array patterns" do
+ eval(<<~RUBY).should == [42, 2]
+ case [0, {a: 42, b: [0, 1]}, {a: 42, b: [1, 2]}]
+ in [*, {a:, b: [1, c]}, *]
+ [a, c]
+ else
+ false
+ end
+ RUBY
+ end
end
end
diff --git a/spec/ruby/language/range_spec.rb b/spec/ruby/language/range_spec.rb
index 4cde7e9488..79500c6b33 100644
--- a/spec/ruby/language/range_spec.rb
+++ b/spec/ruby/language/range_spec.rb
@@ -15,12 +15,6 @@ describe "Literal Ranges" do
(1...).should == Range.new(1, nil, true)
end
- ruby_version_is "3.0" do
- it "is frozen" do
- (42..).should.frozen?
- end
- end
-
ruby_version_is "2.7" do
it "creates beginless ranges" do
eval("(..1)").should == Range.new(nil, 1)
diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb
index 4d164b38c6..fcd9ae0de9 100644
--- a/spec/ruby/language/rescue_spec.rb
+++ b/spec/ruby/language/rescue_spec.rb
@@ -115,6 +115,18 @@ describe "The rescue keyword" do
end
end
+ it "converts the splatted list of exceptions using #to_a" do
+ exceptions = mock("to_a")
+ exceptions.should_receive(:to_a).and_return(exception_list)
+ caught_it = false
+ begin
+ raise SpecificExampleException, "not important"
+ rescue *exceptions
+ caught_it = true
+ end
+ caught_it.should be_true
+ end
+
it "can combine a splatted list of exceptions with a literal list of exceptions" do
caught_it = false
begin