From ec7e6c1d5fc3205033e165110306afea6b0d05c2 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 3 Nov 2013 20:35:39 -0800 Subject: [PATCH] Add mutator for next nodes --- lib/mutant.rb | 1 + lib/mutant/mutator/node/generic.rb | 2 +- lib/mutant/mutator/node/next.rb | 30 +++++++++++++++++++ .../mutant/mutator/node/next/mutation_spec.rb | 5 +++- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 lib/mutant/mutator/node/next.rb diff --git a/lib/mutant.rb b/lib/mutant.rb index 8db007b4..42e647fd 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -72,6 +72,7 @@ require 'mutant/mutator/node/dsym' require 'mutant/mutator/node/named_value/access' require 'mutant/mutator/node/named_value/constant_assignment' require 'mutant/mutator/node/named_value/variable_assignment' +require 'mutant/mutator/node/next' require 'mutant/mutator/node/noop' require 'mutant/mutator/node/op_asgn' require 'mutant/mutator/node/while' diff --git a/lib/mutant/mutator/node/generic.rb b/lib/mutant/mutator/node/generic.rb index 8d5b8e2d..75963c09 100644 --- a/lib/mutant/mutator/node/generic.rb +++ b/lib/mutant/mutator/node/generic.rb @@ -10,7 +10,7 @@ module Mutant # These nodes still need a dedicated mutator, # your contribution is that close! handle( - :next, :ensure, + :ensure, :rescue, :redo, :defined?, :regopt, :resbody, :retry, :arg_expr, :kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty, diff --git a/lib/mutant/mutator/node/next.rb b/lib/mutant/mutator/node/next.rb new file mode 100644 index 00000000..333cf4a3 --- /dev/null +++ b/lib/mutant/mutator/node/next.rb @@ -0,0 +1,30 @@ +# encoding: utf-8 + +module Mutant + class Mutator + class Node + + # Next mutator + class Next < Generic + + handle(:next) + + private + + # Emit mutations + # + # @return [undefined] + # + # @api private + # + def dispatch + super + children.each_index(&method(:delete_child)) + emit(s(:break, *children)) + emit_nil + end + + end # Next + end # Node + end # Mutator +end # Mutant diff --git a/spec/unit/mutant/mutator/node/next/mutation_spec.rb b/spec/unit/mutant/mutator/node/next/mutation_spec.rb index 4bf4e406..cd6c054d 100644 --- a/spec/unit/mutant/mutator/node/next/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/next/mutation_spec.rb @@ -2,13 +2,16 @@ require 'spec_helper' -describe Mutant::Mutator::Node::Generic, 'next' do +describe Mutant::Mutator::Node::Next, 'next' do let(:source) { 'next true' } let(:mutations) do mutations = [] mutations << 'next false' mutations << 'next nil' + mutations << 'next' + mutations << 'nil' + mutations << 'break true' end it_should_behave_like 'a mutator'