# coding: utf-8 require 'helper' class TestTags < Test::Unit::TestCase def create_post(content, override = {}, converter_class = Jekyll::Converters::Markdown) stub(Jekyll).configuration do Jekyll::Configuration::DEFAULTS.deep_merge({'pygments' => true}).deep_merge(override) end site = Site.new(Jekyll.configuration) if override['read_posts'] site.read_posts('') end info = { :filters => [Jekyll::Filters], :registers => { :site => site } } @converter = site.converters.find { |c| c.class == converter_class } payload = { "pygments_prefix" => @converter.pygments_prefix, "pygments_suffix" => @converter.pygments_suffix } @result = Liquid::Template.parse(content).render(payload, info) @result = @converter.convert(@result) end def fill_post(code, override = {}) content = < 'inline' }, tag.instance_variable_get(:@options)) tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table ', ["test", "{% endhighlight %}", "\n"]) assert_equal({ 'linenos' => 'table' }, tag.instance_variable_get(:@options)) tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table nowrap', ["test", "{% endhighlight %}", "\n"]) assert_equal({ 'linenos' => 'table', 'nowrap' => true }, tag.instance_variable_get(:@options)) tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl', ["test", "{% endhighlight %}", "\n"]) assert_equal({ 'cssclass' => 'hl', 'linenos' => 'table' }, tag.instance_variable_get(:@options)) end end context "post content has highlight tag" do setup do fill_post("test") end should "not cause a markdown error" do assert_no_match /markdown\-html\-error/, @result end should "render markdown with pygments" do assert_match %{
test\n
}, @result end should "render markdown with pygments with line numbers" do assert_match %{
1 test\n
}, @result end end context "post content has highlight with file reference" do setup do fill_post("./jekyll.gemspec") end should "not embed the file" do assert_match %{
./jekyll.gemspec\n
}, @result end end context "post content has highlight tag with UTF character" do setup do fill_post("Æ") end should "render markdown with pygments line handling" do assert_match %{
Æ\n
}, @result end end context "simple post with markdown and pre tags" do setup do @content = <
}, @result end end context "using Maruku" do setup do create_post(@content) end should "parse correctly" do assert_match %r{FIGHT!}, @result assert_match %r{FINISH HIM}, @result end end context "using RDiscount" do setup do create_post(@content, 'markdown' => 'rdiscount') end should "parse correctly" do assert_match %r{FIGHT!}, @result assert_match %r{FINISH HIM}, @result end end context "using Kramdown" do setup do create_post(@content, 'markdown' => 'kramdown') end should "parse correctly" do assert_match %r{FIGHT!}, @result assert_match %r{FINISH HIM}, @result end end context "using Redcarpet" do setup do create_post(@content, 'markdown' => 'redcarpet') end should "parse correctly" do assert_match %r{FIGHT!}, @result assert_match %r{FINISH HIM}, @result end end end context "simple page with post linking" do setup do content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end should "not cause an error" do assert_no_match /markdown\-html\-error/, @result end should "have the url to the \"complex\" post from 2008-11-21" do assert_match %r{/2008/11/21/complex/}, @result end end context "simple page with nested post linking" do setup do content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end should "not cause an error" do assert_no_match /markdown\-html\-error/, @result end should "have the url to the \"nested\" post from 2008-11-21" do assert_match %r{1\s/2008/11/21/complex/}, @result assert_match %r{2\s/2008/11/21/complex/}, @result end should "have the url to the \"nested\" post from 2008-11-21" do assert_match %r{3\s/2008/11/21/nested/}, @result assert_match %r{4\s/2008/11/21/nested/}, @result end end context "gist tag" do context "simple" do setup do @gist = 358471 content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end should "write script tag" do assert_match "", @result end end context "for private gist" do context "when valid" do setup do @gist = "mattr-/24081a1d93d2898ecf0f" @filename = "myfile.ext" content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end should "write script tag with specific file in gist" do assert_match "", @result end end context "when invalid" do setup do @gist = "mattr-24081a1d93d2898ecf0f" @filename = "myfile.ext" content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end should "write script tag with specific file in gist" do assert_match "Error parsing gist id", @result end end end context "with specific file" do setup do @gist = 358471 @filename = 'somefile.rb' content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end should "write script tag with specific file in gist" do assert_match "", @result end end context "with blank gist id" do setup do content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end should "output error message" do assert_match "Error parsing gist id", @result end end context "with invalid gist id" do setup do invalid_gist = 'invalid' content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end should "output error message" do assert_match "Error parsing gist id", @result end end end context "include tag with parameters" do context "with one parameter" do setup do content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end should "correctly output include variable" do assert_match "value", @result.strip end should "ignore parameters if unused" do assert_match "
\n

Tom Preston-Werner github.com/mojombo

\n", @result end end context "with invalid parameter syntax" do should "throw a SyntaxError" do content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end end end context "with several parameters" do setup do content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end should "list all parameters" do assert_match '
  • param1 = new_value
  • ', @result assert_match '
  • param2 = another
  • ', @result end should "not include previously used parameters" do assert_match "", @result end end context "without parameters" do setup do content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end should "include file with empty parameters" do assert_match "", @result end end end end