Assertions for duplicate literal hash key warnings

This commit is contained in:
Nobuyoshi Nakada 2021-06-03 12:26:52 +09:00
Родитель 31b9ce365d
Коммит a023db49bf
1 изменённых файлов: 15 добавлений и 2 удалений

Просмотреть файл

@ -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