Class: Evilution::Mutator::Base
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- Evilution::Mutator::Base
show all
- Defined in:
- lib/evilution/mutator/base.rb
Direct Known Subclasses
Operator::ArgumentNilSubstitution, Operator::ArgumentRemoval, Operator::ArithmeticReplacement, Operator::ArrayLiteral, Operator::BangMethod, Operator::BeginUnwrap, Operator::BitwiseComplement, Operator::BitwiseReplacement, Operator::BlockParamRemoval, Operator::BlockPassRemoval, Operator::BlockRemoval, Operator::BooleanLiteralReplacement, Operator::BooleanOperatorReplacement, Operator::BreakStatement, Operator::CaseWhen, Operator::ClassVariableWrite, Operator::CollectionReplacement, Operator::CollectionReturn, Operator::ComparisonReplacement, Operator::CompoundAssignment, Operator::ConditionalBranch, Operator::ConditionalFlip, Operator::ConditionalNegation, Operator::DefinedCheck, Operator::EnsureRemoval, Operator::EqualityToIdentity, Operator::ExplicitSuperMutation, Operator::FloatLiteral, Operator::GlobalVariableWrite, Operator::HashLiteral, Operator::IndexAssignmentRemoval, Operator::IndexToAt, Operator::IndexToDig, Operator::IndexToFetch, Operator::InlineRescue, Operator::InstanceVariableWrite, Operator::IntegerLiteral, Operator::KeywordArgument, Operator::LambdaBody, Operator::LocalVariableAssignment, Operator::LoopFlip, Operator::MethodBodyReplacement, Operator::MethodCallRemoval, Operator::MixinRemoval, Operator::MultipleAssignment, Operator::NegationInsertion, Operator::NextStatement, Operator::NilReplacement, Operator::PatternMatchingAlternative, Operator::PatternMatchingArray, Operator::PatternMatchingGuard, Operator::PredicateReplacement, Operator::RangeReplacement, Operator::ReceiverReplacement, Operator::RedoStatement, Operator::RegexCapture, Operator::RegexSimplification, Operator::RegexpMutation, Operator::RescueBodyReplacement, Operator::RescueRemoval, Operator::RetryRemoval, Operator::ReturnValueRemoval, Operator::ScalarReturn, Operator::SendMutation, Operator::SplatOperator, Operator::StatementDeletion, Operator::StringInterpolation, Operator::StringLiteral, Operator::SuperclassRemoval, Operator::SymbolLiteral, Operator::YieldStatement, Operator::ZsuperRemoval
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(**_options) ⇒ Base
Returns a new instance of Base.
10
11
12
13
14
|
# File 'lib/evilution/mutator/base.rb', line 10
def initialize(**_options)
@mutations = []
@subject = nil
@file_source = nil
end
|
Instance Attribute Details
#mutations ⇒ Object
Returns the value of attribute mutations.
8
9
10
|
# File 'lib/evilution/mutator/base.rb', line 8
def mutations
@mutations
end
|
Class Method Details
.clear_parse_cache! ⇒ Object
72
73
74
|
# File 'lib/evilution/mutator/base.rb', line 72
def self.clear_parse_cache!
Evilution::Mutator::Base.instance_variable_set(:@parse_cache, {})
end
|
.operator_name ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/evilution/mutator/base.rb', line 52
def self.operator_name
class_name = name || "anonymous"
class_name.split("::").last
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
.downcase
end
|
.parsed_tree_for(file_path, file_source) ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/evilution/mutator/base.rb', line 62
def self.parsed_tree_for(file_path, file_source)
cache = Evilution::Mutator::Base.instance_variable_get(:@parse_cache)
entry = cache[file_path]
return entry[:tree] if entry && entry[:source_hash] == file_source.hash
tree = Prism.parse(file_source).value
cache[file_path] = { source_hash: file_source.hash, tree: tree }
tree
end
|
Instance Method Details
#call(subject, filter: nil) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/evilution/mutator/base.rb', line 16
def call(subject, filter: nil)
@subject = subject
@file_source = File.read(subject.file_path)
@mutations = []
@filter = filter
visit(subject.node)
@mutations
end
|