Muex.Mutator behaviour (Muex v0.3.3)
View SourceBehaviour for mutation operators that transform AST nodes.
Mutators implement specific mutation strategies (e.g., arithmetic operators, boolean operators, literals) and return a list of possible mutations for a given AST.
Each mutator is language-agnostic and works with the raw AST structure provided by the language adapter.
Example
defmodule Muex.Mutator.MyMutator do
@behaviour Muex.Mutator
@impl true
def mutate(ast, _context) do
# Return list of mutated AST variants
[mutated_ast_1, mutated_ast_2]
end
@impl true
def name, do: "My Mutator"
@impl true
def description, do: "Mutates specific AST patterns"
end
Summary
Types
Represents a single mutation with its metadata.
Callbacks
Returns a description of what this mutator does.
Applies mutations to the given AST.
Returns the name of the mutator.
Functions
Walks through an AST and applies all registered mutators.
Types
@type mutation() :: %{ ast: term(), mutator: module(), description: String.t(), location: %{file: String.t(), line: non_neg_integer()} }
Represents a single mutation with its metadata.
Callbacks
@callback description() :: String.t()
Returns a description of what this mutator does.
Returns
String describing the mutation strategy
Applies mutations to the given AST.
Parameters
ast- The AST to mutatecontext- Map containing additional context (file path, line number, etc.)
Returns
List of mutation maps, each representing a possible mutation
@callback name() :: String.t()
Returns the name of the mutator.
Returns
String name identifying this mutator