You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search_helper_test.rb 2.0KB

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