<commit_before>module("MDTest", {
  setup: function() {
    Discourse.SiteSettings.traditional_markdown_linebreaks = false;
  }
});

// This is cheating, but the trivial differences between sanitization
// do not affect formatting.
function normalize(str) {
  return str.replace(/\n\s*/g, '').
             replace(/ \/\>/g, '/>').
             replace(/    ?/g, "\t").
             replace(/&#34;/g, '&quot;');
}

var md = function(input, expected, text) {
  var result = Discourse.Markdown.cook(input, {mentionLookup: false, sanitize: true, traditional_markdown_linebreaks: true}),
      resultNorm = normalize(result),
      expectedNorm = normalize(expected),
      same = (result === expected) || (resultNorm === expectedNorm);

  if (same) {
    ok(same, text);
  } else {
    console.log(resultNorm);
    console.log(expectedNorm);
    equal(resultNorm, expectedNorm, text);
  }
};

test("first", function(){
  equal(1, 1, "cool")
});

<%
  def mdtest_suite
    result = ""
    Dir.glob("#{Rails.root}/test/javascripts/mdtest/fixtures/*.text").each do |f|

      filename_no_ext = f.sub(/\.text$/, '')
      filename = Pathname.new(filename_no_ext)

      text = File.read(f)
      html = File.read("#{filename_no_ext}.xhtml");
      result << "test(\"#{filename}\", function() { md(#{text.to_json}, #{html.to_json}, 'passes MDTest'); });\n"
    end
    result
  end

%>

<%= mdtest_suite %><commit_msg>Fix the build<commit_after>module("MDTest", {
  setup: function() {
    Discourse.SiteSettings.traditional_markdown_linebreaks = false;
  }
});

// This is cheating, but the trivial differences between sanitization
// do not affect formatting.
function normalize(str) {
  return str.replace(/\n\s*/g, '').
             replace(/ \/\>/g, '/>').
             replace(/    ?/g, "\t").
             replace(/&#34;/g, '&quot;');
}

var md = function(input, expected, text) {
  var result = Discourse.Markdown.cook(input, {mentionLookup: false, sanitize: true, traditional_markdown_linebreaks: true}),
      resultNorm = normalize(result),
      expectedNorm = normalize(expected),
      same = (result === expected) || (resultNorm === expectedNorm);

  if (same) {
    ok(same, text);
  } else {
    console.log(resultNorm);
    console.log(expectedNorm);
    equal(resultNorm, expectedNorm, text);
  }
};

test("first", function(){
  equal(1, 1, "cool")
});

<%

  def mdtest_suite
    result = ""
    Dir.glob("#{Rails.root}/test/javascripts/mdtest/fixtures/*.text").each do |f|

      filename_no_ext = f.sub(/\.text$/, '')
      filename = Pathname.new(filename_no_ext)

      text = File.read(f)
      html = File.read("#{filename_no_ext}.xhtml");
      result << "test(\"#{filename}\", function() { md(#{text.to_json}, #{html.to_json}, 'passes MDTest'); });\n"
    end
    result
  end

%>

<%= mdtest_suite %>

{'fraction_non_alphanumeric': 0.18355776045357902, 'fraction_numerical': 0.002834868887313962, 'mean_word_length': 3.1332357247437774, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '915520', 'n_tokens_mistral': 962, 'n_tokens_neox': 923, 'n_words': 188}