/
when.rb
46 lines (36 loc) · 850 Bytes
/
when.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
module Mutant
class Mutator
class Node
# Mutator for when nodes
class When < self
handle(:when)
private
def dispatch
if body
mutate_body
else
emit_child_update(body_index, N_RAISE)
end
mutate_conditions
end
def mutate_conditions
conditions = children.length - 1
children[..-2].each_index do |index|
delete_child(index) if conditions > 1
mutate_child(index)
end
end
def mutate_body
mutate_child(body_index)
end
def body
children.fetch(body_index)
end
def body_index
children.length - 1
end
end # When
end # Node
end # Mutator
end # Mutant