Add constant assignment mutator

This commit is contained in:
Dan Kubb 2013-07-23 00:23:21 -07:00
parent e15fd87a93
commit 1e14b7f703
4 changed files with 64 additions and 1 deletions

View file

@ -58,6 +58,7 @@ require 'mutant/mutator/node/argument'
require 'mutant/mutator/node/arguments'
require 'mutant/mutator/node/begin'
require 'mutant/mutator/node/named_value/access'
require 'mutant/mutator/node/named_value/constant_assignment'
require 'mutant/mutator/node/named_value/variable_assignment'
require 'mutant/mutator/node/while'
require 'mutant/mutator/node/super'

View file

@ -14,7 +14,7 @@ module Mutant
:next, :break, :match, :ensure,
:dstr, :dsym, :yield, :rescue, :redo, :defined?,
:blockarg, :block_pass, :op_asgn, :and_asgn,
:regopt, :restarg, :casgn, :resbody, :retry, :arg_expr,
:regopt, :restarg, :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

View file

@ -0,0 +1,42 @@
module Mutant
class Mutator
class Node
module NamedValue
# Mutation emitter to handle constant assignment nodes
class ConstantAssignment < Node
children :cbase, :name, :value
handle :casgn
private
# Perform dispatch
#
# @return [undefined]
#
# @api private
#
def dispatch
mutate_name
emit_value_mutations if value
end
# Emit name mutations
#
# @return [undefined]
#
# @api private
#
def mutate_name
Mutator::Util::Symbol.each(name, self) do |name|
emit_name(name.upcase)
end
end
end # ConstantAssignment
end # NamedValue
end # Node
end # Mutator
end # Mutant

View file

@ -0,0 +1,20 @@
require 'spec_helper'
describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do
before do
Mutant::Random.stub(:hex_string => :RANDOM)
end
let(:source) { 'A = true' }
let(:mutations) do
mutations = []
mutations << 'SRANDOM = true'
mutations << 'A = false'
mutations << 'A = nil'
end
it_should_behave_like 'a mutator'
end