From 72b7488809632a923c63cc4958b260052595fc94 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Mon, 22 Jul 2013 00:33:54 -0700 Subject: [PATCH] Add Mutant::Mutator::Node::LocalVariable --- lib/mutant.rb | 1 + lib/mutant/mutator/node/generic.rb | 2 +- lib/mutant/mutator/node/lvar.rb | 25 +++++++++++++++++++ .../mutant/mutator/node/lvar/mutation_spec.rb | 21 ++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 lib/mutant/mutator/node/lvar.rb create mode 100644 spec/unit/mutant/mutator/node/lvar/mutation_spec.rb diff --git a/lib/mutant.rb b/lib/mutant.rb index 6e70cc1b..e8f7dbd0 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -58,6 +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/while' require 'mutant/mutator/node/super' require 'mutant/mutator/node/send' diff --git a/lib/mutant/mutator/node/generic.rb b/lib/mutant/mutator/node/generic.rb index 1bea61e1..7bb82aa7 100644 --- a/lib/mutant/mutator/node/generic.rb +++ b/lib/mutant/mutator/node/generic.rb @@ -13,7 +13,7 @@ module Mutant :zsuper, :not, :or, :and, :defined, :next, :break, :match, :gvar, :cvar, :ensure, :dstr, :dsym, :yield, :rescue, :redo, :defined?, - :lvar, :const, :blockarg, :block_pass, :op_asgn, :and_asgn, + :const, :blockarg, :block_pass, :op_asgn, :and_asgn, :regopt, :ivar, :restarg, :casgn, :resbody, :retry, :arg_expr, :kwrestarg, :kwoptarg, :kwarg, :undef, :module, :cbase, :empty, :alias, :for, :xstr, :back_ref, :nth_ref, :class, diff --git a/lib/mutant/mutator/node/lvar.rb b/lib/mutant/mutator/node/lvar.rb new file mode 100644 index 00000000..c67aa824 --- /dev/null +++ b/lib/mutant/mutator/node/lvar.rb @@ -0,0 +1,25 @@ +module Mutant + class Mutator + class Node + + # Mutation emitter to handle local variable nodes + class LocalVariable < self + + handle(:lvar) + + private + + # Emit mutations + # + # @return [undefined] + # + # @api private + # + def dispatch + emit_nil + end + + end # LocalVariable + end # Node + end # Mutator +end # Mutant diff --git a/spec/unit/mutant/mutator/node/lvar/mutation_spec.rb b/spec/unit/mutant/mutator/node/lvar/mutation_spec.rb new file mode 100644 index 00000000..e63edc8b --- /dev/null +++ b/spec/unit/mutant/mutator/node/lvar/mutation_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Mutant::Mutator, 'lvar' 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