ruby-changes:66417
From: Nobuyoshi <ko1@a...>
Date: Thu, 3 Jun 2021 15:11:36 +0900 (JST)
Subject: [ruby-changes:66417] a023db49bf (master): Assertions for duplicate literal hash key warnings
https://git.ruby-lang.org/ruby.git/commit/?id=a023db49bf From a023db49bfbbbe119638bae6abf8113f0de371de Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 3 Jun 2021 12:26:52 +0900 Subject: Assertions for duplicate literal hash key warnings --- test/ruby/test_literal.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb index 679af20..10cb09b 100644 --- a/test/ruby/test_literal.rb +++ b/test/ruby/test_literal.rb @@ -461,17 +461,30 @@ class TestRubyLiteral < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_literal.rb#L461 def test_hash_duplicated_key h = EnvUtil.suppress_warning do - eval <<~end + eval "#{<<-"begin;"}\n#{<<-'end;'}" + begin; # This is a syntax that renders warning at very early stage. # eval used to delay warning, to be suppressible by EnvUtil. {"a" => 100, "b" => 200, "a" => 300, "a" => 400} - end + end; end assert_equal(2, h.size) assert_equal(400, h['a']) assert_equal(200, h['b']) assert_nil(h['c']) assert_equal(nil, h.key('300')) + + assert_all_assertions_foreach( + "duplicated literal key", + ':foo', + '"a"', + '1000', + '1.0', + ) do |key| + assert_warning(/key #{Regexp.quote(eval(key).inspect)} is duplicated/) do + eval("{#{key} => :bar, #{key} => :foo}") + end + end end def test_hash_frozen_key_id -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/