2012-07-26 13:25:23 -04:00
|
|
|
module Mutant
|
2012-11-21 16:28:08 -05:00
|
|
|
# Subject of a mutation
|
2012-08-01 12:34:03 -04:00
|
|
|
class Subject
|
2013-07-28 13:05:17 -04:00
|
|
|
include AbstractType, Adamantium::Flat, Enumerable
|
|
|
|
include Concord::Public.new(:context, :node)
|
2012-07-26 13:25:23 -04:00
|
|
|
|
2013-07-14 19:17:15 -04:00
|
|
|
# Return mutations
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
2013-07-14 19:17:15 -04:00
|
|
|
# @return [Enumerable<Mutation>]
|
2012-12-10 18:17:19 -05:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-07-14 19:17:15 -04:00
|
|
|
def mutations
|
|
|
|
mutations = []
|
|
|
|
generate_mutations(mutations)
|
|
|
|
mutations
|
2012-12-10 18:17:19 -05:00
|
|
|
end
|
2013-07-14 19:17:15 -04:00
|
|
|
memoize :mutations
|
2012-12-10 18:17:19 -05:00
|
|
|
|
2012-12-14 13:53:37 -05:00
|
|
|
# Return source path
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def source_path
|
|
|
|
context.source_path
|
|
|
|
end
|
|
|
|
|
2014-03-14 17:34:21 -04:00
|
|
|
# Prepare the subject for the insertion of mutation
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def prepare
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2012-12-14 13:53:37 -05:00
|
|
|
# Return source line
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def source_line
|
2013-06-14 14:23:46 -04:00
|
|
|
node.location.expression.line
|
2012-12-14 13:53:37 -05:00
|
|
|
end
|
|
|
|
|
2013-06-23 02:08:32 -04:00
|
|
|
# Return subject identification
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @return [String]
|
2012-07-26 13:25:23 -04:00
|
|
|
#
|
|
|
|
# @api private
|
2012-07-30 22:10:37 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
def identification
|
2013-08-04 12:49:42 -04:00
|
|
|
"#{match_expression}:#{source_path}:#{source_line}"
|
2012-07-26 13:25:23 -04:00
|
|
|
end
|
2012-08-15 22:10:54 -04:00
|
|
|
memoize :identification
|
2012-07-26 13:25:23 -04:00
|
|
|
|
2012-08-15 22:10:54 -04:00
|
|
|
# Return source representation of ast
|
2012-08-14 06:27:56 -04:00
|
|
|
#
|
2013-06-21 17:52:57 -04:00
|
|
|
# @return [String]
|
2012-08-14 06:27:56 -04:00
|
|
|
#
|
|
|
|
# @api private
|
2013-04-17 23:31:21 -04:00
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
def source
|
2013-06-21 17:52:57 -04:00
|
|
|
Unparser.unparse(node)
|
2012-08-14 06:27:56 -04:00
|
|
|
end
|
2012-08-15 22:10:54 -04:00
|
|
|
memoize :source
|
2012-08-14 06:27:56 -04:00
|
|
|
|
2012-08-14 16:45:34 -04:00
|
|
|
# Return root AST for node
|
|
|
|
#
|
2013-06-04 04:25:13 -04:00
|
|
|
# @param [Parser::AST::Node] node
|
2012-08-14 16:45:34 -04:00
|
|
|
#
|
2013-06-04 04:25:13 -04:00
|
|
|
# @return [Parser::AST::Node]
|
2012-08-14 16:45:34 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def root(node)
|
|
|
|
context.root(node)
|
|
|
|
end
|
|
|
|
|
2012-08-15 22:10:54 -04:00
|
|
|
# Return root AST node for original AST ndoe
|
|
|
|
#
|
2013-06-04 04:25:13 -04:00
|
|
|
# @return [Parser::AST::Node]
|
2012-08-15 22:10:54 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def original_root
|
2012-10-26 05:24:29 -04:00
|
|
|
root(node)
|
2012-08-15 22:10:54 -04:00
|
|
|
end
|
|
|
|
memoize :original_root
|
|
|
|
|
2013-08-04 12:49:42 -04:00
|
|
|
# Return match expression
|
2013-01-13 16:25:49 -05:00
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-08-04 12:49:42 -04:00
|
|
|
abstract_method :match_expression
|
|
|
|
|
|
|
|
# Return match prefixes
|
|
|
|
#
|
|
|
|
# @return [Enumerable<String>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def match_prefixes
|
2013-08-04 13:30:34 -04:00
|
|
|
[match_expression].concat(context.match_prefixes)
|
2013-08-04 12:49:42 -04:00
|
|
|
end
|
|
|
|
memoize :match_prefixes
|
|
|
|
|
|
|
|
private
|
2013-01-13 16:25:49 -05:00
|
|
|
|
2013-07-04 18:54:50 -04:00
|
|
|
# Return neutral mutation
|
|
|
|
#
|
|
|
|
# @return [Mutation::Neutral]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def noop_mutation
|
|
|
|
Mutation::Neutral::Noop.new(self, node)
|
|
|
|
end
|
|
|
|
|
2013-07-14 19:17:15 -04:00
|
|
|
# Generate mutations
|
|
|
|
#
|
|
|
|
# @param [#<<] emitter
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
abstract_method :generate_mutations
|
|
|
|
|
2013-06-04 04:25:13 -04:00
|
|
|
end # Subject
|
|
|
|
end # Mutant
|