#!/usr/bin/ruby # # Test case for BlueCloth Markdown transforms. # $Id: TEMPLATE.rb.tpl,v 1.2 2003/09/11 04:59:51 deveiant Exp $ # # Copyright (c) 2004 The FaerieMUD Consortium. # if !defined?( BlueCloth ) || !defined?( BlueCloth::TestCase ) basedir = File::dirname( __FILE__ ) require File::join( basedir, 'bctestcase' ) end ### This test case tests ... class SubfunctionsTestCase < BlueCloth::TestCase ### Test email address output Emails = %w[ address@example.com foo-list-admin@bar.com fu@bar.COM baz@ruby-lang.org foo-tim-bazzle@bar-hop.co.uk littlestar@twinkle.twinkle.band.CO.ZA ll@lll.lllll.ll Ull@Ulll.Ulllll.ll UUUU1@UU1.UU1UUU.UU l@ll.ll Ull.Ullll@llll.ll Ulll-Ull.Ulllll@ll.ll 1@111.ll ] # I can't see a way to handle IDNs clearly yet, so these will have to wait. # info@öko.de # jemand@büro.de # irgendwo-interreßant@dÅgta.se #] def test_10_email_address printTestHeader "BlueCloth: Inline email address" rval = match = nil Emails.each {|addr| assert_nothing_raised { rval = BlueCloth::new( "<#{addr}>" ).to_html } match = %r{

[^<]+

}.match( rval ) assert_not_nil match, "Match against output #{rval}" assert_equal "mailto:#{addr}", decode( match[1] ) } end def decode( str ) str.gsub( /&#(x[a-f0-9]+|\d{3});/i ) {|match| code = $1 debugMsg "Decoding %p" % code case code when /^x([a-f0-9]+)/i debugMsg " (hex) = %p" % $1.to_i(16).chr $1.to_i(16).chr when /\d{3}/ debugMsg " (oct) = %p" % code.to_i.chr code.to_i.chr else raise "Hmmm... malformed entity %p" % code end } end ################################################################# ### A U T O - G E N E R A T E D T E S T S ################################################################# # Parse the data section into a hash of test specifications TestSets = {} begin seenEnd = false inMetaSection = true inInputSection = true section, description, input, output = '', '', '', '' linenum = 0 # Read this file, skipping lines until the __END__ token. Then start # reading the tests. File::foreach( __FILE__ ) {|line| linenum += 1 if /^__END__/ =~ line then seenEnd = true; next end debugMsg "#{linenum}: #{line.chomp}" next unless seenEnd # Start off in the meta section, which has sections and # descriptions. if inMetaSection case line # Left angles switch into data section for the current section # and description. when /^<< linenum, :sets => [], } end # Data section has input and expected output parts else case line # Right angles terminate a data section, at which point we # should have enough data to add a test. when /^>>>/ TestSets[ section ][ description ][:sets] << [ input.chomp, output.chomp ] inMetaSection = true inInputSection = true input = ''; output = '' # 3-Dashed divider with text divides input from output when /^--- (.+)/ inInputSection = false # Anything else adds to either input or output else if inInputSection input += line else output += line end end end } end debugMsg "Test sets: %p" % TestSets # Auto-generate tests out of the test specifications TestSets.each {|sname, section| # Generate a test method for each section section.each do |desc, test| methname = "test_%03d_%s" % [ test[:line], desc.gsub(/\W+/, '_').downcase ] # Header code = %{ def #{methname} printTestHeader "BlueCloth: #{desc}" rval = nil } # An assertion for each input/output pair test[:sets].each {|input, output| code << %{ assert_nothing_raised { obj = BlueCloth::new(%p) rval = obj.to_html } assert_equal %p, rval } % [ input, output ] } code << %{ end } debugMsg "--- %s [%s]:\n%s\n---\n" % [sname, desc, code] eval code end } end __END__ ### [Paragraphs and Line Breaks] # Paragraphs <<< This is some stuff that should all be put in one paragraph even though it occurs over several lines. And this is a another one. --- Should become:

This is some stuff that should all be put in one paragraph even though it occurs over several lines.

And this is a another one.

>>> # Line breaks <<< Mostly the same kind of thing with two spaces at the end of each line should result in line breaks, though. And this is a another one. --- Should become:

Mostly the same kind of thing
with two spaces at the end
of each line
should result in
line breaks, though.

And this is a another
one.

>>> # Escaping special characters <<< The left shift operator, which is written as <<, is often used & greatly admired. --- Should become:

The left shift operator, which is written as <<, is often used & greatly admired.

>>> # Preservation of named entities <<< The left shift operator, which is written as <<, is often used & greatly admired. --- Should become:

The left shift operator, which is written as <<, is often used & greatly admired.

>>> # Preservation of decimal-encoded entities <<< The left shift operator, which is written as <<, is often used & greatly admired. --- Should become:

The left shift operator, which is written as <<, is often used & greatly admired.

>>> # Preservation of hex-encoded entities <<< The left shift operator, which is written as <<, is often used & greatly admired. --- Should become:

The left shift operator, which is written as <<, is often used & greatly admired.

>>> # Inline HTML - table tags <<< This is a regular paragraph.
Foo
This is another regular paragraph. --- Should become:

This is a regular paragraph.

Foo

This is another regular paragraph.

>>> # Inline HTML - div tags <<< This is a regular paragraph.
Something
Something else. --- Should become:

This is a regular paragraph.

Something

Something else.

>>> # Inline HTML - Plain HR <<< This is a regular paragraph.
Something else. --- Should become:

This is a regular paragraph.


Something else.

>>> # Inline HTML - Fancy HR <<< This is a regular paragraph.
Something else. --- Should become:

This is a regular paragraph.


Something else.

>>> # Inline HTML - Iframe <<< This is a regular paragraph. Something else. --- Should become:

This is a regular paragraph.

Something else.

>>> # Inline HTML - mathml <<< Examples -------- Now that we have met some of the key players, it is time to see what we can do. Here are some examples and comments which illustrate the use of the basic layout and token elements. Consider the expression x2 + 4x + 4 = 0. A basic MathML presentation encoding for this would be: x 2 + 4 x + 4 = 0 This encoding will display as you would expect. However, if we were interested in reusing this expression in unknown situations, we would likely want to spend a little more effort analyzing and encoding the logical expression structure. --- Should become:

Examples

Now that we have met some of the key players, it is time to see what we can do. Here are some examples and comments which illustrate the use of the basic layout and token elements. Consider the expression x2 + 4x + 4 = 0. A basic MathML presentation encoding for this would be:

x 2 + 4 x + 4 = 0

This encoding will display as you would expect. However, if we were interested in reusing this expression in unknown situations, we would likely want to spend a little more effort analyzing and encoding the logical expression structure.

>>> # Span-level HTML <<< This is some stuff with a spanned bit of text in it. And this *should* be a bit of deleted text which should be preserved, and part of it emphasized. --- Should become:

This is some stuff with a spanned bit of text in it. And this should be a bit of deleted text which should be preserved, and part of it emphasized.

>>> # Inline HTML (Case-sensitivity) <<< This is a regular paragraph.
Foo
This is another regular paragraph. --- Should become:

This is a regular paragraph.

Foo

This is another regular paragraph.

>>> # Span-level HTML (Case-sensitivity) <<< This is some stuff with a spanned bit of text in it. And this *should* be a bit of deleted text which should be preserved, and part of it emphasized. --- Should become:

This is some stuff with a spanned bit of text in it. And this should be a bit of deleted text which should be preserved, and part of it emphasized.

>>> ### [Code spans] # Single backtick <<< Making `code` work for you --- Should become:

Making code work for you

>>> # Literal backtick with doubling <<< Making `` `code` `` work for you --- Should become:

Making `code` work for you

>>> # Many repetitions <<< Making `````code````` work for you --- Should become:

Making code work for you

>>> # Two in a row <<< This `thing` should be `two` spans. --- Should become:

This thing should be two spans.

>>> # At the beginning of a newline <<< I should think that the `tar` command would be universal. --- Should become:

I should think that the tar command would be universal.

>>> # Entity escaping <<< The left angle-bracket (`<`) can also be written as a decimal-encoded (`<`) or hex-encoded (`<`) entity. --- Should become:

The left angle-bracket (&lt;) can also be written as a decimal-encoded (&#060;) or hex-encoded (&#x3c;) entity.

>>> # At the beginning of a document (Bug #525) <<< `world` views --- Should become:

world views

>>> ### [Code blocks] # Para plus code block (literal tab) <<< This is a chunk of code: some.code > some.other_code Some stuff. --- Should become:

This is a chunk of code:

some.code > some.other_code

Some stuff.

>>> # Para plus code block (literal tab, no colon) <<< This is a chunk of code some.code > some.other_code Some stuff. --- Should become:

This is a chunk of code

some.code > some.other_code

Some stuff.

>>> # Para plus code block (tab-width spaces) <<< This is a chunk of code: some.code > some.other_code Some stuff. --- Should become:

This is a chunk of code:

some.code > some.other_code

Some stuff.

>>> # Para plus code block (tab-width spaces, no colon) <<< This is a chunk of code some.code > some.other_code Some stuff. --- Should become:

This is a chunk of code

some.code > some.other_code

Some stuff.

>>> # Colon with preceeding space <<< A regular paragraph, without a colon. : This is a code block. Some stuff. --- Should become:

A regular paragraph, without a colon. :

This is a code block.

Some stuff.

>>> # Single colon <<< : some.code > some.other_code Some stuff. --- Should become:

:

some.code > some.other_code

Some stuff.

>>> # Preserve leading whitespace (Bug #541) <<< Examples: # (Waste character because first line is flush left !!!) # Example script1 x = 1 x += 1 puts x Some stuff. --- Should become:

Examples:

      # (Waste character because first line is flush left !!!)
      # Example script1
      x = 1
      x += 1
      puts x

Some stuff.

>>> ### [Horizontal Rules] # Hrule 1 <<< * * * --- Should become:
>>> # Hrule 2 <<< *** --- Should become:
>>> # Hrule 3 <<< ***** --- Should become:
>>> # Hrule 4 <<< - - - --- Should become:
>>> # Hrule 5 <<< --------------------------------------- --- Should become:
>>> ### [Titles] # setext-style h1 <<< Title Text = --- Should become:

Title Text

>>> <<< Title Text === --- Should become:

Title Text

>>> <<< Title Text ========== --- Should become:

Title Text

>>> # setext-style h2 <<< Title Text - --- Should become:

Title Text

>>> <<< Title Text --- --- Should become:

Title Text

>>> <<< Title Text ---------- --- Should become:

Title Text

>>> # ATX-style h1 <<< # Title Text --- Should become:

Title Text

>>> <<< # Title Text # --- Should become:

Title Text

>>> <<< # Title Text ### --- Should become:

Title Text

>>> <<< # Title Text ##### --- Should become:

Title Text

>>> # ATX-style h2 <<< ## Title Text --- Should become:

Title Text

>>> <<< ## Title Text # --- Should become:

Title Text

>>> <<< ## Title Text ### --- Should become:

Title Text

>>> <<< ## Title Text ##### --- Should become:

Title Text

>>> # ATX-style h3 <<< ### Title Text --- Should become:

Title Text

>>> <<< ### Title Text # --- Should become:

Title Text

>>> <<< ### Title Text ### --- Should become:

Title Text

>>> <<< ### Title Text ##### --- Should become:

Title Text

>>> # ATX-style h4 <<< #### Title Text --- Should become:

Title Text

>>> <<< #### Title Text # --- Should become:

Title Text

>>> <<< #### Title Text ### --- Should become:

Title Text

>>> <<< #### Title Text ##### --- Should become:

Title Text

>>> # ATX-style h5 <<< ##### Title Text --- Should become:
Title Text
>>> <<< ##### Title Text # --- Should become:
Title Text
>>> <<< ##### Title Text ### --- Should become:
Title Text
>>> <<< ##### Title Text ##### --- Should become:
Title Text
>>> # ATX-style h6 <<< ###### Title Text --- Should become:
Title Text
>>> <<< ###### Title Text # --- Should become:
Title Text
>>> <<< ###### Title Text ### --- Should become:
Title Text
>>> <<< ###### Title Text ##### --- Should become:
Title Text
>>> ### [Blockquotes] # Regular 1-level blockquotes <<< > Email-style angle brackets > are used for blockquotes. --- Should become:

Email-style angle brackets are used for blockquotes.

>>> # Doubled blockquotes <<< > > And, they can be nested. --- Should become:

And, they can be nested.

>>> # Nested blockquotes <<< > Email-style angle brackets > are used for blockquotes. > > And, they can be nested. --- Should become:

Email-style angle brackets are used for blockquotes.

And, they can be nested.

>>> # Lazy blockquotes <<< > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. --- Should become:

This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.

Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.

>>> # Blockquotes containing other markdown elements <<< > ## This is a header. > > 1. This is the first list item. > 2. This is the second list item. > > Here's some example code: > > return shell_exec("echo $input | $markdown_script"); --- Should become:

This is a header.

  1. This is the first list item.
  2. This is the second list item.

Here's some example code:

return shell_exec("echo $input | $markdown_script");
>>> # Blockquotes with a
 section
<<<
> The best approximation of the problem is the following code:
>
> 
> foo + bar; foo.factorize; foo.display
> 
> > This should result in an error on any little-endian platform. --- Should become:

The best approximation of the problem is the following code:

foo + bar; foo.factorize; foo.display

This should result in an error on any little-endian platform.

>>> ### [Images] # Inline image with title <<< ![alt text](/path/img.jpg "Title") --- Should become:

alt text

>>> # Inline image with title (single-quotes) <<< ![alt text](/path/img.jpg 'Title') --- Should become:

alt text

>>> # Inline image with title (with embedded quotes) <<< ![alt text](/path/img.jpg 'The "Title" Image') --- Should become:

alt text

>>> # Inline image without title <<< ![alt text](/path/img.jpg) --- Should become:

alt text

>>> # Inline image with quoted alt text <<< ![the "alt text"](/path/img.jpg) --- Should become:

the "alt text"

>>> # Reference image <<< ![alt text][id] [id]: /url/to/img.jpg "Title" --- Should become:

alt text

>>> ### [Emphasis] # Emphasis () with asterisks <<< Use *single splats* for emphasis. --- Should become:

Use single splats for emphasis.

>>> # Emphasis () with underscores <<< Use *underscores* for emphasis. --- Should become:

Use underscores for emphasis.

>>> # Strong emphasis () with asterisks <<< Use **double splats** for more emphasis. --- Should become:

Use double splats for more emphasis.

>>> # Strong emphasis () with underscores <<< Use __doubled underscores__ for more emphasis. --- Should become:

Use doubled underscores for more emphasis.

>>> # Combined emphasis types 1 <<< Use *single splats* or _single unders_ for normal emphasis. --- Should become:

Use single splats or single unders for normal emphasis.

>>> # Combined emphasis types 2 <<< Use _single unders_ for normal emphasis or __double them__ for strong emphasis. --- Should become:

Use single unders for normal emphasis or double them for strong emphasis.

>>> # Emphasis containing escaped metachars <<< You can include literal *\*splats\** by escaping them. --- Should become:

You can include literal *splats* by escaping them.

>>> # Two instances of asterisked emphasis on one line <<< If there's *two* splatted parts on a *single line* it should still work. --- Should become:

If there's two splatted parts on a single line it should still work.

>>> # Two instances of double asterisked emphasis on one line <<< This **doubled** one should **work too**. --- Should become:

This doubled one should work too.

>>> # Two instances of underscore emphasis on one line <<< If there's _two_ underbarred parts on a _single line_ it should still work. --- Should become:

If there's two underbarred parts on a single line it should still work.

>>> # Two instances of doubled underscore emphasis on one line <<< This __doubled__ one should __work too__. --- Should become:

This doubled one should work too.

>>> # Initial emphasis (asterisk) <<< *Something* like this should be bold. --- Should become:

Something like this should be bold.

>>> # Initial emphasis (underscore) <<< _Something_ like this should be bold. --- Should become:

Something like this should be bold.

>>> # Initial strong emphasis (asterisk) <<< **Something** like this should be bold. --- Should become:

Something like this should be bold.

>>> # Initial strong emphasis (underscore) <<< __Something__ like this should be bold. --- Should become:

Something like this should be bold.

>>> # Partial-word emphasis (Bug #568) <<< **E**xtended **TURN** --- Should become:

Extended TURN

>>> ### [Links] # Inline link, no title <<< An [example](http://url.com/). --- Should become:

An example.

>>> # Inline link with title <<< An [example](http://url.com/ "Check out url.com!"). --- Should become:

An example.

>>> # Reference-style link, no title <<< An [example][ex] reference-style link. [ex]: http://www.bluefi.com/ --- Should become:

An example reference-style link.

>>> # Reference-style link with quoted title <<< An [example][ex] reference-style link. [ex]: http://www.bluefi.com/ "Check out our air." --- Should become:

An example reference-style link.

>>> # Reference-style link with paren title <<< An [example][ex] reference-style link. [ex]: http://www.bluefi.com/ (Check out our air.) --- Should become:

An example reference-style link.

>>> # Reference-style link with one of each (hehe) <<< An [example][ex] reference-style link. [ex]: http://www.bluefi.com/ "Check out our air.) --- Should become:

An example reference-style link.

>>> " <- For syntax highlighting # Reference-style link with intervening space <<< You can split the [linked part] [ex] from the reference part with a single space. [ex]: http://www.treefrog.com/ "for some reason" --- Should become:

You can split the linked part from the reference part with a single space.

>>> # Reference-style link with intervening space <<< You can split the [linked part] [ex] from the reference part with a newline in case your editor wraps it there, I guess. [ex]: http://www.treefrog.com/ --- Should become:

You can split the linked part from the reference part with a newline in case your editor wraps it there, I guess.

>>> # Reference-style anchors <<< I get 10 times more traffic from [Google] [1] than from [Yahoo] [2] or [MSN] [3]. [1]: http://google.com/ "Google" [2]: http://search.yahoo.com/ "Yahoo Search" [3]: http://search.msn.com/ "MSN Search" --- Should become:

I get 10 times more traffic from Google than from Yahoo or MSN.

>>> # Implicit name-link shortcut anchors <<< I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][]. [google]: http://google.com/ "Google" [yahoo]: http://search.yahoo.com/ "Yahoo Search" [msn]: http://search.msn.com/ "MSN Search" --- Should become:

I get 10 times more traffic from Google than from Yahoo or MSN.

>>> # Inline anchors <<< I get 10 times more traffic from [Google](http://google.com/ "Google") than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or [MSN](http://search.msn.com/ "MSN Search"). --- Should become:

I get 10 times more traffic from Google than from Yahoo or MSN.

>>> # Graceful fail for unclosed brackets (and bug #524) <<< This is just a [bracket opener; it should fail gracefully. --- Should become:

This is just a [bracket opener; it should fail gracefully.

>>> # Unresolved reference-style links (Bug #620) <<< This is an unresolved [url][1]. --- Should become:

This is an unresolved [url][1].

>>> ### [Auto-links] # Plain HTTP link <<< This is a reference to . You should follow it. --- Should become:

This is a reference to http://www.FaerieMUD.org/. You should follow it.

>>> # FTP link <<< Why not download your very own chandelier from ? --- Should become:

Why not download your very own chandelier from ftp://ftp.usuc.edu/pub/foof/mir/?

>>> ### [Lists] # Unordered list <<< * Red * Green * Blue --- Should become:
  • Red
  • Green
  • Blue
>>> # Unordered list w/alt bullets <<< - Red - Green - Blue --- Should become:
  • Red
  • Green
  • Blue
>>> # Unordered list w/alt bullets 2 <<< + Red + Green + Blue --- Should become:
  • Red
  • Green
  • Blue
>>> # Unordered list w/mixed bullets <<< + Red - Green * Blue --- Should become:
  • Red
  • Green
  • Blue
>>> # Ordered list <<< 1. Bird 2. McHale 3. Parish --- Should become:
  1. Bird
  2. McHale
  3. Parish
>>> # Ordered list, any numbers <<< 1. Bird 1. McHale 1. Parish --- Should become:
  1. Bird
  2. McHale
  3. Parish
>>> # Ordered list, any numbers 2 <<< 3. Bird 1. McHale 8. Parish --- Should become:
  1. Bird
  2. McHale
  3. Parish
>>> # Hanging indents <<< * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. --- Should become:
  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
  • Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.
>>> # Lazy indents <<< * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. --- Should become:
  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
  • Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.
>>> # Paragraph wrapped list items <<< * Bird * Magic --- Should become:
  • Bird

  • Magic

>>> # Multi-paragraph list items <<< 1. This is a list item with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. Donec sit amet nisl. Aliquam semper ipsum sit amet velit. 2. Suspendisse id sem consectetuer libero luctus adipiscing. --- Should become:
  1. This is a list item with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.

    Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. Donec sit amet nisl. Aliquam semper ipsum sit amet velit.

  2. Suspendisse id sem consectetuer libero luctus adipiscing.

>>> # Lazy multi-paragraphs <<< * This is a list item with two paragraphs. This is the second paragraph in the list item. You're only required to indent the first line. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. * Another item in the same list. --- Should become:
  • This is a list item with two paragraphs.

    This is the second paragraph in the list item. You're only required to indent the first line. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

  • Another item in the same list.

>>> # Blockquote in list item <<< * A list item with a blockquote: > This is a blockquote > inside a list item. --- Should become:
  • A list item with a blockquote:

    This is a blockquote inside a list item.

>>> # Code block in list item <<< * A list item with a code block: --- Should become:
  • A list item with a code block:

    <code goes here>
    
>>> # Backslash-escaped number-period-space <<< 1986\. What a great season. --- Should become:

1986. What a great season.

>>>