summaryrefslogtreecommitdiff
path: root/test/ruby/test_literal.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2021-06-03 12:26:52 +0900
committerNobuyoshi Nakada <[email protected]>2021-06-03 15:11:18 +0900
commita023db49bfbbbe119638bae6abf8113f0de371de (patch)
treed94e1cc497c41df315d830b0a1a20dae01ce0f4a /test/ruby/test_literal.rb
parent31b9ce365dff68f2e7a96b78d7dded98e338e5c6 (diff)
Assertions for duplicate literal hash key warnings
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4548
Diffstat (limited to 'test/ruby/test_literal.rb')
-rw-r--r--test/ruby/test_literal.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb
index 679af20bb9..10cb09b833 100644
--- a/test/ruby/test_literal.rb
+++ b/test/ruby/test_literal.rb
@@ -461,17 +461,30 @@ class TestRubyLiteral < Test::Unit::TestCase
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