From 8995bc844ead57358676358d71e83aa7c96cec47 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 30 Jul 2012 22:39:03 +0200 Subject: [PATCH] Bring back yard coverage to 100% --- lib/mutant/mutator.rb | 12 +++++-- lib/mutant/mutator/array_literal.rb | 51 ++++++++++++++++++++++++++--- lib/mutant/mutator/block.rb | 37 +++++++++++++++++++++ lib/mutant/mutator/empty_array.rb | 9 +++++ lib/mutant/mutator/hash_literal.rb | 40 ++++++++++++++++++++-- lib/mutant/mutator/range.rb | 10 +++++- lib/mutant/mutator/range_exclude.rb | 10 +++++- lib/mutant/mutator/true_literal.rb | 2 +- 8 files changed, 158 insertions(+), 13 deletions(-) diff --git a/lib/mutant/mutator.rb b/lib/mutant/mutator.rb index 4f07cec3..3d3b37a0 100644 --- a/lib/mutant/mutator.rb +++ b/lib/mutant/mutator.rb @@ -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] + # returns enumerator on AST nodes otherwise + # + # @api private + # def each(&block) return to_enum unless block_given? mutants(Generator.new(@node,block)) diff --git a/lib/mutant/mutator/array_literal.rb b/lib/mutant/mutator/array_literal.rb index 11e0d2f5..5f42cd32 100644 --- a/lib/mutant/mutator/array_literal.rb +++ b/lib/mutant/mutator/array_literal.rb @@ -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 diff --git a/lib/mutant/mutator/block.rb b/lib/mutant/mutator/block.rb index 815b7868..7d64b0b9 100644 --- a/lib/mutant/mutator/block.rb +++ b/lib/mutant/mutator/block.rb @@ -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 diff --git a/lib/mutant/mutator/empty_array.rb b/lib/mutant/mutator/empty_array.rb index e5ed2c56..e25171be 100644 --- a/lib/mutant/mutator/empty_array.rb +++ b/lib/mutant/mutator/empty_array.rb @@ -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]) diff --git a/lib/mutant/mutator/hash_literal.rb b/lib/mutant/mutator/hash_literal.rb index 3ce289e7..22b5e03c 100644 --- a/lib/mutant/mutator/hash_literal.rb +++ b/lib/mutant/mutator/hash_literal.rb @@ -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 diff --git a/lib/mutant/mutator/range.rb b/lib/mutant/mutator/range.rb index b46f5f4b..ff9a105c 100644 --- a/lib/mutant/mutator/range.rb +++ b/lib/mutant/mutator/range.rb @@ -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) diff --git a/lib/mutant/mutator/range_exclude.rb b/lib/mutant/mutator/range_exclude.rb index 5ddd67a0..51a9fb82 100644 --- a/lib/mutant/mutator/range_exclude.rb +++ b/lib/mutant/mutator/range_exclude.rb @@ -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) diff --git a/lib/mutant/mutator/true_literal.rb b/lib/mutant/mutator/true_literal.rb index 2098a9ae..c03e4f4e 100644 --- a/lib/mutant/mutator/true_literal.rb +++ b/lib/mutant/mutator/true_literal.rb @@ -12,7 +12,7 @@ module Mutant # @return [undefined] # def mutants(generator) - generator << new_ni + generator << new_nil generator << new(Rubinius::AST::FalseLiteral) end end