
Several steps were made to achieve mutant working with Ruby 2.4 without warnings and spec failures: * Fix Fixnum deprecation warning * Update RuboCop to 0.47 and fix offenses * Relax version requirements on parser gem * Update diff-lcs to 1.3 * Update rake 11.x -> 12.x * Update reek 4.5 -> 4.6 (to work with parser 2.4) * Update json 2.0 -> 2.1 * Update parallel 1.10 -> 1.11 * Update simplecov 0.12 -> 0.14 * Run regexp_parser integration against v0.4.3 (as we requiring this exact version) * Update warnings.yml with new whitelist * Run CircleCI tests on Ruby 2.3 and 2.4 (Bundler.with_clean_env was causing troubles on new CircleCI 2.0 setup, so it was removed)
63 lines
1.2 KiB
Ruby
63 lines
1.2 KiB
Ruby
module Mutant
|
|
class Mutator
|
|
class Node
|
|
|
|
# Mutator for when nodes
|
|
class When < self
|
|
|
|
handle(:when)
|
|
|
|
private
|
|
|
|
# Emit mutations
|
|
#
|
|
# @return [undefined]
|
|
def dispatch
|
|
if body
|
|
mutate_body
|
|
else
|
|
emit_child_update(body_index, N_RAISE)
|
|
end
|
|
mutate_conditions
|
|
end
|
|
|
|
# Emit condition mutations
|
|
#
|
|
# @return [undefined]
|
|
def mutate_conditions
|
|
conditions = children.length - 1
|
|
children[0..-2].each_index do |index|
|
|
delete_child(index) if conditions > 1
|
|
mutate_child(index)
|
|
end
|
|
end
|
|
|
|
# Emit body mutations
|
|
#
|
|
# @return [undefined]
|
|
def mutate_body
|
|
mutate_child(body_index)
|
|
end
|
|
|
|
# Body node
|
|
#
|
|
# @return [Parser::AST::Node]
|
|
# if body is present
|
|
#
|
|
# @return [nil]
|
|
# otherwise
|
|
def body
|
|
children.fetch(body_index)
|
|
end
|
|
|
|
# Index of body node
|
|
#
|
|
# @return [Integer]
|
|
def body_index
|
|
children.length - 1
|
|
end
|
|
|
|
end # When
|
|
end # Node
|
|
end # Mutator
|
|
end # Mutant
|