# encoding: utf-8 require 'test/unit' require './rubypants' # Test EVERYTHING against SmartyPants.pl output! class TestRubyPants < Test::Unit::TestCase def assert_rp_equal(str, orig, options=[2]) assert_equal orig, RubyPants.new(str, options).to_html end def assert_verbatim(str) assert_rp_equal str, str end def test_verbatim assert_verbatim "foo!" assert_verbatim "
This is HTML
" assert_verbatim "
This is HTML with tags>" assert_verbatim <html code EOF end def test_quotes assert_rp_equal '"A first example"', '“A first example”' assert_rp_equal '"A first "nested" example"', '“A first “nested” example”' assert_rp_equal '".', '”.' assert_rp_equal '"a', '“a' assert_rp_equal "'.", '’.' assert_rp_equal "'a", '‘a' assert_rp_equal %{

He said, "'Quoted' words in a larger quote."

}, "

He said, “‘Quoted’ words in a larger quote.”

" assert_rp_equal %{"I like the 70's"}, '“I like the 70’s”' assert_rp_equal %{"I like the '70s"}, '“I like the ’70s”' assert_rp_equal %{"I like the '70!"}, '“I like the ‘70!”' assert_rp_equal 'pre"post', 'pre”post' assert_rp_equal 'pre "post', 'pre “post' assert_rp_equal 'pre "post', 'pre “post' assert_rp_equal 'pre--"post', 'pre–“post' assert_rp_equal 'pre--"!', 'pre–”!' assert_rp_equal "pre'post", 'pre’post' assert_rp_equal "pre 'post", 'pre ‘post' assert_rp_equal "pre 'post", 'pre ‘post' assert_rp_equal "pre--'post", 'pre–‘post' assert_rp_equal "pre--'!", 'pre–’!' assert_rp_equal "'", "" assert_rp_equal "foo'", "foo" assert_rp_equal '"', "" assert_rp_equal 'foo"', "foo" end def test_dashes assert_rp_equal "foo--bar", 'foo—bar', 1 assert_rp_equal "foo---bar", 'foo—-bar', 1 assert_rp_equal "foo----bar", 'foo——bar', 1 assert_rp_equal "foo-----bar", 'foo——-bar', 1 assert_rp_equal "--foo--bar--quux--", '—foo—bar—quux—', 1 assert_rp_equal "foo--bar", 'foo–bar', 2 assert_rp_equal "foo---bar", 'foo—bar', 2 assert_rp_equal "foo----bar", 'foo—-bar', 2 assert_rp_equal "foo-----bar", 'foo—–bar', 2 assert_rp_equal "--foo--bar--quux--", '–foo–bar–quux–', 2 assert_rp_equal "foo--bar", 'foo—bar', 3 assert_rp_equal "foo---bar", 'foo–bar', 3 assert_rp_equal "foo----bar", 'foo–-bar', 3 assert_rp_equal "foo-----bar", 'foo–—bar', 3 assert_rp_equal "--foo--bar--quux--", '—foo—bar—quux—', 3 end def test_ellipses assert_rp_equal "foo..bar", 'foo..bar' assert_rp_equal "foo...bar", 'foo…bar' assert_rp_equal "foo....bar", 'foo….bar' # Nasty ones assert_rp_equal "foo. . ..bar", 'foo….bar' assert_rp_equal "foo. . ...bar", 'foo. . …bar' assert_rp_equal "foo. . ....bar", 'foo. . ….bar' end def test_backticks assert_rp_equal "pre``post", 'pre“post' assert_rp_equal "pre ``post", 'pre “post' assert_rp_equal "pre ``post", 'pre “post' assert_rp_equal "pre--``post", 'pre–“post' assert_rp_equal "pre--``!", 'pre–“!' assert_rp_equal "pre''post", 'pre”post' assert_rp_equal "pre ''post", 'pre ”post' assert_rp_equal "pre ''post", 'pre ”post' assert_rp_equal "pre--''post", 'pre–”post' assert_rp_equal "pre--''!", 'pre–”!' end def test_single_backticks o = [:oldschool, :allbackticks] assert_rp_equal "`foo'", "‘foo’", o assert_rp_equal "pre`post", 'pre‘post', o assert_rp_equal "pre `post", 'pre ‘post', o assert_rp_equal "pre `post", 'pre ‘post', o assert_rp_equal "pre--`post", 'pre–‘post', o assert_rp_equal "pre--`!", 'pre–‘!', o assert_rp_equal "pre'post", 'pre’post', o assert_rp_equal "pre 'post", 'pre ’post', o assert_rp_equal "pre 'post", 'pre ’post', o assert_rp_equal "pre--'post", 'pre–’post', o assert_rp_equal "pre--'!", 'pre–’!', o end def test_stupefy o = [:stupefy] assert_rp_equal "

He said, “‘Quoted’ words " + "in a larger quote.”

", %{

He said, "'Quoted' words in a larger quote."

}, o assert_rp_equal "– — ‘’ “” …", %{- -- '' "" ...}, o assert_rp_equal %{- -- '' "" ...}, %{- -- '' "" ...}, o end def test_process_escapes assert_rp_equal %q{foo\bar}, "foo\\bar" assert_rp_equal %q{foo\\\bar}, "foo\bar" assert_rp_equal %q{foo\\\\\bar}, "foo\\\bar" assert_rp_equal %q{foo\...bar}, "foo...bar" assert_rp_equal %q{foo\.\.\.bar}, "foo...bar" assert_rp_equal %q{foo\'bar}, "foo'bar" assert_rp_equal %q{foo\"bar}, "foo"bar" assert_rp_equal %q{foo\-bar}, "foo-bar" assert_rp_equal %q{foo\`bar}, "foo`bar" assert_rp_equal %q{foo\#bar}, "foo\\#bar" assert_rp_equal %q{foo\*bar}, "foo\\*bar" assert_rp_equal %q{foo\&bar}, "foo\\&bar" end end