2018-09-12 14:21:24 +00:00
|
|
|
# frozen_string_literal: true
|
2018-09-12 13:15:43 +00:00
|
|
|
|
2014-06-04 16:09:24 +00:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
|
|
|
|
Fix incorrect mutator comments
I used a script which detects duplicate comments:
require 'parser/current'
require 'pathname'
require 'concord'
class Comment
include Equalizer.new(:text)
def initialize(path, comment)
@path = path
@comment = comment
end
def text
comment.text
end
def <=>(other)
text <=> other.text
end
attr_reader :path, :comment
end
comments =
Pathname
.glob('lib/**/*.rb')
.flat_map do |path|
Parser::CurrentRuby
.parse_with_comments(path.read)
.last
.map do |comment|
Comment.new(path, comment)
end
end
@seen = Set.new
ignores = [
'#',
'# otherwise',
/\A# [A-Z]\w+\z/,
/\A# rubocop:disable \w+/,
/\A# @\w/,
/\A# @\w/,
/\A# @\w/,
/\A# @\w/,
]
duplicates = []
comments
.reject do |comment|
ignores.any? { |ignore| ignore === comment.text }
end
.sort
.group_by { |comment| comment.text }
.reject { |_, comments| comments.one? }
.sort_by { |_, comments| comments.size }
.each do |text, comments|
next if comments.one?
warn text
comments.each do |comment|
warn " #{comment.path}:#{comment.comment.loc.line}"
end
end
2016-06-18 15:28:49 -07:00
|
|
|
# OrAsgn mutator
|
2014-06-04 16:09:24 +00:00
|
|
|
class OrAsgn < self
|
|
|
|
|
|
|
|
handle(:or_asgn)
|
|
|
|
|
|
|
|
children :left, :right
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Emit mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def dispatch
|
2014-06-05 16:37:31 +00:00
|
|
|
emit_singletons
|
2014-06-04 16:09:24 +00:00
|
|
|
emit_right_mutations
|
2014-06-10 02:05:58 +00:00
|
|
|
return if n_ivasgn?(left)
|
|
|
|
emit_left_mutations do |node|
|
2015-06-13 14:20:36 +00:00
|
|
|
AST::Types::ASSIGNABLE_VARIABLES.include?(node.type)
|
2014-06-10 02:05:58 +00:00
|
|
|
end
|
2014-06-04 16:09:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end # OrAsgn
|
|
|
|
end # Node
|
|
|
|
end # Mutator
|
|
|
|
end # Mutant
|