
Several steps were made to achieve mutant working with Ruby 2.4 without warnings and spec failures: * Fix Fixnum deprecation warning * Update RuboCop to 0.47 and fix offenses * Relax version requirements on parser gem * Update diff-lcs to 1.3 * Update rake 11.x -> 12.x * Update reek 4.5 -> 4.6 (to work with parser 2.4) * Update json 2.0 -> 2.1 * Update parallel 1.10 -> 1.11 * Update simplecov 0.12 -> 0.14 * Run regexp_parser integration against v0.4.3 (as we requiring this exact version) * Update warnings.yml with new whitelist * Run CircleCI tests on Ruby 2.3 and 2.4 (Bundler.with_clean_env was causing troubles on new CircleCI 2.0 setup, so it was removed)
95 lines
1.9 KiB
Ruby
95 lines
1.9 KiB
Ruby
module Mutant
|
|
# Subject of a mutation
|
|
class Subject
|
|
include AbstractType, Adamantium::Flat, Enumerable
|
|
include Concord::Public.new(:context, :node)
|
|
|
|
# Mutations for this subject
|
|
#
|
|
# @return [Enumerable<Mutation>]
|
|
# @return [undefined]
|
|
def mutations
|
|
[neutral_mutation].concat(
|
|
Mutator.mutate(node).map do |mutant|
|
|
Mutation::Evil.new(self, wrap_node(mutant))
|
|
end
|
|
)
|
|
end
|
|
memoize :mutations
|
|
|
|
# Source path
|
|
#
|
|
# @return [Pathname]
|
|
def source_path
|
|
context.source_path
|
|
end
|
|
|
|
# Prepare subject for insertion of mutation
|
|
#
|
|
# @return [self]
|
|
def prepare
|
|
self
|
|
end
|
|
|
|
# Source line range
|
|
#
|
|
# @return [Range<Integer>]
|
|
def source_lines
|
|
expression = node.location.expression
|
|
expression.line..expression.source_buffer.decompose_position(expression.end_pos).first
|
|
end
|
|
memoize :source_lines
|
|
|
|
# First source line
|
|
#
|
|
# @return [Integer]
|
|
def source_line
|
|
source_lines.begin
|
|
end
|
|
|
|
# Identification string
|
|
#
|
|
# @return [String]
|
|
def identification
|
|
"#{expression.syntax}:#{source_path}:#{source_line}"
|
|
end
|
|
memoize :identification
|
|
|
|
# Source representation of AST
|
|
#
|
|
# @return [String]
|
|
def source
|
|
Unparser.unparse(wrap_node(node))
|
|
end
|
|
memoize :source
|
|
|
|
# Match expression
|
|
#
|
|
# @return [Expression]
|
|
abstract_method :expression
|
|
|
|
# Match expressions
|
|
#
|
|
# @return [Enumerable<Expression>]
|
|
abstract_method :match_expressions
|
|
|
|
private
|
|
|
|
# Neutral mutation
|
|
#
|
|
# @return [Mutation::Neutral]
|
|
def neutral_mutation
|
|
Mutation::Neutral.new(self, wrap_node(node))
|
|
end
|
|
|
|
# Wrap node into subject specific container
|
|
#
|
|
# @param [Parser::AST::Node] node
|
|
#
|
|
# @return [Parser::AST::Node]
|
|
def wrap_node(node)
|
|
node
|
|
end
|
|
|
|
end # Subject
|
|
end # Mutant
|