parent
a700eb22d3
commit
0ffa49620e
4 changed files with 48 additions and 1 deletions
|
@ -73,6 +73,7 @@ require 'mutant/mutator/node/send/binary'
|
||||||
require 'mutant/mutator/node/when'
|
require 'mutant/mutator/node/when'
|
||||||
require 'mutant/mutator/node/define'
|
require 'mutant/mutator/node/define'
|
||||||
require 'mutant/mutator/node/mlhs'
|
require 'mutant/mutator/node/mlhs'
|
||||||
|
require 'mutant/mutator/node/nthref'
|
||||||
require 'mutant/mutator/node/masgn'
|
require 'mutant/mutator/node/masgn'
|
||||||
require 'mutant/mutator/node/return'
|
require 'mutant/mutator/node/return'
|
||||||
require 'mutant/mutator/node/block'
|
require 'mutant/mutator/node/block'
|
||||||
|
|
|
@ -15,7 +15,7 @@ module Mutant
|
||||||
:blockarg, :op_asgn, :and_asgn,
|
:blockarg, :op_asgn, :and_asgn,
|
||||||
:regopt, :restarg, :resbody, :retry, :arg_expr,
|
:regopt, :restarg, :resbody, :retry, :arg_expr,
|
||||||
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty,
|
: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
|
:sclass, :match_with_lvasgn, :match_current_line, :or_asgn, :kwbegin
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
27
lib/mutant/mutator/node/nthref.rb
Normal file
27
lib/mutant/mutator/node/nthref.rb
Normal 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
|
19
spec/unit/mutant/mutator/node/nthref/mutation_spec.rb
Normal file
19
spec/unit/mutant/mutator/node/nthref/mutation_spec.rb
Normal 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
|
Loading…
Reference in a new issue