Emit item promotion in case literal array has only one item

Closes #113
This commit is contained in:
Markus Schirp 2014-05-24 12:45:38 +00:00
parent a1d93f591e
commit 05331a0ab3
4 changed files with 41 additions and 19 deletions

View file

@ -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

View file

@ -1,3 +1,3 @@
---
threshold: 18
total_score: 791
total_score: 794

View file

@ -21,6 +21,9 @@ module Mutant
emit_nil
emit_self
mutate_body
if children.one?
emit(children.first)
end
end
# Mutate body

View file

@ -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