Merge pull request #70 from mbj/add-variable-mutator
Add variable mutator
This commit is contained in:
commit
55c68a7b25
7 changed files with 72 additions and 10 deletions
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 16
|
||||
total_score: 719
|
||||
total_score: 722
|
||||
|
|
|
@ -58,7 +58,7 @@ require 'mutant/mutator/node/assignment'
|
|||
require 'mutant/mutator/node/argument'
|
||||
require 'mutant/mutator/node/arguments'
|
||||
require 'mutant/mutator/node/begin'
|
||||
require 'mutant/mutator/node/lvar'
|
||||
require 'mutant/mutator/node/variable'
|
||||
require 'mutant/mutator/node/while'
|
||||
require 'mutant/mutator/node/super'
|
||||
require 'mutant/mutator/node/send'
|
||||
|
|
|
@ -11,10 +11,10 @@ module Mutant
|
|||
# your contribution is that close!
|
||||
handle(
|
||||
:zsuper, :not, :or, :and, :defined,
|
||||
:next, :break, :match, :gvar, :cvar, :ensure,
|
||||
:next, :break, :match, :ensure,
|
||||
:dstr, :dsym, :yield, :rescue, :redo, :defined?,
|
||||
:const, :blockarg, :block_pass, :op_asgn, :and_asgn,
|
||||
:regopt, :ivar, :restarg, :casgn, :resbody, :retry, :arg_expr,
|
||||
:regopt, :restarg, :casgn, :resbody, :retry, :arg_expr,
|
||||
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :cbase, :empty,
|
||||
:alias, :for, :xstr, :back_ref, :nth_ref, :class,
|
||||
:sclass, :match_with_lvasgn, :match_current_line, :or_asgn, :kwbegin
|
||||
|
@ -30,8 +30,7 @@ module Mutant
|
|||
#
|
||||
def dispatch
|
||||
children.each_with_index do |child, index|
|
||||
next unless child.kind_of?(Parser::AST::Node)
|
||||
mutate_child(index)
|
||||
mutate_child(index) if child.kind_of?(Parser::AST::Node)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@ module Mutant
|
|||
class Mutator
|
||||
class Node
|
||||
|
||||
# Mutation emitter to handle local variable nodes
|
||||
class LocalVariable < self
|
||||
# Mutation emitter to handle variable nodes
|
||||
class Variable < self
|
||||
|
||||
handle(:lvar)
|
||||
handle(:gvar, :cvar, :ivar, :lvar)
|
||||
|
||||
private
|
||||
|
||||
|
@ -19,7 +19,7 @@ module Mutant
|
|||
emit_nil
|
||||
end
|
||||
|
||||
end # LocalVariable
|
||||
end # Variable
|
||||
end # Node
|
||||
end # Mutator
|
||||
end # Mutant
|
21
spec/unit/mutant/mutator/node/cvar/mutation_spec.rb
Normal file
21
spec/unit/mutant/mutator/node/cvar/mutation_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Mutator, 'cvar' do
|
||||
|
||||
before do
|
||||
Mutant::Random.stub(:hex_string => 'random')
|
||||
end
|
||||
|
||||
let(:source) { '@@a = nil; @@a' }
|
||||
|
||||
let(:mutations) do
|
||||
mutants = []
|
||||
mutants << '@@a = nil; nil'
|
||||
mutants << '@@a = nil'
|
||||
mutants << '@@a'
|
||||
mutants << '@@a = ::Object.new; @@a'
|
||||
mutants << '@@srandom = nil; @@a'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
21
spec/unit/mutant/mutator/node/gvar/mutation_spec.rb
Normal file
21
spec/unit/mutant/mutator/node/gvar/mutation_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Mutator, 'gvar' do
|
||||
|
||||
before do
|
||||
Mutant::Random.stub(:hex_string => 'random')
|
||||
end
|
||||
|
||||
let(:source) { '$a = nil; $a' }
|
||||
|
||||
let(:mutations) do
|
||||
mutants = []
|
||||
mutants << '$a = nil; nil'
|
||||
mutants << '$a = nil'
|
||||
mutants << '$a'
|
||||
mutants << '$a = ::Object.new; $a'
|
||||
mutants << '$srandom = nil; $a'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
21
spec/unit/mutant/mutator/node/ivar/mutation_spec.rb
Normal file
21
spec/unit/mutant/mutator/node/ivar/mutation_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Mutator, 'ivar' do
|
||||
|
||||
before do
|
||||
Mutant::Random.stub(:hex_string => 'random')
|
||||
end
|
||||
|
||||
let(:source) { '@a = nil; @a' }
|
||||
|
||||
let(:mutations) do
|
||||
mutants = []
|
||||
mutants << '@a = nil; nil'
|
||||
mutants << '@a = nil'
|
||||
mutants << '@a'
|
||||
mutants << '@a = ::Object.new; @a'
|
||||
mutants << '@srandom = nil; @a'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
Loading…
Reference in a new issue