Add mutator for break nodes

This commit is contained in:
Dan Kubb 2013-11-03 20:32:54 -08:00
parent 6a9e4aa752
commit acc9ba5a6f
4 changed files with 37 additions and 3 deletions

View file

@ -64,6 +64,7 @@ require 'mutant/mutator/node/argument'
require 'mutant/mutator/node/arguments'
require 'mutant/mutator/node/blockarg'
require 'mutant/mutator/node/begin'
require 'mutant/mutator/node/break'
require 'mutant/mutator/node/connective/binary'
require 'mutant/mutator/node/const'
require 'mutant/mutator/node/dstr'

View file

@ -0,0 +1,30 @@
# encoding: utf-8
module Mutant
class Mutator
class Node
# Break mutator
class Break < Generic
handle(:break)
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
super
children.each_index(&method(:delete_child))
emit(s(:next, *children))
emit_nil
end
end # Break
end # Node
end # Mutator
end # Mutant

View file

@ -10,7 +10,7 @@ module Mutant
# These nodes still need a dedicated mutator,
# your contribution is that close!
handle(
:next, :break, :ensure,
:next, :ensure,
:rescue, :redo, :defined?,
:regopt, :resbody, :retry, :arg_expr,
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty,

View file

@ -2,13 +2,16 @@
require 'spec_helper'
describe Mutant::Mutator::Node::Generic, 'break' do
let(:source) { 'break true' }
describe Mutant::Mutator::Node::Break, 'break' do
let(:source) { 'break true' }
let(:mutations) do
mutations = []
mutations << 'break false'
mutations << 'break nil'
mutations << 'break'
mutations << 'nil'
mutations << 'next true'
end
it_should_behave_like 'a mutator'