mutant 0.5.18 → 0.5.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +7 -0
  3. data/README.md +2 -2
  4. data/config/flay.yml +1 -1
  5. data/lib/mutant.rb +4 -1
  6. data/lib/mutant/meta/example/dsl.rb +11 -0
  7. data/lib/mutant/mutator/node.rb +29 -5
  8. data/lib/mutant/mutator/node/and_asgn.rb +34 -0
  9. data/lib/mutant/mutator/node/binary.rb +1 -1
  10. data/lib/mutant/mutator/node/block.rb +1 -1
  11. data/lib/mutant/mutator/node/break.rb +29 -0
  12. data/lib/mutant/mutator/node/case.rb +1 -1
  13. data/lib/mutant/mutator/node/conditional_loop.rb +1 -1
  14. data/lib/mutant/mutator/node/const.rb +1 -1
  15. data/lib/mutant/mutator/node/defined.rb +30 -0
  16. data/lib/mutant/mutator/node/dstr.rb +1 -1
  17. data/lib/mutant/mutator/node/dsym.rb +1 -1
  18. data/lib/mutant/mutator/node/generic.rb +1 -1
  19. data/lib/mutant/mutator/node/if.rb +4 -2
  20. data/lib/mutant/mutator/node/kwbegin.rb +1 -1
  21. data/lib/mutant/mutator/node/literal/array.rb +1 -1
  22. data/lib/mutant/mutator/node/literal/fixnum.rb +1 -1
  23. data/lib/mutant/mutator/node/literal/float.rb +1 -1
  24. data/lib/mutant/mutator/node/literal/hash.rb +1 -1
  25. data/lib/mutant/mutator/node/literal/range.rb +1 -1
  26. data/lib/mutant/mutator/node/literal/regex.rb +1 -1
  27. data/lib/mutant/mutator/node/literal/string.rb +1 -1
  28. data/lib/mutant/mutator/node/literal/symbol.rb +1 -1
  29. data/lib/mutant/mutator/node/masgn.rb +1 -1
  30. data/lib/mutant/mutator/node/match_current_line.rb +1 -1
  31. data/lib/mutant/mutator/node/named_value/access.rb +1 -1
  32. data/lib/mutant/mutator/node/named_value/variable_assignment.rb +1 -1
  33. data/lib/mutant/mutator/node/{loop_control.rb → next.rb} +5 -9
  34. data/lib/mutant/mutator/node/op_asgn.rb +9 -4
  35. data/lib/mutant/mutator/node/or_asgn.rb +6 -2
  36. data/lib/mutant/mutator/node/resbody.rb +2 -2
  37. data/lib/mutant/mutator/node/return.rb +1 -1
  38. data/lib/mutant/mutator/node/send.rb +1 -1
  39. data/lib/mutant/mutator/node/splat.rb +1 -1
  40. data/lib/mutant/mutator/node/super.rb +1 -1
  41. data/lib/mutant/mutator/node/yield.rb +1 -1
  42. data/lib/mutant/mutator/node/zsuper.rb +1 -1
  43. data/lib/mutant/node_helpers.rb +6 -5
  44. data/lib/mutant/version.rb +1 -1
  45. data/meta/and.rb +1 -1
  46. data/meta/and_asgn.rb +3 -1
  47. data/meta/array.rb +2 -2
  48. data/meta/block.rb +6 -4
  49. data/meta/block_pass.rb +1 -1
  50. data/meta/blockarg.rb +1 -1
  51. data/meta/break.rb +1 -2
  52. data/meta/case.rb +104 -183
  53. data/meta/cbase.rb +1 -1
  54. data/meta/const.rb +1 -1
  55. data/meta/cvar.rb +1 -1
  56. data/meta/cvasgn.rb +1 -1
  57. data/meta/{define.rb → def.rb} +2 -1
  58. data/meta/dstr.rb +4 -1
  59. data/meta/dsym.rb +4 -2
  60. data/meta/ensure.rb +1 -1
  61. data/meta/false.rb +8 -0
  62. data/meta/float.rb +3 -4
  63. data/meta/gvar.rb +1 -1
  64. data/meta/gvasgn.rb +1 -1
  65. data/meta/hash.rb +1 -2
  66. data/meta/if.rb +25 -27
  67. data/meta/{fixnum.rb → int.rb} +1 -2
  68. data/meta/ivasgn.rb +1 -1
  69. data/meta/kwbegin.rb +1 -1
  70. data/meta/lvar.rb +2 -0
  71. data/meta/lvasgn.rb +1 -1
  72. data/meta/masgn.rb +1 -1
  73. data/meta/match_current_line.rb +1 -1
  74. data/meta/next.rb +1 -1
  75. data/meta/op_assgn.rb +3 -1
  76. data/meta/{binary.rb → or.rb} +1 -1
  77. data/meta/or_asgn.rb +4 -2
  78. data/meta/range.rb +6 -2
  79. data/meta/regex.rb +4 -2
  80. data/meta/rescue.rb +7 -6
  81. data/meta/restarg.rb +3 -1
  82. data/meta/return.rb +3 -2
  83. data/meta/send.rb +48 -51
  84. data/meta/{string.rb → str.rb} +1 -1
  85. data/meta/super.rb +6 -3
  86. data/meta/symbol.rb +1 -1
  87. data/meta/true.rb +8 -0
  88. data/meta/until.rb +17 -0
  89. data/meta/while.rb +4 -2
  90. data/meta/yield.rb +1 -1
  91. data/spec/spec_helper.rb +1 -1
  92. metadata +13 -8
  93. data/meta/unless.rb +0 -15
@@ -20,7 +20,7 @@ module Mutant
20
20
  # @api private
21
21
  #
22
22
  def dispatch
23
- emit_nil
23
+ emit_singletons
24
24
  end
25
25
 
26
26
  end # MultipleAssignment
@@ -17,7 +17,7 @@ module Mutant
17
17
  # @api private
18
18
  #
19
19
  def dispatch
20
- emit_nil
20
+ emit_singletons
21
21
  emit_regexp_mutations
22
22
  end
23
23
 
@@ -19,7 +19,7 @@ module Mutant
19
19
  # @api private
20
20
  #
21
21
  def dispatch
22
- emit_nil
22
+ emit_singletons
23
23
  end
24
24
 
25
25
  end # Access
@@ -32,9 +32,9 @@ module Mutant
32
32
  # @api private
33
33
  #
34
34
  def dispatch
35
+ emit_singletons
35
36
  mutate_name
36
37
  emit_value_mutations if value # mlhs!
37
- emit_nil
38
38
  end
39
39
 
40
40
  # Emit name mutations
@@ -5,14 +5,9 @@ module Mutant
5
5
  class Node
6
6
 
7
7
  # Mutator for loop control keywords
8
- class LoopControl < Generic
8
+ class Next < Generic
9
9
 
10
- INVERSE = IceNine.deep_freeze(
11
- next: :break,
12
- break: :next
13
- )
14
-
15
- handle(*INVERSE.keys)
10
+ handle(:next)
16
11
 
17
12
  private
18
13
 
@@ -24,12 +19,13 @@ module Mutant
24
19
  #
25
20
  def dispatch
26
21
  super
22
+ emit_singletons
27
23
  children.each_index(&method(:delete_child))
28
- emit(s(INVERSE.fetch(node.type), *children))
29
- emit_nil
24
+ emit(s(:break, *children))
30
25
  end
31
26
 
32
27
  end # Next
33
28
  end # Node
34
29
  end # Mutator
35
30
  end # Mutant
31
+
@@ -5,9 +5,11 @@ module Mutant
5
5
  class Node
6
6
 
7
7
  # OpAsgn mutator
8
- class OpAsgn < Generic
8
+ class OpAsgn < self
9
9
 
10
- handle(:op_asgn, :and_asgn)
10
+ handle(:op_asgn)
11
+
12
+ children :left, :operation, :right
11
13
 
12
14
  private
13
15
 
@@ -18,8 +20,11 @@ module Mutant
18
20
  # @api private
19
21
  #
20
22
  def dispatch
21
- super
22
- emit_nil
23
+ emit_singletons
24
+ emit_left_mutations do |mutation|
25
+ !mutation.type.equal?(:self)
26
+ end
27
+ emit_right_mutations
23
28
  end
24
29
 
25
30
  end # OpAsgn
@@ -20,8 +20,12 @@ module Mutant
20
20
  # @api private
21
21
  #
22
22
  def dispatch
23
- emit_nil
24
- emit_left_mutations unless left.type.equal?(:ivasgn)
23
+ emit_singletons
24
+ unless left.type.equal?(:ivasgn)
25
+ emit_left_mutations do |mutation|
26
+ !mutation.type.equal?(:self)
27
+ end
28
+ end
25
29
  emit_right_mutations
26
30
  end
27
31
 
@@ -32,8 +32,8 @@ module Mutant
32
32
  #
33
33
  def mutate_captures
34
34
  return unless captures
35
- Util::Array.each(captures.children, self) do |matchers|
36
- next if matchers.empty? || matchers.any? { |node| node.type == :nil }
35
+ Util::Array::Element.each(captures.children, self) do |matchers|
36
+ next if matchers.any? { |node| node.type.equal?(:nil) }
37
37
  emit_captures(s(:array, *matchers))
38
38
  end
39
39
  end
@@ -19,11 +19,11 @@ module Mutant
19
19
  # @api private
20
20
  #
21
21
  def dispatch
22
+ emit_singletons
22
23
  if value
23
24
  emit(value)
24
25
  emit_value_mutations
25
26
  end
26
- emit_nil
27
27
  end
28
28
 
29
29
  end # Return
@@ -34,7 +34,7 @@ module Mutant
34
34
  # @api private
35
35
  #
36
36
  def dispatch
37
- emit_nil
37
+ emit_singletons
38
38
  case selector
39
39
  when INDEX_REFERENCE
40
40
  run(Index::Reference)
@@ -19,7 +19,7 @@ module Mutant
19
19
  # @api private
20
20
  #
21
21
  def dispatch
22
- emit_nil
22
+ emit_singletons
23
23
  emit_expression_mutations
24
24
  emit(expression)
25
25
  end
@@ -21,13 +21,13 @@ module Mutant
21
21
  # @api private
22
22
  #
23
23
  def dispatch
24
+ emit_singletons
24
25
  emit(Z_SUPER)
25
26
  emit(EMPTY_SUPER)
26
27
  children.each_index do |index|
27
28
  mutate_child(index)
28
29
  delete_child(index)
29
30
  end
30
- emit_nil
31
31
  end
32
32
 
33
33
  end # Super
@@ -19,8 +19,8 @@ module Mutant
19
19
  #
20
20
  def dispatch
21
21
  super
22
+ emit_singletons
22
23
  children.each_index(&method(:delete_child))
23
- emit_nil
24
24
  end
25
25
 
26
26
  end # Yield
@@ -18,7 +18,7 @@ module Mutant
18
18
  # @api private
19
19
  #
20
20
  def dispatch
21
- emit_nil
21
+ emit_singletons
22
22
  end
23
23
 
24
24
  end # ZSuper
@@ -24,12 +24,13 @@ module Mutant
24
24
  NEGATIVE_INFINITY =
25
25
  s(:send, s(:float, -1.0), :/, s(:float, 0.0))
26
26
 
27
- RAISE = s(:send, nil, :raise)
27
+ RAISE = s(:send, nil, :raise)
28
28
 
29
- N_TRUE = s(:true)
30
- N_FALSE = s(:false)
31
- N_NIL = s(:nil)
32
- N_EMPTY = s(:empty)
29
+ N_TRUE = s(:true)
30
+ N_FALSE = s(:false)
31
+ N_NIL = s(:nil)
32
+ N_EMPTY = s(:empty)
33
+ N_SELF = s(:self)
33
34
 
34
35
  # Build a negated boolean node
35
36
  #
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Mutant
4
4
  # The current mutant version
5
- VERSION = '0.5.18'.freeze
5
+ VERSION = '0.5.19'.freeze
6
6
  end # Mutant
data/meta/and.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  Mutant::Meta::Example.add do
4
4
  source 'true and false'
5
5
 
6
- mutation 'nil'
6
+ singleton_mutations
7
7
  mutation 'true'
8
8
  mutation 'false'
9
9
  mutation 'true or false'
data/meta/and_asgn.rb CHANGED
@@ -3,10 +3,12 @@
3
3
  Mutant::Meta::Example.add do
4
4
  source 'a &&= 1'
5
5
 
6
+ singleton_mutations
7
+
6
8
  mutation 'a__mutant__ &&= 1'
7
9
  mutation 'a &&= nil'
8
10
  mutation 'a &&= 0'
9
11
  mutation 'a &&= -1'
10
12
  mutation 'a &&= 2'
11
- mutation 'nil'
13
+ mutation 'a &&= self'
12
14
  end
data/meta/array.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  Mutant::Meta::Example.add do
4
4
  source '[true]'
5
5
 
6
- mutation 'nil'
6
+ singleton_mutations
7
7
  mutation 'true'
8
8
  mutation '[false]'
9
9
  mutation '[nil]'
@@ -13,7 +13,7 @@ end
13
13
  Mutant::Meta::Example.add do
14
14
  source '[true, false]'
15
15
 
16
- mutation 'nil'
16
+ singleton_mutations
17
17
 
18
18
  # Mutation of each element in array
19
19
  mutation '[nil, false]'
data/meta/block.rb CHANGED
@@ -3,19 +3,22 @@
3
3
  Mutant::Meta::Example.add do
4
4
  source 'foo() { a; b }'
5
5
 
6
+ singleton_mutations
6
7
  mutation 'foo { a }'
7
8
  mutation 'foo { b }'
8
9
  mutation 'foo {}'
9
10
  mutation 'foo { raise }'
10
11
  mutation 'foo { a; nil }'
12
+ mutation 'foo { a; self }'
11
13
  mutation 'foo { nil; b }'
14
+ mutation 'foo { self; b }'
12
15
  mutation 'foo'
13
- mutation 'nil'
14
16
  end
15
17
 
16
18
  Mutant::Meta::Example.add do
17
19
  source 'foo { |a, b| }'
18
20
 
21
+ singleton_mutations
19
22
  mutation 'foo'
20
23
  mutation 'foo { |a, b| raise }'
21
24
  mutation 'foo { |a, b__mutant__| }'
@@ -23,13 +26,12 @@ Mutant::Meta::Example.add do
23
26
  mutation 'foo { |a| }'
24
27
  mutation 'foo { |b| }'
25
28
  mutation 'foo { || }'
26
- mutation 'nil'
27
29
  end
28
30
 
29
31
  Mutant::Meta::Example.add do
30
32
  source 'foo { |(a, b), c| }'
31
33
 
32
- mutation 'nil'
34
+ singleton_mutations
33
35
  mutation 'foo { || }'
34
36
  mutation 'foo { |a, b, c| }'
35
37
  mutation 'foo { |(a, b), c| raise }'
@@ -46,10 +48,10 @@ end
46
48
  Mutant::Meta::Example.add do
47
49
  source 'foo { |(a)| }'
48
50
 
51
+ singleton_mutations
49
52
  mutation 'foo { || }'
50
53
  mutation 'foo { |a| }'
51
54
  mutation 'foo { |(a)| raise }'
52
55
  mutation 'foo { |(a__mutant__)| }'
53
56
  mutation 'foo'
54
- mutation 'nil'
55
57
  end
data/meta/block_pass.rb CHANGED
@@ -3,6 +3,6 @@
3
3
  Mutant::Meta::Example.add do
4
4
  source 'foo(&bar)'
5
5
 
6
+ singleton_mutations
6
7
  mutation 'foo'
7
- mutation 'nil'
8
8
  end
data/meta/blockarg.rb CHANGED
@@ -3,8 +3,8 @@
3
3
  Mutant::Meta::Example.add do
4
4
  source 'foo { |&bar| }'
5
5
 
6
+ singleton_mutations
6
7
  mutation 'foo { |&bar| raise }'
7
8
  mutation 'foo {}'
8
9
  mutation 'foo'
9
- mutation 'nil'
10
10
  end
data/meta/break.rb CHANGED
@@ -3,9 +3,8 @@
3
3
  Mutant::Meta::Example.add do
4
4
  source 'break true'
5
5
 
6
+ singleton_mutations
6
7
  mutation 'break false'
7
8
  mutation 'break nil'
8
9
  mutation 'break'
9
- mutation 'nil'
10
- mutation 'next true'
11
10
  end
data/meta/case.rb CHANGED
@@ -8,7 +8,7 @@ Mutant::Meta::Example.add do
8
8
  end
9
9
  RUBY
10
10
 
11
- mutation 'nil'
11
+ singleton_mutations
12
12
 
13
13
  mutation <<-RUBY
14
14
  case
@@ -33,271 +33,192 @@ end
33
33
 
34
34
  Mutant::Meta::Example.add do
35
35
  source <<-RUBY
36
- case :condition
37
- when :foo
38
- when :bar, :baz
39
- :barbaz
36
+ case condition
37
+ when A
38
+ when B, C
39
+ C
40
40
  else
41
- :else
41
+ D
42
42
  end
43
43
  RUBY
44
44
 
45
- # Presence of branches
46
- mutation <<-RUBY
47
- case :condition
48
- when :bar, :baz
49
- :barbaz
50
- else
51
- :else
52
- end
53
- RUBY
54
- mutation <<-RUBY
55
- case :condition
56
- when :foo
57
- else
58
- :else
59
- end
60
- RUBY
61
- mutation <<-RUBY
62
- case :condition
63
- when :foo
64
- when :bar, :baz
65
- :barbaz
66
- end
67
- RUBY
45
+ singleton_mutations
68
46
 
69
- # Mutations of condition
70
47
  mutation <<-RUBY
71
48
  case nil
72
- when :foo
73
- when :bar, :baz
74
- :barbaz
49
+ when A
50
+ when B, C
51
+ C
75
52
  else
76
- :else
53
+ D
77
54
  end
78
55
  RUBY
56
+
79
57
  mutation <<-RUBY
80
- case :condition__mutant__
81
- when :foo
82
- when :bar, :baz
83
- :barbaz
58
+ case self
59
+ when A
60
+ when B, C
61
+ C
84
62
  else
85
- :else
63
+ D
86
64
  end
87
65
  RUBY
88
66
 
89
- # Mutations of branch bodies
90
67
  mutation <<-RUBY
91
- case :condition
92
- when :foo
68
+ case condition
69
+ when A
93
70
  raise
94
- when :bar, :baz
95
- :barbaz
96
- else
97
- :else
98
- end
99
- RUBY
100
- mutation <<-RUBY
101
- case :condition
102
- when :foo
103
- when :bar, :baz
104
- :barbaz__mutant__
71
+ when B, C
72
+ C
105
73
  else
106
- :else
107
- end
108
- RUBY
109
- mutation <<-RUBY
110
- case :condition
111
- when :foo
112
- when :bar, :baz
113
- nil
114
- else
115
- :else
116
- end
117
- RUBY
118
- mutation <<-RUBY
119
- case :condition
120
- when :foo
121
- when :bar, :baz
122
- :barbaz
123
- else
124
- :else__mutant__
125
- end
126
- RUBY
127
- mutation <<-RUBY
128
- case :condition
129
- when :foo
130
- when :bar, :baz
131
- :barbaz
132
- else
133
- nil
74
+ D
134
75
  end
135
76
  RUBY
136
77
 
137
- # Mutations of when conditions
138
78
  mutation <<-RUBY
139
- case :condition
140
- when :foo__mutant__
141
- when :bar, :baz
142
- :barbaz
143
- else
144
- :else
145
- end
146
- RUBY
147
- mutation <<-RUBY
148
- case :condition
79
+ case condition
149
80
  when nil
150
- when :bar, :baz
151
- :barbaz
152
- else
153
- :else
154
- end
155
- RUBY
156
- mutation <<-RUBY
157
- case :condition
158
- when :foo
159
- when :bar__mutant__, :baz
160
- :barbaz
161
- else
162
- :else
163
- end
164
- RUBY
165
- mutation <<-RUBY
166
- case :condition
167
- when :foo
168
- when nil, :baz
169
- :barbaz
81
+ when B, C
82
+ C
170
83
  else
171
- :else
84
+ D
172
85
  end
173
86
  RUBY
87
+
174
88
  mutation <<-RUBY
175
- case :condition
176
- when :foo
177
- when :bar, nil
178
- :barbaz
89
+ case condition
90
+ when self
91
+ when B, C
92
+ C
179
93
  else
180
- :else
94
+ D
181
95
  end
182
96
  RUBY
97
+
183
98
  mutation <<-RUBY
184
- case :condition
185
- when :foo
186
- when :bar, :baz__mutant__
187
- :barbaz
99
+ case condition
100
+ when B, C
101
+ C
188
102
  else
189
- :else
103
+ D
190
104
  end
191
105
  RUBY
106
+
192
107
  mutation <<-RUBY
193
- case :condition
194
- when :foo
195
- when :baz
196
- :barbaz
108
+ case condition
109
+ when A
110
+ when B, C
111
+ nil
197
112
  else
198
- :else
113
+ D
199
114
  end
200
115
  RUBY
116
+
201
117
  mutation <<-RUBY
202
- case :condition
203
- when :foo
204
- when :bar
205
- :barbaz
118
+ case condition
119
+ when A
120
+ when B, C
121
+ self
206
122
  else
207
- :else
123
+ D
208
124
  end
209
125
  RUBY
210
126
 
211
- mutation 'nil'
212
- end
213
-
214
- Mutant::Meta::Example.add do
215
- source <<-RUBY
216
- case :condition
217
- when :foo
218
- :foo
127
+ mutation <<-RUBY
128
+ case condition
129
+ when A
130
+ when C
131
+ C
219
132
  else
220
- :else
133
+ D
221
134
  end
222
135
  RUBY
223
136
 
224
- # Presence of branches
225
137
  mutation <<-RUBY
226
- case :condition
227
- when :foo
228
- :foo
138
+ case condition
139
+ when A
140
+ when nil, C
141
+ C
142
+ else
143
+ D
229
144
  end
230
145
  RUBY
231
146
 
232
- # Mutations of condition
233
147
  mutation <<-RUBY
234
- case nil
235
- when :foo
236
- :foo
148
+ case condition
149
+ when A
150
+ when self, C
151
+ C
237
152
  else
238
- :else
153
+ D
239
154
  end
240
155
  RUBY
156
+
241
157
  mutation <<-RUBY
242
- case :condition__mutant__
243
- when :foo
244
- :foo
158
+ case condition
159
+ when A
160
+ when B
161
+ C
245
162
  else
246
- :else
163
+ D
247
164
  end
248
165
  RUBY
249
166
 
250
- # Mutations of branch bodies
251
167
  mutation <<-RUBY
252
- case :condition
253
- when :foo
254
- nil
168
+ case condition
169
+ when A
170
+ when B, nil
171
+ C
255
172
  else
256
- :else
173
+ D
257
174
  end
258
175
  RUBY
176
+
259
177
  mutation <<-RUBY
260
- case :condition
261
- when :foo
262
- :foo__mutant__
178
+ case condition
179
+ when A
180
+ when B, self
181
+ C
263
182
  else
264
- :else
183
+ D
265
184
  end
266
185
  RUBY
186
+
267
187
  mutation <<-RUBY
268
- case :condition
269
- when :foo
270
- :foo
188
+ case condition
189
+ when A
271
190
  else
272
- :else__mutant__
191
+ D
273
192
  end
274
193
  RUBY
194
+
275
195
  mutation <<-RUBY
276
- case :condition
277
- when :foo
278
- :foo
196
+ case condition
197
+ when A
198
+ when B, C
199
+ C
279
200
  else
280
201
  nil
281
202
  end
282
203
  RUBY
283
204
 
284
- # Mutations of when conditions
285
205
  mutation <<-RUBY
286
- case :condition
287
- when :foo__mutant__
288
- :foo
206
+ case condition
207
+ when A
208
+ when B, C
209
+ C
289
210
  else
290
- :else
211
+ self
291
212
  end
292
213
  RUBY
214
+
293
215
  mutation <<-RUBY
294
- case :condition
295
- when nil
296
- :foo
297
- else
298
- :else
216
+ case condition
217
+ when A
218
+ when B, C
219
+ C
299
220
  end
300
221
  RUBY
301
-
302
- mutation 'nil'
303
222
  end
223
+
224
+