Avoid mutating break to next

Closes #201
This commit is contained in:
Markus Schirp 2014-06-06 13:06:50 +00:00
parent e393667ed5
commit bee44d7888
5 changed files with 36 additions and 11 deletions

View file

@ -1,3 +1,3 @@
---
threshold: 18
total_score: 869
total_score: 883

View file

@ -156,7 +156,8 @@ require 'mutant/mutator/node/kwbegin'
require 'mutant/mutator/node/named_value/access'
require 'mutant/mutator/node/named_value/constant_assignment'
require 'mutant/mutator/node/named_value/variable_assignment'
require 'mutant/mutator/node/loop_control'
require 'mutant/mutator/node/next'
require 'mutant/mutator/node/break'
require 'mutant/mutator/node/noop'
require 'mutant/mutator/node/or_asgn'
require 'mutant/mutator/node/and_asgn'

View file

@ -0,0 +1,29 @@
# encoding: utf-8
module Mutant
class Mutator
class Node
# Mutator for loop control keywords
class Break < Generic
handle(:break)
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
super
emit_singletons
children.each_index(&method(:delete_child))
end
end # Break
end # Node
end # Mutator
end # Mutant

View file

@ -5,14 +5,9 @@ module Mutant
class Node
# Mutator for loop control keywords
class LoopControl < Generic
class Next < Generic
INVERSE = IceNine.deep_freeze(
next: :break,
break: :next
)
handle(*INVERSE.keys)
handle(:next)
private
@ -26,10 +21,11 @@ module Mutant
super
emit_singletons
children.each_index(&method(:delete_child))
emit(s(INVERSE.fetch(node.type), *children))
emit(s(:break, *children))
end
end # Next
end # Node
end # Mutator
end # Mutant

View file

@ -7,5 +7,4 @@ Mutant::Meta::Example.add do
mutation 'break false'
mutation 'break nil'
mutation 'break'
mutation 'next true'
end