require "test/unit" require File.join(File.dirname(__FILE__), "../init") class StringExtensionsTest < Test::Unit::TestCase def test_to_html require "rubygems" require "RedCloth" { "h1. A Solution" => "
I hated wrapping textilize around a string.
\nIt always felt dirty.
", "I think _this_ is awesome" => "I think this is awesome
", "Um... _*really*_, man" => "Um… really, man
" }.each do |plain, html| assert_equal html, plain.to_html end rescue MissingSourceFile puts "\n>> Could not load RedCloth. String#to_html was not tested.\n>> Please gem install RedCloth if you'd like to use this functionality." end def test_to_html_lite require "rubygems" require "RedCloth" { "I have no pee on me" => "I have no pee on me", "But I _do_ get Textile!" => "But I do get Textile!" }.each do |plain, html| assert_equal html, plain.to_html(:lite) end rescue MissingSourceFile puts "\n>> Could not load RedCloth. String#to_html (with :lite argument) was not tested.\n>> Please gem install RedCloth if you'd like to use this functionality." end def test_to_url { "This has 100% too much formatting
" => "this-has-100-percent-too-much-formatting", "Tea & crumpets & crêpes for me!" => "tea-and-crumpets-and-crepes-for-me", "The Suspense... Is... Killing Me" => "the-suspense-dot-dot-dot-is-dot-dot-dot-killing-me", "How to use attr_accessible and attr_protected" => "how-to-use-attr-accessible-and-attr-protected", "I'm just making sure there's nothing wrong with things!" => "im-just-making-sure-theres-nothing-wrong-with-things" }.each do |html, plain| assert_equal plain, html.to_url end end def test_remove_formatting { "This has 100% too much formatting
" => "This has 100 percent too much formatting", "Tea & crumpets & crêpes for me!" => "Tea and crumpets and crepes for me" }.each do |html, plain| assert_equal plain, html.remove_formatting end end def test_strip_html_tags { "This is invalid XHTML but valid HTML, right?" => "This is invalid XHTML but valid HTML, right?", "
Everything goes!
" => "Everything goes!", "