Add const mutator
* The const node has children, which need to be mutated
This commit is contained in:
parent
666b6f7e76
commit
345b67144a
5 changed files with 48 additions and 12 deletions
|
@ -57,6 +57,7 @@ require 'mutant/mutator/node/literal/nil'
|
|||
require 'mutant/mutator/node/argument'
|
||||
require 'mutant/mutator/node/arguments'
|
||||
require 'mutant/mutator/node/begin'
|
||||
require 'mutant/mutator/node/const'
|
||||
require 'mutant/mutator/node/named_value/access'
|
||||
require 'mutant/mutator/node/named_value/constant_assignment'
|
||||
require 'mutant/mutator/node/named_value/variable_assignment'
|
||||
|
|
28
lib/mutant/mutator/node/const.rb
Normal file
28
lib/mutant/mutator/node/const.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Mutant
|
||||
class Mutator
|
||||
class Node
|
||||
|
||||
# Mutation emitter to handle const nodes
|
||||
class Const < self
|
||||
|
||||
handle(:const)
|
||||
|
||||
private
|
||||
|
||||
# Emit mutations
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def dispatch
|
||||
emit_nil
|
||||
children.each_with_index do |child, index|
|
||||
mutate_child(index) if child.kind_of?(Parser::AST::Node)
|
||||
end
|
||||
end
|
||||
|
||||
end # Const
|
||||
end # Node
|
||||
end # Mutator
|
||||
end # Mutant
|
|
@ -6,7 +6,7 @@ module Mutant
|
|||
# Mutation emitter to handle named value access nodes
|
||||
class Access < Node
|
||||
|
||||
handle(:gvar, :cvar, :ivar, :lvar, :const, :self)
|
||||
handle(:gvar, :cvar, :ivar, :lvar, :self)
|
||||
|
||||
private
|
||||
|
||||
|
|
18
spec/unit/mutant/mutator/node/const/mutation_spec.rb
Normal file
18
spec/unit/mutant/mutator/node/const/mutation_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Mutator::Node::NamedValue::Access, 'const' do
|
||||
|
||||
before do
|
||||
Mutant::Random.stub(:hex_string => :random)
|
||||
end
|
||||
|
||||
let(:source) { 'A::B' }
|
||||
|
||||
let(:mutations) do
|
||||
mutants = []
|
||||
mutants << 'nil'
|
||||
mutants << 'nil::B'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
|
@ -64,17 +64,6 @@ describe Mutant::Mutator::Node::NamedValue::Access, 'mutations' do
|
|||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
||||
context 'constant' do
|
||||
let(:source) { 'A' }
|
||||
|
||||
let(:mutations) do
|
||||
mutants = []
|
||||
mutants << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
||||
context 'self' do
|
||||
let(:source) { 'self' }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue