Refactor example verification to reduce redundant unparsing

This commit is contained in:
Markus Schirp 2018-12-01 22:44:38 +00:00
parent bfd41e6948
commit 9219e3b018

View file

@ -34,12 +34,24 @@ module Mutant
# Unexpected mutations
#
# @return [Array<Parser::AST::Node>]
# @return [Array<Mutation>]
def unexpected
mutations.map(&:node) - example.expected
mutations.reject do |mutation|
example.expected.include?(mutation.node)
end
end
memoize :unexpected
# Missing mutations
#
# @return [Array<Mutation>]
def missing
(example.expected - mutations.map(&:node)).map do |node|
Mutation::Evil.new(self, node)
end
end
memoize :missing
# Mutations with no diff to original
#
# @return [Enumerable<Mutation>]
@ -50,14 +62,14 @@ module Mutant
# Mutation report
#
# @param [Array<Parser::AST::Node>] nodes
# @param [Array<Mutation>] mutations
#
# @return [Array<Hash>]
def format_mutations(nodes)
nodes.map do |node|
def format_mutations(mutations)
mutations.map do |mutation|
{
'node' => node.inspect,
'source' => Unparser.unparse(node)
'node' => mutation.node.inspect,
'source' => mutation.source
}
end
end
@ -74,14 +86,6 @@ module Mutant
end
end
# Missing mutations
#
# @return [Array<Parser::AST::Node>]
def missing
example.expected - mutations.map(&:node)
end
memoize :missing
end # Verification
end # Example
end # Meta