| CODENOTIFIER | HelpYou are not signed inSign in |
Project: BlueCloth
Revision: 87
Author: deveiant
Date: 01 Sep 2008 18:24:13
Diff at Trac: http://www.deveiate.org/projects/BlueCloth/changeset/87
Changes:* Checkpoint commit of MarkdownTest integration
Files:| ... | ...@@ -105,16 +105,7 @@ | |
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | Ruby version: |
| 108 | This module is Open Source Software which is Copyright (c) 2004 by The FaerieMUD | |
| 109 | Consortium. | |
| 110 | ||
| 111 | You may use, modify, and/or redistribute this software under the same terms as | |
| 112 | Ruby itself. | |
| 113 | ||
| 114 | BlueCloth is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 115 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
| 116 | PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
| 117 | ||
| 108 | See the LICENSE file for details. | |
| 118 | 109 | |
| 119 | 110 | [1]: http://daringfireball.net/projects/markdown/ |
| 120 | 111 | [2]: http://www.whytheluckystiff.net/ruby/redcloth/ |
| ... | ...@@ -0,0 +1,27 @@ | |
| 1 | Copyright (c) 2004-2008, Michael Granger | |
| 2 | All rights reserved. | |
| 3 | ||
| 4 | Redistribution and use in source and binary forms, with or without | |
| 5 | modification, are permitted provided that the following conditions are met: | |
| 6 | ||
| 7 | * Redistributions of source code must retain the above copyright notice, | |
| 8 | this list of conditions and the following disclaimer. | |
| 9 | ||
| 10 | * Redistributions in binary form must reproduce the above copyright notice, | |
| 11 | this list of conditions and the following disclaimer in the documentation | |
| 12 | and/or other materials provided with the distribution. | |
| 13 | ||
| 14 | * Neither the name of the author/s, nor the names of the project's | |
| 15 | contributors may be used to endorse or promote products derived from this | |
| 16 | software without specific prior written permission. | |
| 17 | ||
| 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | |
| 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
| 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| ... | ...@@ -39,7 +39,8 @@ | |
| 39 | 39 | DOCSDIR = BASEDIR + 'docs' |
| 40 | 40 | PKGDIR = BASEDIR + 'pkg' |
| 41 | 41 | |
| 42 | PKG_NAME = 'bluecloth' | |
| 42 | PROJECT_NAME = 'BlueCloth' | |
| 43 | PKG_NAME = PROJECT_NAME.downcase | |
| 43 | 44 | PKG_SUMMARY = 'BlueCloth is a Ruby implementation of Markdown' |
| 44 | 45 | VERSION_FILE = LIBDIR + 'bluecloth.rb' |
| 45 | 46 | PKG_VERSION = VERSION_FILE.read[ /VERSION = '(\d+\.\d+\.\d+)'/, 1 ] |
| ... | ...@@ -107,6 +108,7 @@ | |
| 107 | 108 | SNAPSHOT_GEM_NAME = "#{SNAPSHOT_PKG_NAME}.gem" |
| 108 | 109 | |
| 109 | 110 | # Documentation constants |
| 111 | RDOCDIR = DOCSDIR + 'api' | |
| 110 | 112 | RDOC_OPTIONS = [ |
| 111 | 113 | '-w', '4', |
| 112 | 114 | '-SHN', |
| ... | ...@@ -174,6 +176,9 @@ | |
| 174 | 176 | end |
| 175 | 177 | end |
| 176 | 178 | |
| 179 | # Manual-generation config | |
| 180 | MANUALDIR = DOCSDIR + 'manual' | |
| 181 | ||
| 177 | 182 | $trace = Rake.application.options.trace ? true : false |
| 178 | 183 | $dryrun = Rake.application.options.dryrun ? true : false |
| 179 | 184 |
| ... | ...@@ -0,0 +1,145 @@ | |
| 1 | #!/usr/bin/ruby | |
| 2 | ||
| 3 | begin | |
| 4 | require 'spec/runner' | |
| 5 | ||
| 6 | require 'bluecloth' | |
| 7 | require 'spec/lib/matchers' | |
| 8 | require 'spec/lib/constants' | |
| 9 | rescue LoadError | |
| 10 | unless Object.const_defined?( :Gem ) | |
| 11 | require 'rubygems' | |
| 12 | retry | |
| 13 | end | |
| 14 | raise | |
| 15 | end | |
| 16 | ||
| 17 | module BlueCloth::SpecHelpers | |
| 18 | ||
| 19 | ############### | |
| 20 | module_function | |
| 21 | ############### | |
| 22 | ||
| 23 | end | |
| 24 | ||
| 25 | # Override the badly-formatted output of the RSpec HTML formatter | |
| 26 | require 'spec/runner/formatter/html_formatter' | |
| 27 | ||
| 28 | class Spec::Runner::Formatter::HtmlFormatter | |
| 29 | def example_failed( example, counter, failure ) | |
| 30 | failure_style = failure.pending_fixed? ? 'pending_fixed' : 'failed' | |
| 31 | ||
| 32 | unless @header_red | |
| 33 | @output.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>" | |
| 34 | @header_red = true | |
| 35 | end | |
| 36 | ||
| 37 | unless @example_group_red | |
| 38 | css_class = 'example_group_%d' % [current_example_group_number] | |
| 39 | @output.puts " <script type=\"text/javascript\">makeRed('#{css_class}');</script>" | |
| 40 | @example_group_red = true | |
| 41 | end | |
| 42 | ||
| 43 | move_progress() | |
| 44 | ||
| 45 | @output.puts " <dd class=\"spec #{failure_style}\">", | |
| 46 | " <span class=\"failed_spec_name\">#{h(example.description)}</span>", | |
| 47 | " <div class=\"failure\" id=\"failure_#{counter}\">" | |
| 48 | if failure.exception | |
| 49 | backtrace = format_backtrace( failure.exception.backtrace ) | |
| 50 | message = failure.exception.message | |
| 51 | ||
| 52 | @output.puts " <div class=\"message\"><code>#{h message}</code></div>", | |
| 53 | " <div class=\"backtrace\"><pre>#{backtrace}</pre></div>" | |
| 54 | end | |
| 55 | ||
| 56 | if extra = extra_failure_content( failure ) | |
| 57 | @output.puts( extra ) | |
| 58 | end | |
| 59 | ||
| 60 | @output.puts " </div>", | |
| 61 | " </dd>" | |
| 62 | @output.flush | |
| 63 | end | |
| 64 | ||
| 65 | ||
| 66 | alias_method :default_global_styles, :global_styles | |
| 67 | ||
| 68 | def global_styles | |
| 69 | css = default_global_styles() | |
| 70 | css << %Q{ | |
| 71 | /* Stuff added by #{__FILE__} */ | |
| 72 | ||
| 73 | /* Overrides */ | |
| 74 | #rspec-header { | |
| 75 | -webkit-box-shadow: #333 0 2px 5px; | |
| 76 | margin-bottom: 1em; | |
| 77 | } | |
| 78 | ||
| 79 | .example_group dt { | |
| 80 | -webkit-box-shadow: #333 0 2px 3px; | |
| 81 | } | |
| 82 | ||
| 83 | /* Style for log output */ | |
| 84 | dd.log-message { | |
| 85 | background: #eee; | |
| 86 | padding: 0 2em; | |
| 87 | margin: 0.2em 1em; | |
| 88 | border-bottom: 1px dotted #999; | |
| 89 | border-top: 1px dotted #999; | |
| 90 | text-indent: -1em; | |
| 91 | } | |
| 92 | ||
| 93 | /* Parts of the message */ | |
| 94 | dd.log-message .log-time { | |
| 95 | font-weight: bold; | |
| 96 | } | |
| 97 | dd.log-message .log-time:after { | |
| 98 | content: ": "; | |
| 99 | } | |
| 100 | dd.log-message .log-level { | |
| 101 | font-variant: small-caps; | |
| 102 | border: 1px solid #ccc; | |
| 103 | padding: 1px 2px; | |
| 104 | } | |
| 105 | dd.log-message .log-name { | |
| 106 | font-size: 1.2em; | |
| 107 | color: #1e51b2; | |
| 108 | } | |
| 109 | dd.log-message .log-name:before { content: "«"; } | |
| 110 | dd.log-message .log-name:after { content: "»"; } | |
| 111 | ||
| 112 | dd.log-message .log-message-text { | |
| 113 | padding-left: 4px; | |
| 114 | font-family: Monaco, "Andale Mono", "Vera Sans Mono", mono; | |
| 115 | } | |
| 116 | ||
| 117 | ||
| 118 | /* Distinguish levels */ | |
| 119 | dd.log-message.debug { color: #666; } | |
| 120 | dd.log-message.info {} | |
| 121 | ||
| 122 | dd.log-message.warn, | |
| 123 | dd.log-message.error { | |
| 124 | background: #ff9; | |
| 125 | } | |
| 126 | dd.log-message.error .log-level, | |
| 127 | dd.log-message.error .log-message-text { | |
| 128 | color: #900; | |
| 129 | } | |
| 130 | dd.log-message.fatal { | |
| 131 | background: #900; | |
| 132 | color: white; | |
| 133 | font-weight: bold; | |
| 134 | border: 0; | |
| 135 | } | |
| 136 | dd.log-message.fatal .log-name { | |
| 137 | color: white; | |
| 138 | } | |
| 139 | } | |
| 140 | ||
| 141 | return css | |
| 142 | end | |
| 143 | end | |
| 144 | ||
| 145 |
| ... | ...@@ -31,7 +31,7 @@ | |
| 31 | 31 | |
| 32 | 32 | describe BlueCloth, "-- Markdown" do |
| 33 | 33 | include BlueCloth::TestConstants, |
| 34 | BlueClothMatchers | |
| 34 | BlueCloth::Matchers | |
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | ### Output some debugging if $DEBUG is true |
| ... | ...@@ -31,7 +31,7 @@ | |
| 31 | 31 | |
| 32 | 32 | describe BlueCloth, " contributed features" do |
| 33 | 33 | include BlueCloth::TestConstants, |
| 34 | BlueClothMatchers | |
| 34 | BlueCloth::Matchers | |
| 35 | 35 | |
| 36 | 36 | ### HTML filter options contributed by Florian Gross. |
| 37 | 37 | describe "Florian Gross's HTML filtering" do |
| ... | ...@@ -1,10 +1,21 @@ | |
| 1 | 1 | #!/usr/bin/env ruby |
| 2 | 2 | |
| 3 | require 'bluecloth' | |
| 4 | require 'spec/matchers' | |
| 3 | begin | |
| 4 | require 'bluecloth' | |
| 5 | require 'diff/lcs' | |
| 6 | require 'diff/lcs/callbacks' | |
| 7 | require 'spec/lib/constants' | |
| 8 | rescue LoadError | |
| 9 | unless Object.const_defined?( :Gem ) | |
| 10 | require 'rubygems' | |
| 11 | retry | |
| 12 | end | |
| 13 | raise | |
| 14 | end | |
| 15 | ||
| 5 | 16 | |
| 6 | 17 | ### Fixturing functions |
| 7 | module BlueClothMatchers | |
| 18 | module BlueCloth::Matchers | |
| 8 | 19 | |
| 9 | 20 | class TransformMatcher |
| 10 | 21 | |
| ... | ...@@ -18,13 +29,14 @@ | |
| 18 | 29 | def matches?( bluecloth ) |
| 19 | 30 | @bluecloth = bluecloth |
| 20 | 31 | @output_html = bluecloth.to_html |
| 21 | return @output_html == @html | |
| 32 | return @output_html.strip == @html.strip | |
| 22 | 33 | end |
| 23 | 34 | |
| 24 | 35 | ### Build a failure message for the matching case. |
| 25 | 36 | def failure_message |
| 26 | return "Expected the generated html:\n\n %p\n\nto be the same as:\n\n %p\n\n" % | |
| 27 | [ @output_html, @html ] | |
| 37 | patch = self.make_patch( @html, @output_html ) | |
| 38 | return "Expected the generated html:\n\n %p\n\nto be the same as:\n\n %p\n\nDiffs:\n\n%s" % | |
| 39 | [ @output_html, @html, patch ] | |
| 28 | 40 | end |
| 29 | 41 | |
| 30 | 42 | ### Build a failure message for the non-matching case. |
| ... | ...@@ -32,6 +44,32 @@ | |
| 32 | 44 | return "Expected the generated html:\n\n %p\n\nnot to be the same as:\n\n %p\n\n" % |
| 33 | 45 | [ @output_html, @html ] |
| 34 | 46 | end |
| 47 | ||
| 48 | ### Compute a patch between the given +expected+ output and the +actual+ output | |
| 49 | ### and return it as a string. | |
| 50 | def make_patch( expected, actual ) | |
| 51 | diffs = Diff::LCS.sdiff( expected.split("\n"), actual.split("\n"), | |
| 52 | Diff::LCS::ContextDiffCallbacks ) | |
| 53 | ||
| 54 | maxcol = diffs.flatten. | |
| 55 | collect {|d| [d.old_element.to_s.length, d.new_element.to_s.length ] }. | |
| 56 | flatten.max || 0 | |
| 57 | maxcol += 4 | |
| 58 | ||
| 59 | patch = " %#{maxcol}s | %s\n" % [ "Expected", "Actual" ] | |
| 60 | patch << diffs.collect do |changeset| | |
| 61 | changeset.collect do |change| | |
| 62 | "%s [%03d, %03d]: %#{maxcol}s | %-#{maxcol}s" % [ | |
| 63 | change.action, | |
| 64 | change.old_position, | |
| 65 | change.new_position, | |
| 66 | change.old_element.inspect, | |
| 67 | change.new_element.inspect, | |
| 68 | ] | |
| 69 | end.join("\n") | |
| 70 | end.join("\n---\n") | |
| 71 | end | |
| 72 | ||
| 35 | 73 | end |
| 36 | 74 | |
| 37 | 75 | |
| ... | ...@@ -86,14 +124,13 @@ | |
| 86 | 124 | html.gsub!( /^#{indent}|\A\n|\n\t*\Z/m, '' ) |
| 87 | 125 | end |
| 88 | 126 | |
| 89 | return BlueClothMatchers::TransformMatcher.new( html ) | |
| 127 | return BlueCloth::Matchers::TransformMatcher.new( html ) | |
| 90 | 128 | end |
| 91 | 129 | |
| 92 | 130 | ### Generate a matcher that expects to match the given +regexp+. |
| 93 | 131 | def be_transformed_into_html_matching( regexp ) |
| 94 | return BlueClothMatchers::TransformMatcher.new( regexp ) | |
| 132 | return BlueCloth::Matchers::TransformMatcher.new( regexp ) | |
| 95 | 133 | end |
| 96 | 134 | |
| 97 | end | |
| 98 | ||
| 135 | end # module BlueCloth::Matchers | |
| 99 | 136 |
| ... | ...@@ -11,9 +11,10 @@ | |
| 11 | 11 | |
| 12 | 12 | begin |
| 13 | 13 | require 'spec/runner' |
| 14 | require 'logger' | |
| 14 | ||
| 15 | 15 | require 'bluecloth' |
| 16 | 16 | require 'spec/lib/constants' |
| 17 | require 'spec/lib/helpers' | |
| 17 | 18 | require 'spec/lib/matchers' |
| 18 | 19 | rescue LoadError |
| 19 | 20 | unless Object.const_defined?( :Gem ) |
| ... | ...@@ -31,7 +32,7 @@ | |
| 31 | 32 | |
| 32 | 33 | describe BlueCloth, "-- MarkdownTest 1.0: " do |
| 33 | 34 | include BlueCloth::TestConstants, |
| 34 | BlueClothMatchers | |
| 35 | BlueCloth::Matchers | |
| 35 | 36 | |
| 36 | 37 | markdowntest_dir = Pathname.new( __FILE__ ).dirname + 'data/markdowntest' |
| 37 | 38 | Pathname.glob( markdowntest_dir + '*.text' ).each do |textfile| |
| ... | ...@@ -130,7 +130,7 @@ | |
| 130 | 130 | LESS_THAN_TAB_WIDTH = TAB_WIDTH - 1 |
| 131 | 131 | |
| 132 | 132 | # The tag-closing string -- set to '>' for HTML |
| 133 | EMPTY_ELEMENT_SUFFIX = "/>"; | |
| 133 | EMPTY_ELEMENT_SUFFIX = " />"; | |
| 134 | 134 | |
| 135 | 135 | # Table of MD5 sums for escaped characters |
| 136 | 136 | ESCAPE_TABLE = {} |
| ... | ...@@ -941,10 +941,10 @@ | |
| 941 | 941 | |
| 942 | 942 | |
| 943 | 943 | # Pattern to match strong emphasis in Markdown text |
| 944 | BoldRegexp = %r{ (\*\*|__) (\S|\S.+?\S) \1 }x | |
| 944 | BoldRegexp = %r{ (\*\*|__) (\S|\S.*?\S) \1 }x | |
| 945 | 945 | |
| 946 | 946 | # Pattern to match normal emphasis in Markdown text |
| 947 | ItalicRegexp = %r{ (\*|_) (\S|\S.+?\S) \1 }x | |
| 947 | ItalicRegexp = %r{ (\*|_) (\S|\S.*?\S) \1 }x | |
| 948 | 948 | |
| 949 | 949 | ### Transform italic- and bold-encoded text in a copy of the specified +str+ |
| 950 | 950 | ### and return it. |
| ... | ...@@ -31,7 +31,7 @@ | |
| 31 | 31 | |
| 32 | 32 | describe BlueCloth, "bugfixes" do |
| 33 | 33 | include BlueCloth::TestConstants, |
| 34 | BlueClothMatchers | |
| 34 | BlueCloth::Matchers | |
| 35 | 35 | |
| 36 | 36 | before( :all ) do |
| 37 | 37 | @basedir = Pathname.new( __FILE__ ).dirname.parent |