# coding: UTF-8 rootdir = File.dirname(File.dirname(__FILE__)) $LOAD_PATH.unshift "#{rootdir}/lib" if defined? Encoding Encoding.default_internal = 'UTF-8' end require 'test/unit' require 'github/markdown' require 'nokogiri' def html_equal(html_a, html_b) assert_equal Nokogiri::HTML::DocumentFragment.parse(html_a).to_html, Nokogiri::HTML::DocumentFragment.parse(html_b).to_html end class GFMBasicTest < Test::Unit::TestCase Dir['test/fixtures/*.text', 'test/fixtures/Markdown_Redcarpet/**/*.text'].each do |md_file| dirname = File.dirname(md_file) markup = md_file.split('/').last.gsub(/\.text/, '').gsub(/(\s+)/, "_") define_method "test_#{dirname}_#{markup}" do source = File.read(md_file) expected_file = "#{dirname}/#{markup}.html" expected = File.read(expected_file).rstrip actual = GitHub::Markdown.render(source).rstrip if source != expected assert(source != actual, "#{markup} did not render anything") end diff = IO.popen("diff -u - #{expected_file}", 'r+') do |f| f.write actual f.close_write f.read end assert expected == actual, <