From 52c630da004d9273e8e5fc91c6304e9eed902566 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 26 Oct 2020 18:00:24 +0900 Subject: Assoc pattern matching (#3703) [Feature #17260] One-line pattern matching using tASSOC R-assignment is rejected instead. --- spec/ruby/command_line/dash_upper_w_spec.rb | 4 ++-- spec/ruby/command_line/rubyopt_spec.rb | 4 ++-- spec/ruby/core/warning/element_set_spec.rb | 4 ++-- spec/ruby/language/pattern_matching_spec.rb | 12 +++++++----- 4 files changed, 13 insertions(+), 11 deletions(-) (limited to 'spec/ruby') diff --git a/spec/ruby/command_line/dash_upper_w_spec.rb b/spec/ruby/command_line/dash_upper_w_spec.rb index 8343bc08e4..2b617f9f7f 100644 --- a/spec/ruby/command_line/dash_upper_w_spec.rb +++ b/spec/ruby/command_line/dash_upper_w_spec.rb @@ -32,10 +32,10 @@ ruby_version_is "2.7" do describe "The -W command line option with :no-experimental" do it "suppresses experimental warnings" do - result = ruby_exe('0 in a', args: '2>&1') + result = ruby_exe('case 0; in a; end', args: '2>&1') result.should =~ /is experimental/ - result = ruby_exe('0 in a', options: '-W:no-experimental', args: '2>&1') + result = ruby_exe('case 0; in a; end', options: '-W:no-experimental', args: '2>&1') result.should == "" end end diff --git a/spec/ruby/command_line/rubyopt_spec.rb b/spec/ruby/command_line/rubyopt_spec.rb index ee4e594a1c..a739f23eb8 100644 --- a/spec/ruby/command_line/rubyopt_spec.rb +++ b/spec/ruby/command_line/rubyopt_spec.rb @@ -68,13 +68,13 @@ describe "Processing RUBYOPT" do it "suppresses experimental warnings for '-W:no-experimental'" do ENV["RUBYOPT"] = '-W:no-experimental' - result = ruby_exe('0 in a', args: '2>&1') + result = ruby_exe('case 0; in a; end', args: '2>&1') result.should == "" end it "suppresses deprecation and experimental warnings for '-W:no-deprecated -W:no-experimental'" do ENV["RUBYOPT"] = '-W:no-deprecated -W:no-experimental' - result = ruby_exe('($; = "") in a', args: '2>&1') + result = ruby_exe('case ($; = ""); in a; end', args: '2>&1') result.should == "" end end diff --git a/spec/ruby/core/warning/element_set_spec.rb b/spec/ruby/core/warning/element_set_spec.rb index ee83656cb4..a6b28282a0 100644 --- a/spec/ruby/core/warning/element_set_spec.rb +++ b/spec/ruby/core/warning/element_set_spec.rb @@ -8,8 +8,8 @@ ruby_version_is '2.7' do end it "emits and suppresses warnings for :experimental" do - ruby_exe('Warning[:experimental] = true; eval("0 in a")', args: "2>&1").should =~ /is experimental/ - ruby_exe('Warning[:experimental] = false; eval("0 in a")', args: "2>&1").should == "" + ruby_exe('Warning[:experimental] = true; eval("case 0; in a; end")', args: "2>&1").should =~ /is experimental/ + ruby_exe('Warning[:experimental] = false; eval("case 0; in a; end")', args: "2>&1").should == "" end it "raises for unknown category" do diff --git a/spec/ruby/language/pattern_matching_spec.rb b/spec/ruby/language/pattern_matching_spec.rb index 91ad23bf32..2d22ec7e64 100644 --- a/spec/ruby/language/pattern_matching_spec.rb +++ b/spec/ruby/language/pattern_matching_spec.rb @@ -9,11 +9,13 @@ ruby_version_is "2.7" do ScratchPad.record [] end - it "can be standalone in operator that deconstructs value" do - eval(<<-RUBY).should == [0, 1] - [0, 1] in [a, b] - [a, b] - RUBY + ruby_version_is "3.0" do + it "can be standalone assoc operator that deconstructs value" do + eval(<<-RUBY).should == [0, 1] + [0, 1] => [a, b] + [a, b] + RUBY + end end it "extends case expression with case/in construction" do -- cgit v1.2.3