Fix begin mutator

This commit is contained in:
Markus Schirp 2013-06-04 22:16:04 +02:00
parent ededf82ebe
commit 2d9da54041
6 changed files with 43 additions and 48 deletions

View file

@ -52,7 +52,7 @@ require 'mutant/mutator/node/literal/hash'
require 'mutant/mutator/node/literal/regex'
require 'mutant/mutator/node/literal/nil'
require 'mutant/mutator/node/assignment'
require 'mutant/mutator/node/block'
require 'mutant/mutator/node/begin'
require 'mutant/mutator/node/while'
require 'mutant/mutator/node/super'
require 'mutant/mutator/node/send'

View file

@ -0,0 +1,26 @@
module Mutant
class Mutator
class Node
# Mutator for begin nodes
class Begin < self
handle(:begin)
private
# Emit mutants
#
# @return [undefined]
#
# @api private
#
def dispatch
Mutator::Util::Array.each(children) do |children|
emit_self(children)
end
end
end # Block
end # Node
end # Mutator
end # Mutant

View file

@ -1,32 +0,0 @@
module Mutant
class Mutator
class Node
# Mutator on AST blocks
class Block < self
handle(:block)
private
# Emit mutants
#
# @return [undefined]
#
# @api private
#
def dispatch
array = input.array
emit_attribute_mutations(:array) do |mutation|
array = mutation.array
# Do not generate empty bodies
if array.empty?
array << new_nil
end
mutation
end
end
end # Block
end # Node
end # Mutator
end # Mutant

View file

@ -29,10 +29,10 @@ shared_examples_for 'a mutator' do
mutations.map do |mutation|
case mutation
when String
ast = parse(mutation)
assert_transitive(ast)
ast
when Rubinius::AST::Node
node = parse(mutation)
assert_transitive(node)
node
when Parser::AST::Node
assert_transitive(mutation)
mutation
else

View file

@ -1,12 +1,10 @@
# encoding: utf-8
require 'mutant'
require 'devtools'
Devtools.init_spec_helper
$: << File.join(TestApp.root,'lib')
require 'test_app'
require 'mutant'
module ParserHelper
def generate(node)
@ -21,4 +19,5 @@ end
RSpec.configure do |config|
config.include(CompressHelper)
config.include(ParserHelper)
config.include(Mutant::NodeHelpers)
end

View file

@ -3,18 +3,20 @@ require 'spec_helper'
describe Mutant::Mutator, 'block' do
context 'with more than one statement' do
let(:source) { "self.foo\nself.bar" }
let(:source) { "true\nfalse" }
let(:mutations) do
mutations = []
# Mutation of each statement in block
mutations << "foo\nself.bar"
mutations << "self.foo\nbar"
mutations << "true\ntrue"
mutations << "false\nfalse"
mutations << "nil\nfalse"
mutations << "true\nnil"
# Remove statement in block
mutations << 'self.foo'
mutations << 'self.bar'
mutations << s(:begin, s(:true))
mutations << s(:begin, s(:false))
mutations << 'nil'
end
@ -22,12 +24,12 @@ describe Mutant::Mutator, 'block' do
end
context 'with one statement' do
let(:node) { 'self.foo' }
let(:source) { 'true' }
let(:mutations) do
mutations = []
mutations << Rubinius::AST::Block.new(1, ['foo'.to_ast])
mutations << Rubinius::AST::Block.new(1, ['nil'.to_ast])
mutations << s(:false)
mutations << s(:nil)
end
it_should_behave_like 'a mutator'