aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/text_helper_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-03-15 19:59:34 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-03-15 19:59:34 +0000
commit5f5822af37b439caabf1993453e93ac6182a4c9e (patch)
tree697633b255b694e671dab91828e1d86d1e6d945f /actionpack/test/template/text_helper_test.rb
parentd0bc724786906644d7ce00e28ca62f5c308f4309 (diff)
downloadrails-5f5822af37b439caabf1993453e93ac6182a4c9e.tar.gz
rails-5f5822af37b439caabf1993453e93ac6182a4c9e.tar.bz2
rails-5f5822af37b439caabf1993453e93ac6182a4c9e.zip
Fixed that TextHelper#excerpt would include one character too many (closes #11268) [Irfy]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9030 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/template/text_helper_test.rb')
-rw-r--r--actionpack/test/template/text_helper_test.rb31
1 files changed, 24 insertions, 7 deletions
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 16f1e092c2..dd5725376f 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -102,30 +102,47 @@ class TextHelperTest < Test::Unit::TestCase
end
def test_excerpt
- assert_equal("...is a beautiful morni...", excerpt("This is a beautiful morning", "beautiful", 5))
+ assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", 5))
assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5))
assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5))
assert_nil excerpt("This is a beautiful morning", "day")
end
+ def test_excerpt_in_borderline_cases
+ assert_equal("", excerpt("", "", 0))
+ assert_equal("a", excerpt("a", "a", 0))
+ assert_equal("...b...", excerpt("abc", "b", 0))
+ assert_equal("abc", excerpt("abc", "b", 1))
+ assert_equal("abc...", excerpt("abcd", "b", 1))
+ assert_equal("...abc", excerpt("zabc", "b", 1))
+ assert_equal("...abc...", excerpt("zabcd", "b", 1))
+ assert_equal("zabcd", excerpt("zabcd", "b", 2))
+
+ # excerpt strips the resulting string before ap-/prepending excerpt_string.
+ # whether this behavior is meaningful when excerpt_string is not to be
+ # appended is questionable.
+ assert_equal("zabcd", excerpt(" zabcd ", "b", 4))
+ assert_equal("...abc...", excerpt("z abc d", "b", 1))
+ end
+
def test_excerpt_with_regex
- assert_equal('...is a beautiful! morn...', excerpt('This is a beautiful! morning', 'beautiful', 5))
- assert_equal('...is a beautiful? morn...', excerpt('This is a beautiful? morning', 'beautiful', 5))
+ assert_equal('...is a beautiful! mor...', excerpt('This is a beautiful! morning', 'beautiful', 5))
+ assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', 'beautiful', 5))
end
if RUBY_VERSION < '1.9'
def test_excerpt_with_utf8
with_kcode('u') do
- assert_equal("...fficiency could not be h...", excerpt("That's why efficiency could not be helped", 'could', 8))
+ assert_equal("...fficiency could not be...", excerpt("That's why efficiency could not be helped", 'could', 8))
end
with_kcode('none') do
- assert_equal("...\203ciency could not be h...", excerpt("That's why efficiency could not be helped", 'could', 8))
+ assert_equal("...\203ciency could not be...", excerpt("That's why efficiency could not be helped", 'could', 8))
end
end
else
def test_excerpt_with_utf8
- assert_equal("...fficiency could not be h...".force_encoding('UTF-8'), excerpt("That's why efficiency could not be helped".force_encoding('UTF-8'), 'could', 8))
- assert_equal("...\203ciency could not be h...", excerpt("That's why efficiency could not be helped", 'could', 8))
+ assert_equal("...fficiency could not be...".force_encoding('UTF-8'), excerpt("That's why efficiency could not be helped".force_encoding('UTF-8'), 'could', 8))
+ assert_equal("...\203ciency could not be...", excerpt("That's why efficiency could not be helped", 'could', 8))
end
end