Add nthref mutator

Closes #20
This commit is contained in:
Markus Schirp 2013-08-03 01:36:13 +02:00
parent a700eb22d3
commit 0ffa49620e
4 changed files with 48 additions and 1 deletions

View file

@ -73,6 +73,7 @@ require 'mutant/mutator/node/send/binary'
require 'mutant/mutator/node/when'
require 'mutant/mutator/node/define'
require 'mutant/mutator/node/mlhs'
require 'mutant/mutator/node/nthref'
require 'mutant/mutator/node/masgn'
require 'mutant/mutator/node/return'
require 'mutant/mutator/node/block'

View file

@ -15,7 +15,7 @@ module Mutant
:blockarg, :op_asgn, :and_asgn,
:regopt, :restarg, :resbody, :retry, :arg_expr,
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty,
:alias, :for, :xstr, :back_ref, :nth_ref, :class,
:alias, :for, :xstr, :back_ref, :class,
:sclass, :match_with_lvasgn, :match_current_line, :or_asgn, :kwbegin
)

View file

@ -0,0 +1,27 @@
module Mutant
class Mutator
class Node
# Mutator for nth-ref nodes
class NthRef < self
handle :nth_ref
children :number
private
# Perform dispatch
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_number(number - 1)
emit_number(number + 1)
end
end # NthRef
end # Node
end # Mutator
end # Mutant

View file

@ -0,0 +1,19 @@
# encoding: utf-8
require 'spec_helper'
describe Mutant::Mutator, 'nthref' do
context '$1' do
let(:source) { '$1' }
let(:mutations) { ['$2', '$0'] }
it_should_behave_like 'a mutator'
end
context '$2' do
let(:source) { '$2' }
let(:mutations) { ['$3', '$1'] }
it_should_behave_like 'a mutator'
end
end