Bring back yard coverage to 100%

This commit is contained in:
Markus Schirp 2012-07-30 22:39:03 +02:00
parent 02a726d767
commit 8995bc844e
8 changed files with 158 additions and 13 deletions

View file

@ -21,8 +21,8 @@ module Mutant
#
# @return [Mutator]
#
# @raise [ArgumentError]
# raises ArgumentError if mutator for node cannot be found
# @raise [NameError]
# raises NameError if mutator for node cannot be found
#
# @api private
#
@ -35,6 +35,14 @@ module Mutant
#
# @api private
#
# @return [self]
# returns self if block given
#
# @return [Enumerator<Rubnius::AST::Node>]
# returns enumerator on AST nodes otherwise
#
# @api private
#
def each(&block)
return to_enum unless block_given?
mutants(Generator.new(@node,block))

View file

@ -1,31 +1,72 @@
module Mutant
class Mutator
# Mutator for array literals
class ArrayLiteral < Mutator
private
# Append mutants to generator
#
# @param [#<<] generator
#
# @return [undefined]
#
# @api private
#
def mutants(generator)
generator << new_nil
generator << new_self([])
generator << new_self(dup_body << new_nil)
mutate_elements(generator)
mutate_element_presence(generator)
mutate_presence(generator)
end
# Return array literal body
#
# @return [Array]
#
# @api private
#
def body
node.body
end
# Return duplicated body on each call
#
# @return [Array]
#
# @api private
#
def dup_body
node.body.dup
body.dup
end
def mutate_element_presence(generator)
node.body.each_with_index do |child,index|
# Append mutations on element presence
#
# @param [#<<] generator
#
# @api private
#
# @return [undefined]
#
def mutate_presence(generator)
body.each_index do |index|
body = dup_body
body.delete_at(index)
generator << new_self(body)
end
end
# Append mutations on elements
#
# @param [#<<] generator
#
# @api private
#
# @return [undefined]
#
def mutate_elements(generator)
node.body.each_with_index do |child,index|
body.each_with_index do |child,index|
body = dup_body
Mutator.build(child).each do |mutation|
body[index]=mutation

View file

@ -1,22 +1,51 @@
module Mutant
class Mutator
# Mutator on AST blocks
class Block < Mutator
private
# Append mutations to block
#
# @param [#<<] generator
#
# @return [undefined]
#
# @api private
#
def mutants(generator)
mutate_elements(generator)
mutate_presence(generator)
end
# Return block array
#
# @return [Array]
#
# @api private
#
def array
node.array
end
# Return duplicated block array each call
#
# @return [Array]
#
# @api private
#
def dup_array
array.dup
end
# Append mutations on block member presence
#
# @param [#<<] generator
#
# @return [undefined]
#
# @api private
#
def mutate_presence(generator)
array.each_index do |index|
array = dup_array
@ -25,6 +54,14 @@ module Mutant
end
end
# Append mutations on block elements
#
# @param [#<<] generator
#
# @return [undefined]
#
# @api private
#
def mutate_elements(generator)
array.each_with_index do |child,index|
array = dup_array

View file

@ -1,9 +1,18 @@
module Mutant
class Mutator
# Mutator for empty array literals
class EmptyArray < Mutator
private
# Append mutations on empty literals
#
# @param [#<<] generator
#
# @return [undefined]
#
# @api private
#
def mutants(generator)
generator << new_nil
generator << new(Rubinius::AST::ArrayLiteral,[new_nil])

View file

@ -1,9 +1,18 @@
module Mutant
class Mutator
# Mutator for hash literal AST nodes
class HashLiteral < Mutator
private
# Append mutants for hash literals
#
# @param [#<<] generator
#
# @return [undefined]
#
# @api private
#
def mutants(generator)
generator << new_nil
generator << new_self([])
@ -12,17 +21,34 @@ module Mutant
mutate_presence(generator)
end
# Return hash literal node array
#
# @return [Array]
#
# @api private
#
def array
node.array
end
# Return duplicated literal array on each call
#
# @return [Array]
#
# @api private
#
def dup_array
array.dup
end
def dup_pairs
end
# Append mutations on pair presence
#
# @param [#<<] generator
#
# @return [undefined]
#
# @api private
#
def mutate_presence(generator)
pairs = array.each_slice(2).to_a
pairs.each_index do |index|
@ -32,6 +58,14 @@ module Mutant
end
end
# Append mutations on members
#
# @param [#<<] generator
#
# @return [undefined]
#
# @api private
#
def mutate_elements(generator)
array.each_with_index do |child,index|
array = dup_array

View file

@ -1,12 +1,20 @@
module Mutant
class Mutator
# Mutator for range literal AST nodes
class Range < Mutator
private
# Append mutations on range literals
#
# @param [#<<] generator
#
# @return [undefined]
#
# @api private
#
def mutants(generator)
generator << new_nil
generator << new(Rubinius::AST::RangeExclude,node.start,node.finish)
generator << new_self(neg_infinity,node.finish)
generator << new_self(nan,node.finish)
generator << new_self(node.start,infinity)

View file

@ -1,13 +1,21 @@
module Mutant
class Mutator
# Mutator for range exclude literals
class RangeExclude < Mutator
private
# Append mutations on range exclude literals
#
# @param [#<<] generator
#
# @return [undefined]
#
# @api private
#
def mutants(generator)
generator << new_nil
generator << new(Rubinius::AST::Range,node.start,node.finish)
generator << new_self(neg_infinity,node.finish)
generator << new_self(nan,node.finish)
generator << new_self(node.start,infinity)

View file

@ -12,7 +12,7 @@ module Mutant
# @return [undefined]
#
def mutants(generator)
generator << new_ni
generator << new_nil
generator << new(Rubinius::AST::FalseLiteral)
end
end