require File.join(File.dirname(__FILE__), *%w[helper]) context "Markup" do setup do @path = testpath("examples/test.git") FileUtils.rm_rf(@path) Grit::Repo.init_bare(@path) @wiki = Gollum::Wiki.new(@path) @commit = { :message => "Add stuff", :name => "Tom Preston-Werner", :email => "tom@github.com" } end teardown do FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git])) end test "page link" do @wiki.write_page("Bilbo Baggins", :markdown, "a [[Bilbo Baggins]] b", @commit) page = @wiki.page("Bilbo Baggins") output = Gollum::Markup.new(page).render assert_equal %{
a Bilbo Baggins b
}, output end test "absent page link" do @wiki.write_page("Tolkien", :markdown, "a [[J. R. R. Tolkien]]'s b", @commit) page = @wiki.page("Tolkien") output = Gollum::Markup.new(page).render assert_equal %{a J. R. R. Tolkien's b
}, output end test "page link with custom base path" do ["/wiki", "/wiki/"].each do |path| @wiki = Gollum::Wiki.new(@path, :base_path => path) @wiki.write_page("Bilbo Baggins", :markdown, "a [[Bilbo Baggins]] b", @commit) page = @wiki.page("Bilbo Baggins") output = Gollum::Markup.new(page).render assert_equal %{a Bilbo Baggins b
}, output end end test "image with http url" do ['http', 'https'].each do |scheme| @wiki.write_page("Bilbo Baggins", :markdown, "a [[#{scheme}://example.com/bilbo.jpg]] b", @commit) page = @wiki.page("Bilbo Baggins") output = Gollum::Markup.new(page).render assert_equal %{a
b
a
b
a
b
a
b
a
b
a
b
a
b
a
b
a
\n\n
b
" relative_image(content, output) end test "image with float and align" do %w{left right}.each do |align| content = "a\n\n[[alpha.jpg|float|align=#{align}]]\n\nb" output = "a
\n\n
b
" relative_image(content, output) end end test "image with frame" do content = "a\n\n[[alpha.jpg|frame]]\n\nb" output = "a
\n\n
b
" relative_image(content, output) end test "image with frame and alt" do content = "a\n\n[[alpha.jpg|frame|alt=Alpha]]\n\nb" output = "a
\n\n
Alpha
b
" relative_image(content, output) end test "file link with absolute path" do index = @wiki.repo.index index.add("alpha.jpg", "hi") index.commit("Add alpha.jpg") @wiki.write_page("Bilbo Baggins", :markdown, "a [[Alpha|/alpha.jpg]] b", @commit) page = @wiki.page("Bilbo Baggins") output = Gollum::Markup.new(page).render assert_equal %{a Alpha b
}, output end test "file link with relative path" do index = @wiki.repo.index index.add("greek/alpha.jpg", "hi") index.add("greek/Bilbo-Baggins.md", "a [[Alpha|alpha.jpg]] b") index.commit("Add alpha.jpg") page = @wiki.page("Bilbo Baggins") output = Gollum::Markup.new(page).render assert_equal %{a Alpha b
}, output end test "code blocks" do content = "a\n\n```ruby\nx = 1\n```\n\nb" output = "a
\n\n" +
"x = " +
"1\n\nb
" index = @wiki.repo.index index.add("Bilbo-Baggins.md", content) index.commit("Add alpha.jpg") page = @wiki.page("Bilbo Baggins") rendered = Gollum::Markup.new(page).render assert_equal output, rendered end test "code blocks with carriage returns" do content = "a\r\n\r\n```ruby\r\nx = 1\r\n```\r\n\r\nb" output = "a
\n\n" +
"x = " +
"1\n\nb
" index = @wiki.repo.index index.add("Bilbo-Baggins.md", content) index.commit("Add alpha.jpg") page = @wiki.page("Bilbo Baggins") rendered = Gollum::Markup.new(page).render assert_equal output, rendered end test "escaped wiki link" do content = "a '[[Foo]], b" output = "a [[Foo]], b
" compare(content, output) end test "quoted wiki link" do content = "a '[[Foo]]', b" output = "a 'Foo', b
" compare(content, output) end test "org mode style double links" do content = "a [[http://google.com][Google]] b" output = "a Google b
" compare(content, output, 'org') end def compare(content, output, ext = "md") index = @wiki.repo.index index.add("Bilbo-Baggins.#{ext}", content) index.commit("Add baggins") page = @wiki.page("Bilbo Baggins") rendered = Gollum::Markup.new(page).render assert_equal output, rendered end def relative_image(content, output) index = @wiki.repo.index index.add("greek/alpha.jpg", "hi") index.add("greek/Bilbo-Baggins.md", content) index.commit("Add alpha.jpg") page = @wiki.page("Bilbo Baggins") rendered = Gollum::Markup.new(page).render assert_equal output, rendered end end