require File.dirname(__FILE__) + '/../test_helper' class TruncateTest < Test::Unit::TestCase include ActionView::Helpers::TextHelper def test_short assert_equal "hello", truncate("hello") assert_equal "hello there this is a test nothing more", truncate("hello there this is a test nothing more", 50) end def test_long assert_equal "hello...", truncate("hello there", 3) assert_equal "hello there this is a test nothing...", truncate("hello there this is a test nothing more than that my good man") end def test_multibyte assert_equal "ɦɛĺłø...", truncate("ɦɛĺłø ŵőřļđ", 3) assert_equal "ɦɛĺłø ŵőřļđ", truncate("ɦɛĺłø ŵőřļđ", 12) end def test_new_calling_convention assert_equal "hello…", truncate("hello world", :length => 3, :omission => "…") assert_equal "hello world", truncate("hello world", :omission => "…") assert_equal "hello...", truncate("hello world", :length => 3) end def test_paragraph_truncate assert_equal "This line stands alone.…", truncate("This line stands alone.\nNobody should see this.", :length => 28, :avoid_orphans => true, :omission => "…") end def test_multi_paragraph_truncate (18..20).to_a.each do |len| assert_equal "Para 1\n\nPara 2...", truncate("Para 1\n\nPara 2\n\nPara 3", :length => len, :avoid_orphans => true) end assert_equal "Para 1\n\nPara 2\n\nPara 3", truncate("Para 1\n\nPara 2\n\nPara 3", :length => 22, :avoid_orphans => true) end end