1
0
Fork 0

Port mutation generator infrastructure to parser

This commit is contained in:
Markus Schirp 2013-06-04 19:26:53 +02:00
parent fca5b8a168
commit 90aa3589fa
3 changed files with 13 additions and 12 deletions
lib/mutant
spec/shared

View file

@ -5,16 +5,16 @@ module Mutant
# Run mutator on input
#
# @param [Object] input
# @param [Parser::AST::Node] node
# @param [#call] block
#
# @return [self]
#
# @api private
#
def self.each(input, &block)
return to_enum(__method__, input) unless block_given?
Registry.lookup(input.class).new(input, block)
def self.each(node, &block)
return to_enum(__method__, node) unless block_given?
Registry.lookup(node).new(node, block)
self
end

View file

@ -27,9 +27,9 @@ module Mutant
self
end
# Lookup mutator class for AST node class
# Lookup mutator class for node
#
# @param [Class] ast_class
# @param [Parser::AST::Node] node
#
# @return [Class]
#
@ -38,9 +38,10 @@ module Mutant
#
# @api private
#
def self.lookup(ast_class)
registry.fetch(ast_class) do
raise ArgumentError,"No mutator to handle: #{ast_class.inspect}"
def self.lookup(node)
type = node.type
registry.fetch(type) do
raise ArgumentError,"No mutator to handle: #{type.inspect}"
end
end
end

View file

@ -1,11 +1,11 @@
shared_examples_for 'a mutator' do
subject { object.each(node) { |item| yields << item } }
let(:yields) { [] }
let(:object) { described_class }
let(:yields) { [] }
let(:object) { described_class }
unless instance_methods.map(&:to_s).include?('node')
let(:node) { parse(source) }
let(:node) { parse(source) }
end
it_should_behave_like 'a command method'