2018-09-12 14:21:24 +00:00
|
|
|
# frozen_string_literal: true
|
2013-06-04 23:44:17 +02:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
|
|
|
|
|
|
|
# Mutator for required arguments
|
|
|
|
class Argument < self
|
2016-04-05 01:17:00 -07:00
|
|
|
handle(:arg, :kwarg)
|
2013-06-04 23:44:17 +02:00
|
|
|
|
|
|
|
UNDERSCORE = '_'.freeze
|
2013-06-21 15:04:44 +02:00
|
|
|
|
|
|
|
children :name
|
2013-06-04 23:44:17 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-06-18 15:39:16 -07:00
|
|
|
# Emit mutations
|
2013-06-04 23:44:17 +02:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def dispatch
|
|
|
|
emit_name_mutation
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit name mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def emit_name_mutation
|
2013-12-04 18:48:20 +01:00
|
|
|
return if skip?
|
2015-08-13 22:02:04 -04:00
|
|
|
emit_name(:"#{UNDERSCORE}#{name}")
|
2013-06-04 23:44:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Test if argument mutation is skipped
|
|
|
|
#
|
2014-06-15 19:27:57 +00:00
|
|
|
# @return [Boolean]
|
2013-06-04 23:44:17 +02:00
|
|
|
def skip?
|
|
|
|
name.to_s.start_with?(UNDERSCORE)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Mutator for optional arguments
|
|
|
|
class Optional < self
|
|
|
|
|
2016-04-05 01:17:45 -07:00
|
|
|
TYPE_MAP = IceNine.deep_freeze(
|
|
|
|
optarg: :arg,
|
|
|
|
kwoptarg: :kwarg
|
|
|
|
)
|
|
|
|
|
|
|
|
handle(:optarg, :kwoptarg)
|
2013-06-04 23:44:17 +02:00
|
|
|
|
2013-06-21 15:52:46 +02:00
|
|
|
children :name, :default
|
2013-06-04 23:44:17 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-06-18 15:39:16 -07:00
|
|
|
# Emit mutations
|
2013-06-04 23:44:17 +02:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def dispatch
|
|
|
|
emit_name_mutation
|
|
|
|
emit_required_mutation
|
|
|
|
emit_default_mutations
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit required mutation
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
def emit_required_mutation
|
2016-04-05 01:17:45 -07:00
|
|
|
emit(s(TYPE_MAP.fetch(node.type), name))
|
2013-06-04 23:44:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end # Optional
|
|
|
|
|
|
|
|
end # Argument
|
|
|
|
end # Node
|
|
|
|
end # Mutator
|
|
|
|
end # Mutant
|