Add mutation foo[n..-1] -> foo.drop(n)

Fixes #521
This commit is contained in:
John Backus 2016-04-03 16:38:23 -07:00
parent ca1a13f5d9
commit ae0b22236f
3 changed files with 16 additions and 1 deletions

View file

@ -1,3 +1,3 @@
---
threshold: 16
total_score: 1166
total_score: 1171

View file

@ -105,6 +105,7 @@ module Mutant
emit_const_get_mutation
emit_integer_mutation
emit_dig_mutation
emit_drop_mutation
end
# Emit selector mutations specific to top level constants
@ -137,6 +138,19 @@ module Mutant
emit(s(:send, fetch_mutation, :dig, *tail))
end
# Emit mutation `foo[n..-1]` -> `foo.drop(n)`
#
# @return [undefined]
def emit_drop_mutation
return if !selector.equal?(:[]) || !arguments.one? || !n_irange?(arguments.first)
start, ending = *arguments.first
return unless ending.eql?(s(:int, -1))
emit(s(:send, receiver, :drop, start))
end
# Emit mutation from `to_i` to `Integer(...)`
#
# @return [undefined]

View file

@ -597,6 +597,7 @@ Mutant::Meta::Example.add :send do
mutation 'foo[n..(1.0 / 0.0)]'
mutation 'foo[n..(0.0 / 0.0)]'
mutation 'foo[(0.0 / 0.0)..-1]'
mutation 'foo.drop(n)'
end
Mutant::Meta::Example.add :send do