Assay.Formatter.Helpers (assay v0.6.0)

Copy Markdown View Source

Formatter-agnostic helpers used across warning renderers to normalize Erlang terms and render rich diffs.

Summary

Functions

Wraps text with ANSI color codes when enabled? is true.

Computes a +/- diff between two lists of strings, highlighting only the differing segments while keeping delimiters balanced.

Converts Erlang-ish term output into Elixir-friendly string lines.

Functions

colorize(text, color, arg3)

Wraps text with ANSI color codes when enabled? is true.

diff_lines(expected_lines, actual_lines, opts)

Computes a +/- diff between two lists of strings, highlighting only the differing segments while keeping delimiters balanced.

Returns a flat list of formatted lines (already prefixed with - or +).

Examples

iex> result = Assay.Formatter.Helpers.diff_lines(["(atom())"], ["(binary())"], color?: false)
iex> List.flatten(result)
["-  (atom())", "+  (binary())"]

format_term_lines(value)

Converts Erlang-ish term output into Elixir-friendly string lines.

Printable binaries are stringified.

Examples

iex> Assay.Formatter.Helpers.format_term_lines("%{title => <<116,105,116,108,101>>}")
["%{title => \"title\"}"]