Add mutation A.const_get(:B) -> A::B

Closes #422
This commit is contained in:
John Backus 2015-08-19 19:30:35 -04:00 committed by Markus Schirp
parent 1f26cf554e
commit a8453f01cc
6 changed files with 59 additions and 1 deletions

View file

@ -1,3 +1,7 @@
# v0.8.4 2015-09-xx
* Add mutation `A.const_get(:B)` -> `A::B` #426
# v0.8.3 2015-09-01
* Remove invalid mutation `super(...)` to `super`

View file

@ -1,3 +1,3 @@
---
threshold: 18
total_score: 1200
total_score: 1214

View file

@ -49,6 +49,7 @@ require 'mutant/ast/named_children'
require 'mutant/ast/node_predicates'
require 'mutant/ast/meta'
require 'mutant/ast/meta/send'
require 'mutant/ast/meta/symbol'
require 'mutant/ast/meta/optarg'
require 'mutant/ast/meta/resbody'
require 'mutant/actor'

View file

@ -0,0 +1,15 @@
module Mutant
module AST
# Node meta information mixin
module Meta
# Metadata for symbol nodes
class Symbol
include NamedChildren, Concord.new(:node)
children :name
end # Symbol
end # Meta
end # AST
end # Mutant

View file

@ -90,11 +90,23 @@ module Mutant
def normal_dispatch
emit_naked_receiver
emit_selector_replacement
emit_const_get_mutation
emit_argument_propagation
mutate_receiver
mutate_arguments
end
# Emit mutation from `const_get` to const literal
#
# @return [undefined]
#
# @api private
def emit_const_get_mutation
return unless selector.equal?(:const_get) && n_sym?(arguments.first)
emit(s(:const, receiver, AST::Meta::Symbol.new(arguments.first).name))
end
# Emit selector replacement
#
# @return [undefined]

View file

@ -14,6 +14,32 @@ Mutant::Meta::Example.add do
mutation 'b'
end
Mutant::Meta::Example.add do
source 'A.const_get(:B)'
singleton_mutations
mutation 'A::B'
mutation 'A.const_get'
mutation 'A'
mutation ':B'
mutation 'A.const_get(nil)'
mutation 'A.const_get(self)'
mutation 'A.const_get(:B__mutant__)'
mutation 'self.const_get(:B)'
end
Mutant::Meta::Example.add do
source 'A.const_get(bar)'
singleton_mutations
mutation 'A.const_get'
mutation 'A'
mutation 'bar'
mutation 'A.const_get(nil)'
mutation 'A.const_get(self)'
mutation 'self.const_get(bar)'
end
Mutant::Meta::Example.add do
source 'a >= b'