Emit item promotion in case literal array has only one item
Closes #113
This commit is contained in:
parent
a1d93f591e
commit
05331a0ab3
4 changed files with 41 additions and 19 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
Changes:
|
||||
|
||||
* Add mutation from [item] to item
|
||||
* Add mutation from #reverse_each to #each
|
||||
* Add mutation from #reverse_map to #each, #map
|
||||
* Add mutation from #map to #each
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 18
|
||||
total_score: 791
|
||||
total_score: 794
|
||||
|
|
|
@ -21,6 +21,9 @@ module Mutant
|
|||
emit_nil
|
||||
emit_self
|
||||
mutate_body
|
||||
if children.one?
|
||||
emit(children.first)
|
||||
end
|
||||
end
|
||||
|
||||
# Mutate body
|
||||
|
|
|
@ -3,27 +3,45 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Mutator::Node::Literal, 'array' do
|
||||
let(:source) { '[true, false]' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
context 'on one item' do
|
||||
let(:source) { '[true]' }
|
||||
|
||||
# Literal replaced with nil
|
||||
mutations << 'nil'
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'nil'
|
||||
mutations << 'true'
|
||||
mutations << '[false]'
|
||||
mutations << '[nil]'
|
||||
mutations << '[]'
|
||||
end
|
||||
|
||||
# Mutation of each element in array
|
||||
mutations << '[nil, false]'
|
||||
mutations << '[false, false]'
|
||||
mutations << '[true, nil]'
|
||||
mutations << '[true, true]'
|
||||
|
||||
# Remove each element of array once
|
||||
mutations << '[true]'
|
||||
mutations << '[false]'
|
||||
|
||||
# Empty array
|
||||
mutations << '[]'
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
context 'on arrays with more than one item' do
|
||||
let(:source) { '[true, false]' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
|
||||
# Literal replaced with nil
|
||||
mutations << 'nil'
|
||||
|
||||
# Mutation of each element in array
|
||||
mutations << '[nil, false]'
|
||||
mutations << '[false, false]'
|
||||
mutations << '[true, nil]'
|
||||
mutations << '[true, true]'
|
||||
|
||||
# Remove each element of array once
|
||||
mutations << '[true]'
|
||||
mutations << '[false]'
|
||||
|
||||
# Empty array
|
||||
mutations << '[]'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue