From 7ccbae8bd4fdb1dd7f47c8d00490da36a6c693f6 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Wed, 1 Aug 2012 15:08:29 +0200 Subject: [PATCH] Add match all and match none mutations to regexp --- lib/mutant/mutator/literal/regex.rb | 17 ++++++++++++++++- spec/unit/mutant/mutator/literal/regex_spec.rb | 14 ++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/mutant/mutator/literal/regex.rb b/lib/mutant/mutator/literal/regex.rb index 054715a3..cf674587 100644 --- a/lib/mutant/mutator/literal/regex.rb +++ b/lib/mutant/mutator/literal/regex.rb @@ -16,7 +16,22 @@ module Mutant # def dispatch emit_nil - emit_new { new_self(Random.hex_string, node.options) } + emit_self('') # match all + emit_self('a\A') # match nothing + emit_new { new_self(Random.hex_string) } + end + + # Return new Rubinius::AST::Regex + # + # @param [String] source + # + # @param [Integer] options + # options of regexp, defaults to mutation subject node options + # + # @return [undefined] + # + def new_self(source,options=nil) + super(source,options || node.options) end end end diff --git a/spec/unit/mutant/mutator/literal/regex_spec.rb b/spec/unit/mutant/mutator/literal/regex_spec.rb index c2dbbfdc..45fcd038 100644 --- a/spec/unit/mutant/mutator/literal/regex_spec.rb +++ b/spec/unit/mutant/mutator/literal/regex_spec.rb @@ -9,6 +9,8 @@ describe Mutant::Mutator::Literal, 'regex' do mutations = [] mutations << 'nil' mutations << "/#{random_string}/" + mutations << '//' # match all + mutations << '/a\A/' # match nothing end before do @@ -18,16 +20,4 @@ describe Mutant::Mutator::Literal, 'regex' do let(:mutations) { base_mutations } it_should_behave_like 'a mutator' - - context 'when source is empty regexp' do - before do - pending - end - - let(:source) { '//' } - - let(:mutations) { base_mutations - [source.to_ast] } - - it_should_behave_like 'a mutator' - end end