Move named value access under consistent namespace

This commit is contained in:
Dan Kubb 2013-07-22 23:54:54 -07:00
parent 55c68a7b25
commit c63f1d52af
10 changed files with 101 additions and 119 deletions

View file

@ -54,17 +54,16 @@ require 'mutant/mutator/node/literal/array'
require 'mutant/mutator/node/literal/hash' require 'mutant/mutator/node/literal/hash'
require 'mutant/mutator/node/literal/regex' require 'mutant/mutator/node/literal/regex'
require 'mutant/mutator/node/literal/nil' require 'mutant/mutator/node/literal/nil'
require 'mutant/mutator/node/assignment'
require 'mutant/mutator/node/argument' require 'mutant/mutator/node/argument'
require 'mutant/mutator/node/arguments' require 'mutant/mutator/node/arguments'
require 'mutant/mutator/node/begin' require 'mutant/mutator/node/begin'
require 'mutant/mutator/node/variable' require 'mutant/mutator/node/named_value/access'
require 'mutant/mutator/node/named_value/assignment'
require 'mutant/mutator/node/while' require 'mutant/mutator/node/while'
require 'mutant/mutator/node/super' require 'mutant/mutator/node/super'
require 'mutant/mutator/node/send' require 'mutant/mutator/node/send'
require 'mutant/mutator/node/send/binary' require 'mutant/mutator/node/send/binary'
require 'mutant/mutator/node/when' require 'mutant/mutator/node/when'
require 'mutant/mutator/node/assignment'
require 'mutant/mutator/node/define' require 'mutant/mutator/node/define'
require 'mutant/mutator/node/mlhs' require 'mutant/mutator/node/mlhs'
require 'mutant/mutator/node/masgn' require 'mutant/mutator/node/masgn'

View file

@ -0,0 +1,27 @@
module Mutant
class Mutator
class Node
module NamedValue
# Mutation emitter to handle value access nodes
class Access < Node
handle(:gvar, :cvar, :ivar, :lvar)
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_nil
end
end # Access
end # NamedValue
end # Node
end # Mutator
end # Mutant

View file

@ -1,11 +1,10 @@
module Mutant module Mutant
class Mutator class Mutator
class Node class Node
# Mutator base class for assignments module NamedValue
class Assignment < self
# Mutator for variable assignment # Mutation emitter to handle value assignment nodes
class Variable < self class Assignment < Node
children :name, :value children :name, :value
@ -44,8 +43,8 @@ module Mutant
end end
end end
end # Variable
end # Assignment end # Assignment
end # NamedValue
end # Node end # Node
end # Mutator end # Mutator
end # Mutant end # Mutant

View file

@ -1,25 +0,0 @@
module Mutant
class Mutator
class Node
# Mutation emitter to handle variable nodes
class Variable < self
handle(:gvar, :cvar, :ivar, :lvar)
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_nil
end
end # Variable
end # Node
end # Mutator
end # Mutant

View file

@ -1,21 +0,0 @@
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

View file

@ -1,21 +0,0 @@
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

View file

@ -1,21 +0,0 @@
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

View file

@ -1,21 +0,0 @@
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

View file

@ -0,0 +1,66 @@
require 'spec_helper'
describe Mutant::Mutator::Node::NamedValue::Access, 'mutations' do
before do
Mutant::Random.stub(:hex_string => :random)
end
context 'global variable' do
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
context 'class variable' do
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
end
context 'instance variable' do
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
context 'local variable' do
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
end

View file

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe Mutant::Mutator::Node::Assignment, 'mutations' do describe Mutant::Mutator::Node::NamedValue::Assignment, 'mutations' do
before do before do
Mutant::Random.stub(:hex_string => :random) Mutant::Random.stub(:hex_string => :random)