From a756dae95b75b1dec6ae4510fe060247ed477c3c Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Fri, 9 Feb 2024 16:38:47 +0000 Subject: [PATCH] Fix mutation to invalid hash pattern [fix #1417] --- lib/mutant/mutator/node/literal/hash.rb | 4 +++- meta/case.rb | 14 ++++++++++++++ meta/def.rb | 1 - 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/mutant/mutator/node/literal/hash.rb b/lib/mutant/mutator/node/literal/hash.rb index 5bdefc219..8dce21773 100644 --- a/lib/mutant/mutator/node/literal/hash.rb +++ b/lib/mutant/mutator/node/literal/hash.rb @@ -36,7 +36,9 @@ class Pair < Node private def dispatch - emit_key_mutations + emit_key_mutations do |mutation| + !mutation.eql?(s(:nil)) + end emit_value_mutations end diff --git a/meta/case.rb b/meta/case.rb index b8dd0228d..96b677b25 100644 --- a/meta/case.rb +++ b/meta/case.rb @@ -1,5 +1,19 @@ # frozen_string_literal: true +Mutant::Meta::Example.add :case do + source <<-RUBY + case nil + in { a: nil } + end + RUBY + + mutation <<~RUBY + case nil + in {a__mutant__: nil} + end + RUBY +end + Mutant::Meta::Example.add :case do source <<-RUBY case diff --git a/meta/def.rb b/meta/def.rb index 44cde4776..01c3ae9c5 100644 --- a/meta/def.rb +++ b/meta/def.rb @@ -226,7 +226,6 @@ mutation 'def foo(**); { ** }; end' mutation 'def foo(**); { default: nil }; end' mutation 'def foo(**); { default__mutant__: nil, ** }; end' - mutation 'def foo(**); { nil => nil, ** }; end' mutation 'def foo(**); {}; end' end