mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-24 14:32:25 -05:00
ed6e2b1d79
http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony - Thanks @riking for finding it.
51 lines
1.3 KiB
Text
51 lines
1.3 KiB
Text
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(/"/g, '"');
|
|
}
|
|
|
|
var md = function(input, expected, text) {
|
|
var result = Discourse.Markdown.cook(input, {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 %>
|