Extract meta duplication to regexp_mutations

This commit is contained in:
John Backus 2016-08-14 14:25:52 -07:00
parent 79c6704d6e
commit dd58822cc1
No known key found for this signature in database
GPG key ID: 9A91898D0B0B2FBE
7 changed files with 37 additions and 55 deletions

View file

@ -1,3 +1,3 @@
---
threshold: 16
total_score: 1284
total_score: 1290

View file

@ -75,6 +75,14 @@ module Mutant
mutation('self')
end
# Add regexp mutations
#
# @return [undefined]
def regexp_mutations
mutation('//')
mutation('/nomatch\A/')
end
# Helper method to coerce input to node
#
# @param [String,Parser::AST::Node] input

View file

@ -2,56 +2,39 @@ Mutant::Meta::Example.add :regexp do
source '/foo/'
singleton_mutations
# match all inputs
mutation '//'
# match no input
mutation '/nomatch\A/'
regexp_mutations
end
Mutant::Meta::Example.add :regexp do
source '/#{foo.bar}n/'
singleton_mutations
regexp_mutations
mutation '/#{foo}n/'
mutation '/#{self.bar}n/'
mutation '/#{nil}n/'
mutation '/#{self}n/'
# match all inputs
mutation '//'
# match no input
mutation '/nomatch\A/'
end
Mutant::Meta::Example.add :regexp do
source '/#{foo}/'
singleton_mutations
regexp_mutations
mutation '/#{self}/'
mutation '/#{nil}/'
# match all inputs
mutation '//'
# match no input
mutation '/nomatch\A/'
end
Mutant::Meta::Example.add :regexp do
source '/#{foo}#{nil}/'
singleton_mutations
regexp_mutations
mutation '/#{nil}#{nil}/'
mutation '/#{self}#{nil}/'
# match all inputs
mutation '//'
# match no input
mutation '/nomatch\A/'
end
Mutant::Meta::Example.add :regexp do
@ -85,12 +68,7 @@ Mutant::Meta::Example.add :regexp do
source '/(?(1)(foo)(bar))/'
singleton_mutations
# match all inputs
mutation '//'
# match no input
mutation '/nomatch\A/'
regexp_mutations
end
Pathname

View file

@ -2,12 +2,7 @@ Mutant::Meta::Example.add :regexp_bol_anchor do
source '/^/'
singleton_mutations
# match all inputs
mutation '//'
# match no input
mutation '/nomatch\A/'
regexp_mutations
mutation '/\\A/'
end

View file

@ -2,25 +2,15 @@ Mutant::Meta::Example.add :regexp_bos_anchor do
source '/\A/'
singleton_mutations
# match all inputs
mutation '//'
# match no input
mutation '/nomatch\A/'
regexp_mutations
end
Mutant::Meta::Example.add :regexp_bos_anchor do
source '/^#{a}/'
singleton_mutations
regexp_mutations
mutation '/^#{nil}/'
mutation '/^#{self}/'
# match all inputs
mutation '//'
# match no input
mutation '/nomatch\A/'
end

View file

@ -2,12 +2,7 @@ Mutant::Meta::Example.add :regexp_root_expression do
source '/^/'
singleton_mutations
# match all inputs
mutation '//'
# match no input
mutation '/nomatch\A/'
regexp_mutations
mutation '/\\A/'
end

View file

@ -76,6 +76,22 @@ RSpec.describe Mutant::Meta::Example::DSL do
end
end
context 'using #regexp_mutations' do
let(:expected) do
[s(:regexp, s(:regopt)), s(:regexp, s(:str, 'nomatch\\A'), s(:regopt))]
end
let(:node) do
s(:regexp, s(:str, 'foo'), s(:regopt))
end
expect_example do
source '/foo/'
regexp_mutations
end
end
context 'no definition of source' do
expect_error('source not defined') do
end