From: Toshi MARUYAMA Date: Thu, 6 Feb 2014 00:36:50 +0000 (+0000) Subject: add tests of ApplicationHelper#truncate_single_line X-Git-Tag: 2.5.0~76 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fc4004d0ba2b32dd48eea5783bc736eaa0597d44;p=redmine.git add tests of ApplicationHelper#truncate_single_line git-svn-id: http://svn.redmine.org/redmine/trunk@12824 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 9dc9de5e7..965d4dda2 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -1340,4 +1340,22 @@ RAW ensure Redmine::Utils.relative_url_root = '' end + + def test_truncate_single_line + str = "01234" + result = truncate_single_line("#{str}\n#{str}", :length => 10) + assert_equal "01234 0...", result + assert !result.html_safe? + result = truncate_single_line("#{str}<&#>\n#{str}\n#{str}", :length => 15) + assert_equal "01234<&#> 01...", result + assert !result.html_safe? + end + + def test_truncate_single_line_non_ascii + ja = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" + ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding) + result = truncate_single_line("#{ja}\n#{ja}\n#{ja}", :length => 10) + assert_equal "#{ja} #{ja}...", result + assert !result.html_safe? + end end