Correct regexp mutator in case of interpolation

Closes #67
This commit is contained in:
Markus Schirp 2013-07-25 20:24:09 +02:00
parent 811b4737da
commit bd01dd5335
2 changed files with 37 additions and 9 deletions

View file

@ -10,10 +10,18 @@ module Mutant
# No input can ever be matched with this
NULL_REGEXP_SOURCE = 'a\A'.freeze
children :source, :options
private
# Return options
#
# @return [Parser::AST::Node]
#
# @api private
#
def options
children.last
end
# Emit mutants
#
# @return [undefined]
@ -22,6 +30,9 @@ module Mutant
#
def dispatch
emit_nil
children.each_with_index do |child, index|
mutate_child(index) unless child.type == :str
end
emit_self(s(:str, EMPTY_STRING), options)
emit_self(s(:str, NULL_REGEXP_SOURCE), options)
end

View file

@ -2,14 +2,31 @@ require 'spec_helper'
describe Mutant::Mutator::Node::Literal, 'regex' do
let(:source) { '/foo/' }
context 'literal' do
let(:source) { '/foo/' }
let(:mutations) do
mutations = []
mutations << 'nil'
mutations << '//' # match all
mutations << '/a\A/' # match nothing
let(:mutations) do
mutations = []
mutations << 'nil'
mutations << '//' # match all
mutations << '/a\A/' # match nothing
end
it_should_behave_like 'a mutator'
end
context 'interpolated' do
let(:source) { '/#{foo.bar}n/' }
let(:mutations) do
mutations = []
mutations << 'nil'
mutations << '//' # match all
mutations << '/#{foo}n/' # match all
mutations << '/a\A/' # match nothing
end
it_should_behave_like 'a mutator'
end
it_should_behave_like 'a mutator'
end