Extract meta duplication to regexp_mutations
This commit is contained in:
parent
79c6704d6e
commit
dd58822cc1
7 changed files with 37 additions and 55 deletions
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 16
|
||||
total_score: 1284
|
||||
total_score: 1290
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue