Merge pull request #423 from backus/enhancement/zero-arity-arg-splat-mutation
Add mutation `def foo(*args); end` into `def foo(*args); args = []; end`
This commit is contained in:
commit
9d0355075d
6 changed files with 57 additions and 1 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
* Add mutation from `a != b` to `!a.eql?(b)` and `!a.equal?(b)` #417
|
||||
* Add mutation `A.const_get(:B)` -> `A::B` #426
|
||||
* Add mutation `def foo(*args); end` into `def foo(*args); args = []; end` #423
|
||||
|
||||
# v0.8.3 2015-09-01
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 18
|
||||
total_score: 1214
|
||||
total_score: 1219
|
||||
|
|
|
@ -52,6 +52,7 @@ require 'mutant/ast/meta/send'
|
|||
require 'mutant/ast/meta/symbol'
|
||||
require 'mutant/ast/meta/optarg'
|
||||
require 'mutant/ast/meta/resbody'
|
||||
require 'mutant/ast/meta/restarg'
|
||||
require 'mutant/actor'
|
||||
require 'mutant/actor/receiver'
|
||||
require 'mutant/actor/sender'
|
||||
|
|
15
lib/mutant/ast/meta/restarg.rb
Normal file
15
lib/mutant/ast/meta/restarg.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Mutant
|
||||
module AST
|
||||
# Node meta information mixin
|
||||
module Meta
|
||||
|
||||
# Metadata for restarg nodes
|
||||
class Restarg
|
||||
include NamedChildren, Concord.new(:node)
|
||||
|
||||
children :name
|
||||
end # Restarg
|
||||
|
||||
end # Meta
|
||||
end # AST
|
||||
end # Mutant
|
|
@ -14,6 +14,7 @@ module Mutant
|
|||
def dispatch
|
||||
emit_arguments_mutations
|
||||
emit_optarg_body_assignments
|
||||
emit_restarg_body_mutation
|
||||
emit_body(N_RAISE)
|
||||
emit_body(nil)
|
||||
emit_body_mutations if body
|
||||
|
@ -32,6 +33,19 @@ module Mutant
|
|||
end
|
||||
end
|
||||
|
||||
# Emit mutation with arg splat as empty array signment in method
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
def emit_restarg_body_mutation
|
||||
arguments.children.each do |argument|
|
||||
next unless n_restarg?(argument) && argument.children.one?
|
||||
|
||||
emit_body_prepend(s(:lvasgn, AST::Meta::Restarg.new(argument).name, s(:array)))
|
||||
end
|
||||
end
|
||||
|
||||
# Emit valid body ASTs depending on instance body
|
||||
#
|
||||
# @param node [Parser::AST::Node]
|
||||
|
|
25
meta/def.rb
25
meta/def.rb
|
@ -5,6 +5,31 @@ Mutant::Meta::Example.add do
|
|||
mutation 'remove_method :foo'
|
||||
end
|
||||
|
||||
Mutant::Meta::Example.add do
|
||||
source 'def foo(a, *b); nil; end'
|
||||
|
||||
mutation 'def foo(_a, *b); nil; end'
|
||||
mutation 'def foo; nil; end'
|
||||
mutation 'def foo(a, *b); end'
|
||||
mutation 'def foo(a, *b); raise; end'
|
||||
mutation 'def foo(a); nil; end'
|
||||
mutation 'def foo(*b); nil; end'
|
||||
mutation 'def foo(a, *b); b = []; nil; end'
|
||||
mutation 'remove_method :foo'
|
||||
end
|
||||
|
||||
Mutant::Meta::Example.add do
|
||||
source 'def foo(a, *); nil; end'
|
||||
|
||||
mutation 'def foo(_a, *); nil; end'
|
||||
mutation 'def foo; nil; end'
|
||||
mutation 'def foo(a, *); end'
|
||||
mutation 'def foo(a, *); raise; end'
|
||||
mutation 'def foo(a); nil; end'
|
||||
mutation 'def foo(*); nil; end'
|
||||
mutation 'remove_method :foo'
|
||||
end
|
||||
|
||||
Mutant::Meta::Example.add do
|
||||
source 'def foo; foo; rescue; end'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue