Add mutator for break nodes
This commit is contained in:
parent
6a9e4aa752
commit
acc9ba5a6f
4 changed files with 37 additions and 3 deletions
|
@ -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'
|
||||
|
|
30
lib/mutant/mutator/node/break.rb
Normal file
30
lib/mutant/mutator/node/break.rb
Normal 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
|
|
@ -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,
|
||||
|
|
|
@ -2,13 +2,16 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Mutator::Node::Generic, 'break' do
|
||||
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'
|
||||
|
|
Loading…
Add table
Reference in a new issue