3 # Redmine - project management software
4 # Copyright (C) 2006-2009 Jean-Philippe Lang
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 require File.dirname(__FILE__) + '/../../test_helper'
22 class SearchHelperTest < HelperTestCase
25 def test_highlight_single_token
26 assert_equal 'This is a <span class="highlight token-0">token</span>.',
27 highlight_tokens('This is a token.', %w(token))
30 def test_highlight_multiple_tokens
31 assert_equal 'This is a <span class="highlight token-0">token</span> and <span class="highlight token-1">another</span> <span class="highlight token-0">token</span>.',
32 highlight_tokens('This is a token and another token.', %w(token another))
35 def test_highlight_should_not_exceed_maximum_length
36 s = (('1234567890' * 100) + ' token ') * 100
37 r = highlight_tokens(s, %w(token))
38 assert r.include?('<span class="highlight token-0">token</span>')
39 assert r.length <= 1300
42 def test_highlight_multibyte
43 s = ('й' * 200) + ' token ' + ('й' * 200)
44 r = highlight_tokens(s, %w(token))
45 assert_equal ('й' * 45) + ' ... ' + ('й' * 44) + ' <span class="highlight token-0">token</span> ' + ('й' * 44) + ' ... ' + ('й' * 45), r