test/test_conversions.rb in pandoc-ruby-1.0.0 vs test/test_conversions.rb in pandoc-ruby-2.0.0

- old
+ new

@@ -1,67 +1,30 @@ require 'helper' -class TestConversions < Test::Unit::TestCase - - def self.formatted_strings - h = Hash.new - h[:native] = - %Q|[Header 1 (\"this-is-a-title\",[],[]) [Str \"This\",Space,Str \"is\",Space,Str \"a\",Space,Str \"Title\"]\n,Para [Str \"Some\",Space,Emph [Str \"emphasized\",Space,Str \"text\"],Space,Str \"and\",Space,Link [Str \"a\",Space,Str \"link\"] (\"http://daringfireball.net/projects/markdown/\",\"\")]]| - h[:json] = - %Q|[{"unMeta":{}},[{"t":"Header","c":[1,["this-is-a-title",[],[]],[{"t":"Str","c":"This"},{"t":"Space","c":[]},{"t":"Str","c":"is"},{"t":"Space","c":[]},{"t":"Str","c":"a"},{"t":"Space","c":[]},{"t":"Str","c":"Title"}]]},{"t":"Para","c":[{"t":"Str","c":"Some"},{"t":"Space","c":[]},{"t":"Emph","c":[{"t":"Str","c":"emphasized"},{"t":"Space","c":[]},{"t":"Str","c":"text"}]},{"t":"Space","c":[]},{"t":"Str","c":"and"},{"t":"Space","c":[]},{"t":"Link","c":[[{"t":"Str","c":"a"},{"t":"Space","c":[]},{"t":"Str","c":"link"}],["http://daringfireball.net/projects/markdown/",""]]}]}]]| - h[:html] = - %Q|<h1 id=\"this-is-a-title\">This is a Title</h1>\n<p>Some <em>emphasized text</em> and <a href=\"http://daringfireball.net/projects/markdown/\">a link</a></p>| - h[:html5] = - %Q|<h1 id=\"this-is-a-title\">This is a Title</h1>\n<p>Some <em>emphasized text</em> and <a href=\"http://daringfireball.net/projects/markdown/\">a link</a></p>| - h[:s5] = - %Q|<div id=\"this-is-a-title\" class=\"slide section level1\">\n<h1>This is a Title</h1>\n<p>Some <em>emphasized text</em> and <a href=\"http://daringfireball.net/projects/markdown/\">a link</a></p>\n</div>| - h[:slidy] = - %Q|<div id=\"this-is-a-title\" class=\"slide section level1\">\n<h1>This is a Title</h1>\n<p>Some <em>emphasized text</em> and <a href=\"http://daringfireball.net/projects/markdown/\">a link</a></p>\n</div>| - h[:dzslides] = - %Q|<section id=\"this-is-a-title\" class=\"slide level1\">\n<h1>This is a Title</h1>\n<p>Some <em>emphasized text</em> and <a href=\"http://daringfireball.net/projects/markdown/\">a link</a></p>\n</section>| - h[:docbook] = - %Q|<sect1 id=\"this-is-a-title\">\n <title>This is a Title</title>\n <para>\n Some <emphasis>emphasized text</emphasis> and\n <ulink url=\"http://daringfireball.net/projects/markdown/\">a\n link</ulink>\n </para>\n</sect1>| - h[:opendocument] = - %Q|<text:h text:style-name=\"Heading_20_1\" text:outline-level=\"1\">This is a\nTitle</text:h>\n<text:p text:style-name=\"First_20_paragraph\">Some\n<text:span text:style-name=\"T1\">emphasized</text:span><text:span text:style-name=\"T2\">\n</text:span><text:span text:style-name=\"T3\">text</text:span> and\n<text:a xlink:type=\"simple\" xlink:href=\"http://daringfireball.net/projects/markdown/\" office:name=\"\"><text:span text:style-name=\"Definition\">a\nlink</text:span></text:a></text:p>| - h[:latex] = - %Q|\\section{This is a Title}\\label{this-is-a-title}\n\nSome \\emph{emphasized text} and\n\\href{http://daringfireball.net/projects/markdown/}{a link}| - h[:beamer] = - %Q|\\begin{frame}{This is a Title}\n\nSome \\emph{emphasized text} and\n\\href{http://daringfireball.net/projects/markdown/}{a link}\n\n\\end{frame}| - h[:context] = - %Q|\\section[this-is-a-title]{This is a Title}\n\nSome {\\em emphasized text} and\n\\useURL[url1][http://daringfireball.net/projects/markdown/][][a\nlink]\\from[url1]| - h[:texinfo] = - %Q|@node Top\n@top Top\n\n@menu\n* This is a Title::\n@end menu\n\n@node This is a Title\n@chapter This is a Title\n@anchor{#this-is-a-title}\nSome @emph{emphasized text} and @uref{http://daringfireball.net/projects/markdown/,a link}| - h[:man] = - %Q|.SH This is a Title\n.PP\nSome \\f[I]emphasized text\\f[] and a\nlink (http://daringfireball.net/projects/markdown/)| - h[:markdown] = - %Q|This is a Title\n===============\n\nSome *emphasized text* and [a\nlink](http://daringfireball.net/projects/markdown/)| - h[:plain] = - %Q|THIS IS A TITLE\n\n\nSome _emphasized text_ and a link| - h[:rst] = - %Q|This is a Title\n===============\n\nSome *emphasized text* and `a\nlink <http://daringfireball.net/projects/markdown/>`__| - h[:mediawiki] = - %Q|= This is a Title =\n\nSome ''emphasized text'' and [http://daringfireball.net/projects/markdown/ a link]| - h[:textile] = - %Q|h1(#this-is-a-title). This is a Title\n\nSome _emphasized text_ and \"a link\":http://daringfireball.net/projects/markdown/| - h[:rtf] = - %Q|{\\pard \\ql \\f0 \\sa180 \\li0 \\fi0 \\b \\fs36 This is a Title\\par}\n{\\pard \\ql \\f0 \\sa180 \\li0 \\fi0 Some {\\i emphasized text} and {\\field{\\*\\fldinst{HYPERLINK \"http://daringfireball.net/projects/markdown/\"}}{\\fldrslt{\\ul\na link\n}}}\n\\par}| - h[:org] = - %Q|* This is a Title\n\nSome /emphasized text/ and\n[[http://daringfireball.net/projects/markdown/][a link]]| - h[:asciidoc] = - %Q|[[this-is-a-title]]\nThis is a Title\n---------------\n\nSome _emphasized text_ and\nhttp://daringfireball.net/projects/markdown/[a link]| - return h +# Generate tests for converting to and from various formats. Use two nested +# loops to iterate over each source and destination format, using files with +# names of the following structure: "format.#{format_name}" +describe 'Conversions' do + @extensions = [] + Dir.glob(File.join(File.dirname(__FILE__), 'files', 'format*')) do |f| + @extensions << f.match(/format\.(\w+)\Z/)[1] end [:markdown, :html, :rst, :latex].each do |from| - formatted_strings.each_key do |format| - unless from == format - should "convert #{from} to #{format}" do - assert_equal( - PandocRuby.convert(TestConversions.formatted_strings[from], :from => from, :to => format).strip, - TestConversions.formatted_strings[format] - ) - end + @extensions.each do |to| + next if from == to + + it "converts #{from} to #{to}" do + files_dir = File.join(File.dirname(__FILE__), 'files') + from_content = File.read(File.join(files_dir, "format.#{from}")) + to_content = File.read(File.join(files_dir, "format.#{to}")) + + converted_content = PandocRuby.convert( + from_content, + :from => from, + :to => to + ) + assert_equal(converted_content.strip, to_content.strip) end end end - end