diff --git a/config/flay.yml b/config/flay.yml index 47bf198e..860f2976 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 16 -total_score: 1309 +total_score: 1317 diff --git a/lib/mutest/mutator/node/arguments.rb b/lib/mutest/mutator/node/arguments.rb index 8b7f6bcf..0718891b 100644 --- a/lib/mutest/mutator/node/arguments.rb +++ b/lib/mutest/mutator/node/arguments.rb @@ -13,6 +13,7 @@ class Arguments < self def dispatch emit_argument_presence emit_argument_mutations + emit_hash_type_hint emit_mlhs_expansion end @@ -47,6 +48,22 @@ def invalid_argument_replacement?(mutest, index) n_arg?(mutest) && children[0...index].any?(&method(:n_optarg?)) end + def emit_hash_type_hint + *first_args, last_arg = children + + return unless last_arg && hintworthy_node?(last_arg) + + last_name = last_arg.children.first + + emit_type(*first_args, s(:kwrestarg, last_name)) unless last_name.to_s.start_with?('_') + end + + # Is this a simple arg or arg={} ? + def hintworthy_node?(node) + n_arg?(node) || + (n_optarg?(node) && node.children.last.eql?(s(:hash))) + end + # Emit mlhs expansions # # @return [undefined] diff --git a/meta/block.rb b/meta/block.rb index 9627b4ec..6cafea47 100644 --- a/meta/block.rb +++ b/meta/block.rb @@ -19,6 +19,7 @@ singleton_mutations mutation 'foo' + mutation 'foo { |a, **b| }' mutation 'foo { |a, b| raise }' mutation 'foo { |a, _b| }' mutation 'foo { |_a, b| }' @@ -32,6 +33,7 @@ singleton_mutations mutation 'foo { || }' + mutation 'foo { |(a, b), **c| }' mutation 'foo { |a, b, c| }' mutation 'foo { |(a, b), c| raise }' mutation 'foo { |(a), c| }' diff --git a/meta/def.rb b/meta/def.rb index e50bd6bf..8f89ce2b 100644 --- a/meta/def.rb +++ b/meta/def.rb @@ -5,6 +5,30 @@ mutation 'def foo; super; end' end +Mutest::Meta::Example.add :def do + source 'def foo(a); end' + + mutation 'def foo; end' + mutation 'def foo(_a); end' + mutation 'def foo(**a); end' + mutation 'def foo(a); raise; end' + mutation 'def foo(a); super; end' +end + +Mutest::Meta::Example.add :def do + source 'def foo(a = {}); end' + + mutation 'def foo; end' + mutation 'def foo(**a); end' + mutation 'def foo(_a = {}); end' + mutation 'def foo(a); end' + mutation 'def foo(a = nil); end' + mutation 'def foo(a = self); end' + mutation 'def foo(a = {}); a = {}; end' + mutation 'def foo(a = {}); super; end' + mutation 'def foo(a = {}); raise; end' +end + Mutest::Meta::Example.add :def do source 'def foo(a, *b); nil; end' @@ -106,6 +130,9 @@ # Deletion of all arguments mutation 'def foo; end' + # Hash type hint + mutation 'def foo(a, **b); end' + # Rename each argument mutation 'def foo(_a, b); end' mutation 'def foo(a, _b); end' @@ -220,6 +247,9 @@ # Deletion of all arguments mutation 'def self.foo; end' + # Hash type hint + mutation 'def self.foo(a, **b); end' + # Rename each argument mutation 'def self.foo(_a, b); end' mutation 'def self.foo(a, _b); end'