<commit_before>defmodule ExUnit::Escaper do
  defrecord Flag, as: nil

  defimpl String::Inspect, for: Flag do
    def inspect(record),   do: record.as
    def to_binary(record), do: record.as
  end

  # Replace _ by a record that when inspected prints "_"
  def escape({ :_, _, false }) do
    quote { unquote(Flag).new(as: "_") }
  end

  def escape(expr) when is_tuple(expr) do
    list_to_tuple(escape(tuple_to_list(expr)))
  end

  def escape(expr) when is_list(expr) do
    Enum.map expr, escape(_)
  end

  def escape(expr) do
    expr
  end
end<commit_msg>Add some explanation for ExUnit::Escaper.<commit_after># In some assertions we need to show a guard clause
# in the exception message. This usually works fine
# except if the clause has a "_", which means that
# we cannot show it because evaluating it would
# generate a "unbound _" error.
#
# For such cases, we can use `ExUnit::Escaper.escape`
# to escape the expression replacing all "_" by a flag
# that when inspected returns "_".
defmodule ExUnit::Escaper do
  defrecord Flag, as: nil

  defimpl String::Inspect, for: Flag do
    def inspect(record),   do: record.as
    def to_binary(record), do: record.as
  end

  # Replace _ by a record that when inspected prints "_"
  def escape({ :_, _, false }) do
    Flag.new(as: "_")
  end

  def escape(expr) when is_tuple(expr) do
    list_to_tuple(escape(tuple_to_list(expr)))
  end

  def escape(expr) when is_list(expr) do
    Enum.map expr, escape(_)
  end

  def escape(expr) do
    expr
  end
end
{'fraction_non_alphanumeric': 0.09749670619235837, 'fraction_numerical': 0.0, 'mean_word_length': 3.617021276595745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1422013', 'n_tokens_mistral': 505, 'n_tokens_neox': 483, 'n_words': 179}