2018-09-12 14:21:24 +00:00
|
|
|
# frozen_string_literal: true
|
2018-09-12 13:15:43 +00:00
|
|
|
|
2012-07-26 19:25:23 +02:00
|
|
|
module Mutant
|
2012-11-21 22:28:08 +01:00
|
|
|
# Subject of a mutation
|
2012-08-01 18:34:03 +02:00
|
|
|
class Subject
|
2013-07-28 19:05:17 +02:00
|
|
|
include AbstractType, Adamantium::Flat, Enumerable
|
2014-12-22 15:42:21 +00:00
|
|
|
include Concord::Public.new(:context, :node)
|
2012-07-26 19:25:23 +02:00
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Mutations for this subject
|
2012-07-26 19:25:23 +02:00
|
|
|
#
|
2013-07-15 01:17:15 +02:00
|
|
|
# @return [Enumerable<Mutation>]
|
2014-07-03 21:16:12 +00:00
|
|
|
# @return [undefined]
|
2013-07-15 01:17:15 +02:00
|
|
|
def mutations
|
2016-02-14 04:28:59 +00:00
|
|
|
[neutral_mutation].concat(
|
2016-05-05 23:36:46 -07:00
|
|
|
Mutator.mutate(node).map do |mutant|
|
2016-02-14 04:28:59 +00:00
|
|
|
Mutation::Evil.new(self, wrap_node(mutant))
|
|
|
|
end
|
|
|
|
)
|
2012-12-11 00:17:19 +01:00
|
|
|
end
|
2013-07-15 01:17:15 +02:00
|
|
|
memoize :mutations
|
2012-12-11 00:17:19 +01:00
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Source path
|
2012-12-14 19:53:37 +01:00
|
|
|
#
|
2015-07-28 11:50:54 -07:00
|
|
|
# @return [Pathname]
|
2012-12-14 19:53:37 +01:00
|
|
|
def source_path
|
|
|
|
context.source_path
|
|
|
|
end
|
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Prepare subject for insertion of mutation
|
2014-03-14 21:34:21 +00:00
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
def prepare
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Source line range
|
2014-10-05 15:04:57 +00:00
|
|
|
#
|
2017-07-06 09:45:17 +02:00
|
|
|
# @return [Range<Integer>]
|
2014-10-05 15:04:57 +00:00
|
|
|
def source_lines
|
|
|
|
expression = node.location.expression
|
|
|
|
expression.line..expression.source_buffer.decompose_position(expression.end_pos).first
|
|
|
|
end
|
|
|
|
memoize :source_lines
|
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# First source line
|
2012-12-14 19:53:37 +01:00
|
|
|
#
|
2017-07-06 09:45:17 +02:00
|
|
|
# @return [Integer]
|
2012-12-14 19:53:37 +01:00
|
|
|
def source_line
|
2014-10-05 15:04:57 +00:00
|
|
|
source_lines.begin
|
2012-12-14 19:53:37 +01:00
|
|
|
end
|
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Identification string
|
2012-07-26 19:25:23 +02:00
|
|
|
#
|
2012-08-16 04:10:54 +02:00
|
|
|
# @return [String]
|
|
|
|
def identification
|
2014-06-28 20:47:46 +00:00
|
|
|
"#{expression.syntax}:#{source_path}:#{source_line}"
|
2012-07-26 19:25:23 +02:00
|
|
|
end
|
2012-08-16 04:10:54 +02:00
|
|
|
memoize :identification
|
2012-07-26 19:25:23 +02:00
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Source representation of AST
|
2012-08-14 12:27:56 +02:00
|
|
|
#
|
2013-06-21 23:52:57 +02:00
|
|
|
# @return [String]
|
2012-08-16 04:10:54 +02:00
|
|
|
def source
|
2014-12-07 21:27:38 +00:00
|
|
|
Unparser.unparse(wrap_node(node))
|
2012-08-14 12:27:56 +02:00
|
|
|
end
|
2012-08-16 04:10:54 +02:00
|
|
|
memoize :source
|
2012-08-14 12:27:56 +02:00
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Match expression
|
2013-01-13 22:25:49 +01:00
|
|
|
#
|
2014-06-28 20:47:46 +00:00
|
|
|
# @return [Expression]
|
|
|
|
abstract_method :expression
|
2013-08-04 18:49:42 +02:00
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Match expressions
|
2013-08-04 18:49:42 +02:00
|
|
|
#
|
2014-06-28 20:47:46 +00:00
|
|
|
# @return [Enumerable<Expression>]
|
2014-10-08 15:16:05 +00:00
|
|
|
abstract_method :match_expressions
|
2013-08-04 18:49:42 +02:00
|
|
|
|
|
|
|
private
|
2013-01-13 22:25:49 +01:00
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Neutral mutation
|
2013-07-05 00:54:50 +02:00
|
|
|
#
|
|
|
|
# @return [Mutation::Neutral]
|
2014-07-05 23:32:07 +00:00
|
|
|
def neutral_mutation
|
2014-12-07 21:27:38 +00:00
|
|
|
Mutation::Neutral.new(self, wrap_node(node))
|
2013-07-05 00:54:50 +02:00
|
|
|
end
|
|
|
|
|
2014-12-07 21:27:38 +00:00
|
|
|
# Wrap node into subject specific container
|
2013-07-15 01:17:15 +02:00
|
|
|
#
|
2014-12-07 21:27:38 +00:00
|
|
|
# @param [Parser::AST::Node] node
|
2013-07-15 01:17:15 +02:00
|
|
|
#
|
2014-12-07 21:27:38 +00:00
|
|
|
# @return [Parser::AST::Node]
|
|
|
|
def wrap_node(node)
|
|
|
|
node
|
2014-07-05 23:32:07 +00:00
|
|
|
end
|
2013-07-15 01:17:15 +02:00
|
|
|
|
2013-06-04 10:25:13 +02:00
|
|
|
end # Subject
|
|
|
|
end # Mutant
|