a19f3b1691
* I do not use 1.9.3 * Also keeping them in each file increases mental overhead (true it *can* be autoamted) * None of the files encodes NON ASCII chars. * I do not expect it makes any difference, since nobody programmatically will consume strings generated by mutant under the assumption they are UTF-8 encoded. * 1.9.3 Users have to deal with the encoding fuckup under ruby anyways.
137 lines
2.3 KiB
Ruby
137 lines
2.3 KiB
Ruby
module Mutant
|
|
# Subject of a mutation
|
|
class Subject
|
|
include AbstractType, Adamantium::Flat, Enumerable
|
|
include Concord::Public.new(:context, :node)
|
|
|
|
# Return mutations
|
|
#
|
|
# @return [Enumerable<Mutation>]
|
|
#
|
|
# @api private
|
|
#
|
|
def mutations
|
|
mutations = []
|
|
generate_mutations(mutations)
|
|
mutations
|
|
end
|
|
memoize :mutations
|
|
|
|
# Return source path
|
|
#
|
|
# @return [String]
|
|
#
|
|
# @api private
|
|
#
|
|
def source_path
|
|
context.source_path
|
|
end
|
|
|
|
# Prepare the subject for the insertion of mutation
|
|
#
|
|
# @return [self]
|
|
#
|
|
# @api private
|
|
#
|
|
def prepare
|
|
self
|
|
end
|
|
|
|
# Return source line
|
|
#
|
|
# @return [Fixnum]
|
|
#
|
|
# @api private
|
|
#
|
|
def source_line
|
|
node.location.expression.line
|
|
end
|
|
|
|
# Return subject identification
|
|
#
|
|
# @return [String]
|
|
#
|
|
# @api private
|
|
#
|
|
def identification
|
|
"#{match_expression}:#{source_path}:#{source_line}"
|
|
end
|
|
memoize :identification
|
|
|
|
# Return source representation of ast
|
|
#
|
|
# @return [String]
|
|
#
|
|
# @api private
|
|
#
|
|
def source
|
|
Unparser.unparse(node)
|
|
end
|
|
memoize :source
|
|
|
|
# Return root AST for node
|
|
#
|
|
# @param [Parser::AST::Node] node
|
|
#
|
|
# @return [Parser::AST::Node]
|
|
#
|
|
# @api private
|
|
#
|
|
def root(node)
|
|
context.root(node)
|
|
end
|
|
|
|
# Return root AST node for original AST ndoe
|
|
#
|
|
# @return [Parser::AST::Node]
|
|
#
|
|
# @api private
|
|
#
|
|
def original_root
|
|
root(node)
|
|
end
|
|
memoize :original_root
|
|
|
|
# Return match expression
|
|
#
|
|
# @return [String]
|
|
#
|
|
# @api private
|
|
#
|
|
abstract_method :match_expression
|
|
|
|
# Return match prefixes
|
|
#
|
|
# @return [Enumerable<String>]
|
|
#
|
|
# @api private
|
|
#
|
|
def match_prefixes
|
|
[match_expression].concat(context.match_prefixes)
|
|
end
|
|
memoize :match_prefixes
|
|
|
|
private
|
|
|
|
# Return neutral mutation
|
|
#
|
|
# @return [Mutation::Neutral]
|
|
#
|
|
# @api private
|
|
#
|
|
def noop_mutation
|
|
Mutation::Neutral::Noop.new(self, node)
|
|
end
|
|
|
|
# Generate mutations
|
|
#
|
|
# @param [#<<] emitter
|
|
#
|
|
# @return [undefined]
|
|
#
|
|
# @api private
|
|
#
|
|
abstract_method :generate_mutations
|
|
|
|
end # Subject
|
|
end # Mutant
|