Juggernaut.Diff (Juggernaut v0.4.0)

Copy Markdown View Source

Where a site is in the original text, and the mutant as a patch of that text (design notes §6, docs/dependencies/sourceror.md).

The diff is never rendered output compared with the raw file: the original lines are patched over the site's range with the rendered replacement, so everything outside the site keeps its spelling.

Three of Sourceror's range defects are corrected here:

  • a node written in parentheses is ranged over them; its replacement is wrapped in parentheses too, so the patch keeps them;
  • a string or sigil with an escaped delimiter is ranged one column short per escape; its end is found by scanning the original text;
  • an operator whose last operand is a multi-line string, charlist or sigil is ranged past that operand; it ends where the operand ends.

A replacement starting with a sign that would follow a sign in the text (the literal under a unary minus) is written in parentheses (separate_sign/3).

The fourth defect (an anonymous call such as (fn x -> x end).(1) ranged from inside the callee's parentheses) is not corrected: such sites keep Sourceror's range.

Summary

Functions

lines with range replaced by text (later lines re-indented as the first).

The corrected range of node in lines (the file split on newlines), or :error.

The replacement text for node's range: rendered, wrapped in parentheses when the range includes parentheses written around the node.

text in parentheses when it starts with a sign and the character just before range is one: the literal under -0.05 is 0.05, and its replacement -0.95 written there would read --0.95, which does not parse. -(-0.95) is the mutant.

The text of lines over range.

A unified diff of one hunk: the lines range covers, before and after text replaces it. @@ -L +L @@ when one line is replaced by one.

Types

position()

@type position() :: {pos_integer(), pos_integer()}

range()

@type range() :: %{start: position(), end: position()}

Functions

patch(lines, range, text)

@spec patch([String.t()], range(), String.t()) :: [String.t()]

lines with range replaced by text (later lines re-indented as the first).

range(node, lines)

@spec range(Macro.t(), [String.t()]) :: {:ok, range()} | :error

The corrected range of node in lines (the file split on newlines), or :error.

replacement_text(arg1, original, rendered)

@spec replacement_text(Macro.t(), String.t(), String.t()) :: String.t()

The replacement text for node's range: rendered, wrapped in parentheses when the range includes parentheses written around the node.

separate_sign(text, lines, arg3)

@spec separate_sign(String.t(), [String.t()], range()) :: String.t()

text in parentheses when it starts with a sign and the character just before range is one: the literal under -0.05 is 0.05, and its replacement -0.95 written there would read --0.95, which does not parse. -(-0.95) is the mutant.

slice(lines, map)

@spec slice([String.t()], range()) :: String.t()

The text of lines over range.

unified(lines, range, text)

@spec unified([String.t()], range(), String.t()) :: String.t()

A unified diff of one hunk: the lines range covers, before and after text replaces it. @@ -L +L @@ when one line is replaced by one.