diff --git a/Changelog.md b/Changelog.md index 9ab5913e..efe3576a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,7 @@ * Add mutation from `Date.parse` to more strict parsing methods #448 * Add mutation from `foo.to_i` to `Integer(foo)` #455 +* Add mutation from `@foo` to `foo` #454 # v0.8.5 2015-09-11 diff --git a/config/flay.yml b/config/flay.yml index 43da80e3..d8f24430 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 18 -total_score: 1244 +total_score: 1253 diff --git a/lib/mutant/mutator/node/named_value/access.rb b/lib/mutant/mutator/node/named_value/access.rb index c4f96b99..aa78db3a 100644 --- a/lib/mutant/mutator/node/named_value/access.rb +++ b/lib/mutant/mutator/node/named_value/access.rb @@ -6,7 +6,7 @@ module Mutant # Mutation emitter to handle named value access nodes class Access < Node - handle(:gvar, :cvar, :ivar, :lvar, :self) + handle(:gvar, :cvar, :lvar, :self) private @@ -19,6 +19,45 @@ module Mutant emit_singletons end + # Named value access emitter for instance variables + class Ivar < Access + NAME_RANGE = (1..-1).freeze + + handle(:ivar) + + children :name + + # Emit mutations + # + # @return [undefined] + # + # @api private + def dispatch + emit_attribute_read + super() + end + + private + + # Emit instance variable as attribute send + # + # @return [undefined] + # + # @api private + def emit_attribute_read + emit(s(:send, nil, attribute_name)) + end + + # Variable name without leading '@' + # + # @return [Symbol] + # + # @api private + def attribute_name + name.slice(NAME_RANGE).to_sym + end + end + end # Access end # NamedValue end # Node diff --git a/meta/ivar.rb b/meta/ivar.rb new file mode 100644 index 00000000..ba5f8b3f --- /dev/null +++ b/meta/ivar.rb @@ -0,0 +1,6 @@ +Mutant::Meta::Example.add do + source '@foo' + + singleton_mutations + mutation 'foo' +end diff --git a/meta/op_assgn.rb b/meta/op_assgn.rb index d6775f0b..6299039c 100644 --- a/meta/op_assgn.rb +++ b/meta/op_assgn.rb @@ -2,6 +2,7 @@ Mutant::Meta::Example.add do source '@a.b += 1' singleton_mutations + mutation 'a.b += 1' mutation '@a.b += -1' mutation '@a.b += 2' mutation '@a.b += 0'