From 5922d927af4d8e49c55ffd313f8186cab8255ff6 Mon Sep 17 00:00:00 2001 From: Daniel Gollahon Date: Sun, 9 Oct 2016 15:48:00 -0700 Subject: [PATCH] Add mutation for $ -> \z --- config/flay.yml | 2 +- lib/mutant.rb | 1 + lib/mutant/mutator/node/generic.rb | 1 + .../mutator/node/regexp/end_of_line_anchor.rb | 21 +++++++++++++++++++ meta/regexp/regexp_eol_anchor.rb | 8 +++++++ meta/regexp/regexp_eos_anchor.rb | 6 ++++++ 6 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 lib/mutant/mutator/node/regexp/end_of_line_anchor.rb create mode 100644 meta/regexp/regexp_eol_anchor.rb create mode 100644 meta/regexp/regexp_eos_anchor.rb diff --git a/config/flay.yml b/config/flay.yml index 575c95ff..9435d93a 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 16 -total_score: 1306 +total_score: 1312 diff --git a/lib/mutant.rb b/lib/mutant.rb index 7e6c54b5..493c5da8 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -93,6 +93,7 @@ require 'mutant/mutator/node/generic' require 'mutant/mutator/node/regexp' require 'mutant/mutator/node/regexp/alternation_meta' require 'mutant/mutator/node/regexp/character_type' +require 'mutant/mutator/node/regexp/end_of_line_anchor' require 'mutant/mutator/node/literal' require 'mutant/mutator/node/literal/boolean' require 'mutant/mutator/node/literal/range' diff --git a/lib/mutant/mutator/node/generic.rb b/lib/mutant/mutator/node/generic.rb index 0c520ddf..63075da9 100644 --- a/lib/mutant/mutator/node/generic.rb +++ b/lib/mutant/mutator/node/generic.rb @@ -40,6 +40,7 @@ module Mutant regexp_alternation_meta regexp_bol_anchor regexp_digit_type + regexp_eol_anchor regexp_nondigit_type regexp_nonspace_type regexp_nonword_boundary_anchor diff --git a/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb b/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb new file mode 100644 index 00000000..ac91ef8e --- /dev/null +++ b/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb @@ -0,0 +1,21 @@ +module Mutant + class Mutator + class Node + module Regexp + # Mutator for end of line anchor `$` + class EndOfLineAnchor < Node + handle(:regexp_eol_anchor) + + # Emit mutations + # + # Replace `$` with `\z` + # + # @return [undefined] + def dispatch + emit(s(:regexp_eos_anchor)) + end + end # EndOfLineAnchor + end # Regexp + end # Node + end # Mutator +end # Mutant diff --git a/meta/regexp/regexp_eol_anchor.rb b/meta/regexp/regexp_eol_anchor.rb new file mode 100644 index 00000000..f17aa835 --- /dev/null +++ b/meta/regexp/regexp_eol_anchor.rb @@ -0,0 +1,8 @@ +Mutant::Meta::Example.add :regexp_eol_anchor do + source '/$/' + + singleton_mutations + regexp_mutations + + mutation '/\z/' +end diff --git a/meta/regexp/regexp_eos_anchor.rb b/meta/regexp/regexp_eos_anchor.rb new file mode 100644 index 00000000..f70a8278 --- /dev/null +++ b/meta/regexp/regexp_eos_anchor.rb @@ -0,0 +1,6 @@ +Mutant::Meta::Example.add :regexp_eos_anchor do + source '/\z/' + + singleton_mutations + regexp_mutations +end