OSDN Git Service

Move database.yml to template
[redminele/redminele.git] / redmine / test / unit / helpers / search_helper_test.rb
1 # encoding: utf-8
2 #
3 # Redmine - project management software
4 # Copyright (C) 2006-2009  Jean-Philippe Lang
5 #
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.
10
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.
15
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.
19
20 require File.dirname(__FILE__) + '/../../test_helper'
21
22 class SearchHelperTest < HelperTestCase
23   include SearchHelper
24   
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))
28   end
29   
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))
33   end
34   
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
40   end
41   
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
46   end
47 end