diff options
Diffstat (limited to 'test/ruby/test_pattern_matching.rb')
-rw-r--r-- | test/ruby/test_pattern_matching.rb | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index fbb934dc84..cfe3bd1e19 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -9,14 +9,14 @@ class TestPatternMatching < Test::Unit::TestCase end def setup - if defined?(DidYouMean) + if defined?(DidYouMean.formatter=nil) @original_formatter = DidYouMean.formatter DidYouMean.formatter = NullFormatter.new end end def teardown - if defined?(DidYouMean) + if defined?(DidYouMean.formatter=nil) DidYouMean.formatter = @original_formatter end end @@ -109,16 +109,12 @@ class TestPatternMatching < Test::Unit::TestCase end assert_block do - # suppress "warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!" - experimental, Warning[:experimental] = Warning[:experimental], false eval(%q{ case true in a a end }) - ensure - Warning[:experimental] = experimental end assert_block do @@ -358,6 +354,14 @@ END end assert_block do + a = "abc" + case 'abc' + in /#{a}/o + true + end + end + + assert_block do case 0 in ->(i) { i == 0 } true @@ -464,6 +468,8 @@ END true end end + + assert_valid_syntax("1 in ^(1\n)") end def test_array_pattern @@ -798,6 +804,10 @@ END true end end + + assert_syntax_error(%q{ + 0 => [a, *a] + }, /duplicated variable name/) end def test_find_pattern @@ -866,6 +876,10 @@ END false end end + + assert_syntax_error(%q{ + 0 => [*a, a, b, *b] + }, /duplicated variable name/) end def test_hash_pattern @@ -1155,7 +1169,7 @@ END end end - bug18890 = assert_warning(/(?:.*:[47]: warning: unused literal ignored\n){2}/) do + bug18890 = assert_warning(/(?:.*:[47]: warning: possibly useless use of a literal in void context\n){2}/) do eval("#{<<~';;;'}") proc do |i| case i @@ -1317,7 +1331,7 @@ END end assert_block do - case {} + case C.new({}) in {} C.keys == nil end |