#!/bin/env ruby -w require File.dirname(__FILE__) + '/../test_helper' require 'web' require 'revision' class WebStub < Web def initialize(); end attr_accessor :markup def pages() PagesStub.new end def safe_mode() false end end class PagesStub def [](wiki_word) %w( MyWay ThatWay SmartEngine ).include?(wiki_word) end end class PageStub attr_accessor :web, :revisions def name() 'page' end end class RevisionTest < Test::Unit::TestCase def setup @web = WebStub.new @web.markup = :textile @page = PageStub.new @page.web = @web @revision = Revision.new(@page, 1, 'HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- ' + 'see SmartEngine in that SmartEngineGUI', Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson') end def test_wiki_words assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ), @revision.wiki_words.sort end def test_existing_pages assert_equal %w( MyWay SmartEngine ThatWay ), @revision.existing_pages.sort end def test_unexisting_pages assert_equal %w( HisWay SmartEngineGUI ), @revision.unexisting_pages.sort end def test_content_with_wiki_links assert_equal '

His Way? ' + 'would be My Way in kinda ' + 'That Way in ' + 'His Way? ' + 'though My Way OverThere—see ' + 'Smart Engine in that ' + 'Smart Engine GUI' + '?

', @revision.display_content end def test_bluecloth @web.markup = :markdown assert_markup_parsed_as( %{

My Headline

\n\n

that } + %{Smart Engine GUI?

}, "My Headline\n===========\n\n that SmartEngineGUI") code_block = [ 'This is a code block:', '', ' def a_method(arg)', ' return ThatWay', '', 'Nice!' ].join("\n") assert_markup_parsed_as( %{

This is a code block:

\n\n
def a_method(arg)\n} +
	    %{return ThatWay\n
\n\n

Nice!

}, code_block) end def test_rdoc @web.markup = :rdoc @revision = Revision.new(@page, 1, '+hello+ that SmartEngineGUI', Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson') assert_equal "hello that Smart Engine GUI" + "?\n\n", @revision.display_content end def test_content_with_auto_links assert_markup_parsed_as( '

http://www.loudthinking.com/ ' + 'points to That Way from ' + 'david@loudthinking.com

', 'http://www.loudthinking.com/ points to ThatWay from david@loudthinking.com') end def test_content_with_aliased_links assert_markup_parsed_as( '

Would a clever motor' + ' go by any other name?

', 'Would a [[SmartEngine|clever motor]] go by any other name?') end def test_content_with_wikiword_in_em assert_markup_parsed_as( '

should we go ' + 'That Way or This Way?' + '

', '_should we go ThatWay or ThisWay _') end def test_content_with_wikiword_in_tag assert_markup_parsed_as( '

That is some Stylish Emphasis

', 'That is some Stylish Emphasis') end def test_content_with_pre_blocks assert_markup_parsed_as( 'A class SmartEngine end would not mark up
CodeBlocks
', 'A class SmartEngine end would not mark up
CodeBlocks
') end def test_content_with_autolink_in_parentheses assert_markup_parsed_as( '

The W3C body (' + 'http://www.w3c.org) sets web standards

', 'The W3C body (http://www.w3c.org) sets web standards') end def test_content_with_link_in_parentheses assert_markup_parsed_as( '

(What is a wiki?)

', '("What is a wiki?":http://wiki.org/wiki.cgi?WhatIsWiki)') end def test_content_with_image_link assert_markup_parsed_as( '

This is a Textile image link.

', 'This !http://hobix.com/sample.jpg! is a Textile image link.') end def test_content_with_nowiki_text assert_markup_parsed_as( '

Do not mark up [[this text]] or http://www.thislink.com.

', 'Do not mark up [[this text]] ' + 'or http://www.thislink.com.') end def test_content_with_bracketted_wiki_word @web.brackets_only = true assert_markup_parsed_as( '

This is a WikiWord and a tricky name ' + 'Sperberg-McQueen?.

', 'This is a WikiWord and a tricky name [[Sperberg-McQueen]].') end def test_content_for_export assert_equal '

His Way would be ' + 'My Way in kinda ' + 'That Way in ' + 'His Way though ' + 'My Way OverThere—see ' + 'Smart Engine in that ' + 'Smart Engine GUI

', @revision.display_content_for_export end def test_double_replacing @revision.content = "VersionHistory\r\n\r\ncry VersionHistory" assert_equal '

Version History' + "?

\n\n\t

cry " + 'Version History?' + '

', @revision.display_content @revision.clear_display_cache @revision.content = "f\r\nVersionHistory\r\n\r\ncry VersionHistory" assert_equal "

f
\nVersion History" + "?

\n\n\t

cry " + "Version History?" + "

", @revision.display_content end def test_difficult_wiki_words @revision.content = "[[It's just awesome GUI!]]" assert_equal "

It’s just awesome GUI" + "!?

", @revision.display_content end def test_revisions_diff @page.revisions = [ Revision.new(@page, 0, 'What a blue and lovely morning', Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson'), Revision.new(@page, 1, 'What a red and lovely morning today', Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson') ] assert_equal "

What a blue red " + "and lovely morningmorning " + "today

", @page.revisions.last.display_diff end def test_link_to_file assert_markup_parsed_as( '

doc.pdf?

', '[[doc.pdf:file]]') end def test_link_to_pic assert_markup_parsed_as( '

Square?

', '[[square.jpg|Square:pic]]') end # TODO Remove the leading underscores from this test when upgrading to RedCloth 3.0.1; # also add a test for the "Unhappy Face" problem (another interesting RedCloth bug) def __test_list_with_tildas list_with_tildas = <<-EOL * "a":~b * c~ d EOL assert_markup_parsed_as( "
  • a
  • \n" + "
  • c~ d
  • \n", list_with_tildas) end def assert_markup_parsed_as(expected_output, input) revision = Revision.new(@page, 1, input, Time.local(2004, 4, 4, 16, 50), 'AnAuthor') assert_equal expected_output, revision.display_content, 'Textile output not as expected' end end