Skip to content
This repository was archived by the owner on Aug 23, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/flay.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
threshold: 16
total_score: 1309
total_score: 1317
17 changes: 17 additions & 0 deletions lib/mutest/mutator/node/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Arguments < self
def dispatch
emit_argument_presence
emit_argument_mutations
emit_hash_type_hint
emit_mlhs_expansion
end

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions meta/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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| }'
Expand All @@ -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| }'
Expand Down
30 changes: 30 additions & 0 deletions meta/def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down