diff options
Diffstat (limited to 'actionview/test/template/text_helper_test.rb')
-rw-r--r-- | actionview/test/template/text_helper_test.rb | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/actionview/test/template/text_helper_test.rb b/actionview/test/template/text_helper_test.rb index a514bba83d..f1b84c4786 100644 --- a/actionview/test/template/text_helper_test.rb +++ b/actionview/test/template/text_helper_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 require 'abstract_unit' class TextHelperTest < ActionView::TestCase @@ -187,10 +186,16 @@ class TextHelperTest < ActionView::TestCase "This text is not changed because we supplied an empty phrase", highlight("This text is not changed because we supplied an empty phrase", nil) ) + end + def test_highlight_pending assert_equal ' ', highlight(' ', 'blank text is returned verbatim') end + def test_highlight_should_return_blank_string_for_nil + assert_equal '', highlight(nil, 'blank string is returned for nil') + end + def test_highlight_should_sanitize_input assert_equal( "This is a <mark>beautiful</mark> morning", @@ -222,6 +227,11 @@ class TextHelperTest < ActionView::TestCase ) end + def test_highlight_accepts_regexp + assert_equal("This day was challenging for judge <mark>Allen</mark> and his colleagues.", + highlight("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i)) + end + def test_highlight_with_multiple_phrases_in_one_pass assert_equal %(<em>wow</em> <em>em</em>), highlight('wow em', %w(wow em), :highlighter => '<em>\1</em>') end @@ -260,6 +270,13 @@ class TextHelperTest < ActionView::TestCase assert_equal options, passed_options end + def test_highlight_with_block + assert_equal( + "<b>one</b> <b>two</b> <b>three</b>", + highlight("one two three", ["one", "two", "three"]) { |word| "<b>#{word}</b>" } + ) + end + def test_excerpt assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", :radius => 5)) assert_equal("This is a...", excerpt("This is a beautiful morning", "this", :radius => 5)) @@ -267,6 +284,16 @@ class TextHelperTest < ActionView::TestCase assert_nil excerpt("This is a beautiful morning", "day") end + def test_excerpt_with_regex + assert_equal('...is a beautiful! mor...', excerpt('This is a beautiful! morning', 'beautiful', :radius => 5)) + assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', 'beautiful', :radius => 5)) + assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', /\bbeau\w*\b/i, :radius => 5)) + assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', /\b(beau\w*)\b/i, :radius => 5)) + assert_equal("...udge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, :radius => 5)) + assert_equal("...judge Allen and...", excerpt("This day was challenging for judge Allen and his colleagues.", /\ballen\b/i, :radius => 1, :separator => ' ')) + assert_equal("...was challenging for...", excerpt("This day was challenging for judge Allen and his colleagues.", /\b(\w*allen\w*)\b/i, :radius => 5)) + end + def test_excerpt_should_not_be_html_safe assert !excerpt('This is a beautiful! morning', 'beautiful', :radius => 5).html_safe? end @@ -288,11 +315,6 @@ class TextHelperTest < ActionView::TestCase assert_equal("...abc...", excerpt("z abc d", "b", :radius => 1)) end - def test_excerpt_with_regex - assert_equal('...is a beautiful! mor...', excerpt('This is a beautiful! morning', 'beautiful', :radius => 5)) - assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', 'beautiful', :radius => 5)) - end - def test_excerpt_with_omission assert_equal("[...]is a beautiful morn[...]", excerpt("This is a beautiful morning", "beautiful", :omission => "[...]",:radius => 5)) assert_equal( |