<commit_before>defmodule AtomStyleTweaks.MarkdownEngine.Test do
  use ExUnit.Case, async: true

  alias AtomStyleTweaks.MarkdownEngine

  setup do
    github = fn match, _ ->
      if match =~ ~r/@github/ || match =~ ~r/@both/ do
        "github-replacement"
      end
    end

    tweaks = fn match, _ ->
      if match =~ ~r/@tweaks/ || match =~ ~r/@both/ do
        "tweaks-replacement"
      end
    end

    [funcs: [tweaks, github]]
  end

  test "when render is given nil it renders an empty string" do
    assert MarkdownEngine.render(nil) == ""
  end

  test "when render is given an empty string it renders an empty string" do
    assert MarkdownEngine.render("") == ""
  end

  test "when render is given some text it renders the text into HTML" do
    assert MarkdownEngine.render("test") == "<p>test</p>\n"
  end

  test "when replace_mention is given nil it returns nil", context do
    assert MarkdownEngine.replace_mention(nil, context[:funcs]) == nil
  end

  test "when replace_mention is given an empty string it returns an empty string", context do
    assert MarkdownEngine.replace_mention("", context[:funcs]) == ""
  end

  test "when replace_mention is given text with no mentions, it returns the text unchanged", context do
    assert MarkdownEngine.replace_mention("This text has no mentions", context[:funcs]) == "This text has no mentions"
  end

  test "when replace_mention is given text with a mention that is handled by a function, the mention is replaced", context do
    assert MarkdownEngine.replace_mention("This text has a @tweaks-mention in it", context[:funcs]) == "This text has a tweaks-replacement in it"
  end

  test "when replace_mention is given text with a mention that is handled by any function, the mention is replaced", context do
    assert MarkdownEngine.replace_mention("This text has a @github-mention in it", context[:funcs]) == "This text has a github-replacement in it"
  end

  test "when replace_mention is given text with a mention that is handled by multiple functions, the mention is replaced by the earliest one", context do
    assert MarkdownEngine.replace_mention("This text has a @both-mention in it", context[:funcs]) == "This text has a tweaks-replacement in it"
  end
end<commit_msg>Ensure only the first successful function is called<commit_after>defmodule AtomStyleTweaks.MarkdownEngine.Test do
  use ExUnit.Case, async: true

  alias AtomStyleTweaks.MarkdownEngine

  setup do
    github = fn match, _ ->
      if match =~ ~r/@github/ || match =~ ~r/@both/ do
        "github-replacement"
      end
    end

    tweaks = fn match, _ ->
      if match =~ ~r/@tweaks/ || match =~ ~r/@both/ do
        "tweaks-replacement"
      end
    end

    [funcs: [tweaks, github], tweaks: tweaks]
  end

  test "when render is given nil it renders an empty string" do
    assert MarkdownEngine.render(nil) == ""
  end

  test "when render is given an empty string it renders an empty string" do
    assert MarkdownEngine.render("") == ""
  end

  test "when render is given some text it renders the text into HTML" do
    assert MarkdownEngine.render("test") == "<p>test</p>\n"
  end

  test "when replace_mention is given nil it returns nil", context do
    assert MarkdownEngine.replace_mention(nil, context[:funcs]) == nil
  end

  test "when replace_mention is given an empty string it returns an empty string", context do
    assert MarkdownEngine.replace_mention("", context[:funcs]) == ""
  end

  test "when replace_mention is given text with no mentions, it returns the text unchanged", context do
    assert MarkdownEngine.replace_mention("This text has no mentions", context[:funcs]) == "This text has no mentions"
  end

  test "when replace_mention is given text with a mention that is handled by a function, the mention is replaced", context do
    assert MarkdownEngine.replace_mention("This text has a @tweaks-mention in it", context[:funcs]) == "This text has a tweaks-replacement in it"
  end

  test "when replace_mention is given text with a mention that is handled by any function, the mention is replaced", context do
    assert MarkdownEngine.replace_mention("This text has a @github-mention in it", context[:funcs]) == "This text has a github-replacement in it"
  end

  test "when replace_mention is given text with a mention that is handled by multiple functions, the mention is replaced by the earliest one", context do
    assert MarkdownEngine.replace_mention("This text has a @both-mention in it", context[:funcs]) == "This text has a tweaks-replacement in it"
  end

  test "when replace_mention is given text with a mention, that not all functions are called if an earlier one succeeds", context do
    assert MarkdownEngine.replace_mention("This text has a @tweaks-mention in it", [context[:tweaks], fn(_, _) -> raise "bummer" end]) == "This text has a tweaks-replacement in it"
  end
end
{'fraction_non_alphanumeric': 0.08806061847225066, 'fraction_numerical': 0.0, 'mean_word_length': 3.737148399612027, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '2867128', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1398, 'n_words': 595}