2013-07-28 16:03:06 -07:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2012-12-06 21:30:28 +01:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
2013-06-04 10:25:13 +02:00
|
|
|
# Mutator for if nodes
|
2013-01-04 22:16:03 +01:00
|
|
|
class If < self
|
2012-12-06 21:30:28 +01:00
|
|
|
|
2013-06-04 10:25:13 +02:00
|
|
|
handle(:if)
|
2012-12-06 21:30:28 +01:00
|
|
|
|
2013-06-21 15:06:24 +02:00
|
|
|
children :condition, :if_branch, :else_branch
|
2013-06-10 10:15:59 +02:00
|
|
|
|
2012-12-06 21:30:28 +01:00
|
|
|
private
|
|
|
|
|
2013-06-10 10:15:59 +02:00
|
|
|
# Emit mutations
|
2012-12-06 21:30:28 +01:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dispatch
|
2013-06-10 10:15:59 +02:00
|
|
|
mutate_condition
|
|
|
|
mutate_if_branch
|
|
|
|
mutate_else_branch
|
2013-09-07 23:10:25 -07:00
|
|
|
emit_nil
|
2012-12-06 21:30:28 +01:00
|
|
|
end
|
|
|
|
|
2013-06-10 10:15:59 +02:00
|
|
|
# Emit conditon mutations
|
2012-12-06 21:30:28 +01:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-10 10:15:59 +02:00
|
|
|
def mutate_condition
|
2013-06-21 15:06:24 +02:00
|
|
|
emit_condition_mutations
|
2014-04-22 17:24:31 +00:00
|
|
|
emit_self(n_not(condition), if_branch, else_branch) unless condition.type == :match_current_line
|
2013-07-23 22:58:20 -07:00
|
|
|
emit_self(N_TRUE, if_branch, else_branch)
|
|
|
|
emit_self(N_FALSE, if_branch, else_branch)
|
2012-12-06 21:30:28 +01:00
|
|
|
end
|
|
|
|
|
2013-06-10 10:15:59 +02:00
|
|
|
# Emit if branch mutations
|
2013-03-23 23:12:36 -07:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-10 10:15:59 +02:00
|
|
|
def mutate_if_branch
|
2013-06-12 19:04:40 +02:00
|
|
|
emit_self(condition, else_branch, nil) if else_branch
|
|
|
|
if if_branch
|
2013-06-21 15:06:24 +02:00
|
|
|
emit_if_branch_mutations
|
2013-07-23 22:58:39 -07:00
|
|
|
emit_self(condition, if_branch, nil)
|
2013-06-12 19:04:40 +02:00
|
|
|
end
|
2013-03-23 23:12:36 -07:00
|
|
|
end
|
|
|
|
|
2013-06-10 10:15:59 +02:00
|
|
|
# Emit else branch mutations
|
2013-03-23 23:12:36 -07:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-06-10 10:15:59 +02:00
|
|
|
def mutate_else_branch
|
2013-06-12 19:04:40 +02:00
|
|
|
if else_branch
|
2013-06-21 15:06:24 +02:00
|
|
|
emit_else_branch_mutations
|
2013-06-12 19:04:40 +02:00
|
|
|
emit_self(condition, nil, else_branch)
|
|
|
|
end
|
2013-03-23 23:12:36 -07:00
|
|
|
end
|
|
|
|
|
2013-06-04 10:25:13 +02:00
|
|
|
end # If
|
|
|
|
end # Node
|
|
|
|
end # Mutator
|
|
|
|
end # Mutant
|